mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-14 22:22:18 +00:00
improve scanning and added debug messages for scanning
This commit is contained in:
parent
37f0f3577f
commit
1e0f9576a2
2
db.py
2
db.py
@ -320,7 +320,7 @@ class Track(Base):
|
|||||||
return os.path.splitext(self.path)[1][1:].lower()
|
return os.path.splitext(self.path)[1][1:].lower()
|
||||||
|
|
||||||
def sort_key(self):
|
def sort_key(self):
|
||||||
return (self.album.artist.name + self.album.name + ("%02i" % self.disc) + ("%02i" % self.number) + str(self.title)).lower()
|
return (self.album.artist.name + self.album.name + ("%02i" % self.disc) + ("%02i" % self.number) + self.title).lower()
|
||||||
|
|
||||||
class StarredFolder(Base):
|
class StarredFolder(Base):
|
||||||
__tablename__ = 'starred_folder'
|
__tablename__ = 'starred_folder'
|
||||||
|
@ -6,7 +6,6 @@ import uuid
|
|||||||
|
|
||||||
from web import app
|
from web import app
|
||||||
from db import session, Folder
|
from db import session, Folder
|
||||||
from scanner import Scanner
|
|
||||||
from managers.user import UserManager
|
from managers.user import UserManager
|
||||||
from managers.folder import FolderManager
|
from managers.folder import FolderManager
|
||||||
|
|
||||||
|
27
scanner.py
27
scanner.py
@ -1,9 +1,12 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
import sys
|
||||||
import os, os.path
|
import os, os.path
|
||||||
import time, mimetypes
|
import time, mimetypes
|
||||||
import mutagen
|
import mutagen
|
||||||
import config, db
|
import config, db
|
||||||
|
import math
|
||||||
|
from web import app
|
||||||
|
|
||||||
def get_mime(ext):
|
def get_mime(ext):
|
||||||
return mimetypes.guess_type('dummy.' + ext, False)[0] or config.get('mimetypes', ext) or 'application/octet-stream'
|
return mimetypes.guess_type('dummy.' + ext, False)[0] or config.get('mimetypes', ext) or 'application/octet-stream'
|
||||||
@ -12,8 +15,7 @@ class Scanner:
|
|||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
self.__session = session
|
self.__session = session
|
||||||
self.__tracks = db.Track.query.all()
|
self.__tracks = db.Track.query.all()
|
||||||
paths = {x.path for x in self.__tracks}
|
self.__tracks = {x.path: x for x in self.__tracks}
|
||||||
self.__tracks = dict(zip(paths,self.__tracks))
|
|
||||||
|
|
||||||
self.__artists = db.Artist.query.all()
|
self.__artists = db.Artist.query.all()
|
||||||
self.__folders = db.Folder.query.all()
|
self.__folders = db.Folder.query.all()
|
||||||
@ -37,7 +39,14 @@ class Scanner:
|
|||||||
for f in files:
|
for f in files:
|
||||||
suffix = os.path.splitext(f)[1][1:].lower()
|
suffix = os.path.splitext(f)[1][1:].lower()
|
||||||
if suffix in valid:
|
if suffix in valid:
|
||||||
|
try:
|
||||||
|
app.logger.debug('Scanning File: ' + os.path.join(root, f))
|
||||||
self.__scan_file(os.path.join(root, f), folder)
|
self.__scan_file(os.path.join(root, f), folder)
|
||||||
|
except:
|
||||||
|
app.logger.error('Problem adding file: ' + os.path.join(root,f))
|
||||||
|
app.logger.error(sys.exc_info())
|
||||||
|
self.__session.rollback()
|
||||||
|
self.__session.commit()
|
||||||
|
|
||||||
folder.last_scan = int(time.time())
|
folder.last_scan = int(time.time())
|
||||||
|
|
||||||
@ -71,16 +80,25 @@ class Scanner:
|
|||||||
def __scan_file(self, path, folder):
|
def __scan_file(self, path, folder):
|
||||||
if path in self.__tracks:
|
if path in self.__tracks:
|
||||||
tr = self.__tracks[path]
|
tr = self.__tracks[path]
|
||||||
if not os.path.getmtime(path) > tr.last_modification:
|
curmtime = int(math.floor(os.path.getmtime(path)))
|
||||||
|
if curmtime <= tr.last_modification:
|
||||||
|
app.logger.debug('\tFile not modified')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
app.logger.debug('\tFile modified, updating tag')
|
||||||
|
app.logger.debug('\tcurmtime %s / last_mod %s', curmtime, tr.last_modification)
|
||||||
|
app.logger.debug('\t\t%s Seconds Newer\n\t\t', str(curmtime - tr.last_modification))
|
||||||
|
tr.last_modification = curmtime
|
||||||
tag = self.__try_load_tag(path)
|
tag = self.__try_load_tag(path)
|
||||||
if not tag:
|
if not tag:
|
||||||
|
app.logger.debug('\tError retrieving tags, removing track from DB')
|
||||||
self.__remove_track(tr)
|
self.__remove_track(tr)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
app.logger.debug('\tReading tag')
|
||||||
tag = self.__try_load_tag(path)
|
tag = self.__try_load_tag(path)
|
||||||
if not tag:
|
if not tag:
|
||||||
|
app.logger.debug('\tProblem reading tag')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
tr = db.Track(path = path, root_folder = folder, folder = self.__find_folder(path, folder))
|
tr = db.Track(path = path, root_folder = folder, folder = self.__find_folder(path, folder))
|
||||||
@ -97,7 +115,6 @@ class Scanner:
|
|||||||
tr.album = self.__find_album(self.__try_read_tag(tag, 'artist', 'Unknown'), self.__try_read_tag(tag, 'album', 'Unknown'))
|
tr.album = self.__find_album(self.__try_read_tag(tag, 'artist', 'Unknown'), self.__try_read_tag(tag, 'album', 'Unknown'))
|
||||||
tr.bitrate = (tag.info.bitrate if hasattr(tag.info, 'bitrate') else int(os.path.getsize(path) * 8 / tag.info.length)) / 1000
|
tr.bitrate = (tag.info.bitrate if hasattr(tag.info, 'bitrate') else int(os.path.getsize(path) * 8 / tag.info.length)) / 1000
|
||||||
tr.content_type = get_mime(os.path.splitext(path)[1][1:])
|
tr.content_type = get_mime(os.path.splitext(path)[1][1:])
|
||||||
tr.last_modification = os.path.getmtime(path)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -143,7 +160,7 @@ class Scanner:
|
|||||||
|
|
||||||
def __try_load_tag(self, path):
|
def __try_load_tag(self, path):
|
||||||
try:
|
try:
|
||||||
return mutagen.File(path, easy = False)
|
return mutagen.File(path, easy = True)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
4
web.py
4
web.py
@ -5,12 +5,14 @@ from flask import Flask, request, session, flash, render_template, redirect, url
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = '?9huDM\\H'
|
app.secret_key = '?9huDM\\H'
|
||||||
|
|
||||||
|
app.debug = True
|
||||||
|
|
||||||
import config
|
import config
|
||||||
if config.get('base', 'log_file'):
|
if config.get('base', 'log_file'):
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight')
|
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight')
|
||||||
handler.setLevel(logging.WARNING)
|
handler.setLevel(logging.DEBUG)
|
||||||
app.logger.addHandler(handler)
|
app.logger.addHandler(handler)
|
||||||
|
|
||||||
import db
|
import db
|
||||||
|
Loading…
Reference in New Issue
Block a user