mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-14 22:22:18 +00:00
fix unicode transcoding, add debug config option, improve scan
This commit is contained in:
parent
c734f8dd09
commit
0dd8626069
18
api/media.py
18
api/media.py
@ -77,25 +77,29 @@ def stream_media():
|
|||||||
|
|
||||||
transcoder, decoder, encoder = map(lambda x: prepare_transcoding_cmdline(x, res.path, src_suffix, dst_suffix, dst_bitrate), [ transcoder, decoder, encoder ])
|
transcoder, decoder, encoder = map(lambda x: prepare_transcoding_cmdline(x, res.path, src_suffix, dst_suffix, dst_bitrate), [ transcoder, decoder, encoder ])
|
||||||
|
|
||||||
decoder = shlex.split(decoder)
|
decoder = map(lambda s: s.decode('UTF8'), shlex.split(decoder.encode('utf8')))
|
||||||
encoder = shlex.split(encoder)
|
encoder = map(lambda s: s.decode('UTF8'), shlex.split(encoder.encode('utf8')))
|
||||||
|
transcoder = map(lambda s: s.decode('UTF8'), shlex.split(transcoder.encode('utf8')))
|
||||||
|
|
||||||
if '|' in shlex.split(transcoder):
|
app.logger.debug(decoder)
|
||||||
transcoder = shlex.split(transcoder)
|
app.logger.debug(encoder)
|
||||||
|
app.logger.debug(transcoder)
|
||||||
|
|
||||||
|
if '|' in transcoder:
|
||||||
pipe_index = transcoder.index('|')
|
pipe_index = transcoder.index('|')
|
||||||
decoder = transcoder[:pipe_index]
|
decoder = transcoder[:pipe_index]
|
||||||
encoder = transcoder[pipe_index+1:]
|
encoder = transcoder[pipe_index+1:]
|
||||||
transcoder = None
|
transcoder = None
|
||||||
|
|
||||||
|
app.logger.warn('decoder' + str(decoder))
|
||||||
|
app.logger.warn('encoder' + str(encoder))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if transcoder:
|
if transcoder:
|
||||||
app.logger.warn('single line transcode: '+transcoder)
|
app.logger.warn('single line transcode: '+transcoder)
|
||||||
proc = subprocess.Popen(shlex.split(transcoder), stdout = subprocess.PIPE, shell=False)
|
proc = subprocess.Popen(transcoder, stdout = subprocess.PIPE, shell=False)
|
||||||
else:
|
else:
|
||||||
app.logger.warn('multi process transcode: ')
|
app.logger.warn('multi process transcode: ')
|
||||||
app.logger.warn('decoder' + str(decoder))
|
|
||||||
app.logger.warn('encoder' + str(encoder))
|
|
||||||
dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE, shell=False)
|
dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE, shell=False)
|
||||||
proc = subprocess.Popen(encoder, stdin = dec_proc.stdout, stdout = subprocess.PIPE, shell=False)
|
proc = subprocess.Popen(encoder, stdin = dec_proc.stdout, stdout = subprocess.PIPE, shell=False)
|
||||||
|
|
||||||
|
24
scanner.py
24
scanner.py
@ -35,23 +35,34 @@ class Scanner:
|
|||||||
valid = [x.lower() for x in config.get('base','filetypes').split(',')]
|
valid = [x.lower() for x in config.get('base','filetypes').split(',')]
|
||||||
print "valid filetypes: ",valid
|
print "valid filetypes: ",valid
|
||||||
|
|
||||||
|
n = 0
|
||||||
for root, subfolders, files in os.walk(folder.path, topdown=False):
|
for root, subfolders, files in os.walk(folder.path, topdown=False):
|
||||||
for f in files:
|
for f in files:
|
||||||
suffix = os.path.splitext(f)[1][1:].lower()
|
suffix = os.path.splitext(f)[1][1:].lower()
|
||||||
|
n += 1
|
||||||
|
if n == 1000:
|
||||||
|
app.logger.debug('commit db')
|
||||||
|
self.__session.commit()
|
||||||
|
n = 0
|
||||||
|
|
||||||
if suffix in valid:
|
if suffix in valid:
|
||||||
try:
|
try:
|
||||||
app.logger.debug('Scanning File: ' + os.path.join(root, f))
|
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)
|
||||||
|
self.__session.flush()
|
||||||
except:
|
except:
|
||||||
app.logger.error('Problem adding file: ' + os.path.join(root,f))
|
app.logger.error('Problem adding file: ' + os.path.join(root,f))
|
||||||
app.logger.error(sys.exc_info())
|
app.logger.error(sys.exc_info())
|
||||||
self.__session.rollback()
|
self.__session.rollback()
|
||||||
self.__session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.__session.commit()
|
||||||
folder.last_scan = int(time.time())
|
folder.last_scan = int(time.time())
|
||||||
|
|
||||||
def prune(self, folder):
|
def prune(self, folder):
|
||||||
for track in [ t for t in self.__tracks if t.root_folder.id == folder.id and not self.__is_valid_path(t.path) ]:
|
for k, track in self.__tracks.iteritems():
|
||||||
|
if track.root_folder.id == folder.id and not self.__is_valid_path(k):
|
||||||
self.__remove_track(track)
|
self.__remove_track(track)
|
||||||
|
|
||||||
for album in [ album for artist in self.__artists for album in artist.albums if len(album.tracks) == 0 ]:
|
for album in [ album for artist in self.__artists for album in artist.albums if len(album.tracks) == 0 ]:
|
||||||
@ -78,9 +89,14 @@ class Scanner:
|
|||||||
return os.path.splitext(path)[1][1:].lower() in self.__extensions
|
return os.path.splitext(path)[1][1:].lower() in self.__extensions
|
||||||
|
|
||||||
def __scan_file(self, path, folder):
|
def __scan_file(self, path, folder):
|
||||||
|
curmtime = int(math.floor(os.path.getmtime(path)))
|
||||||
|
|
||||||
if path in self.__tracks:
|
if path in self.__tracks:
|
||||||
tr = self.__tracks[path]
|
tr = self.__tracks[path]
|
||||||
curmtime = int(math.floor(os.path.getmtime(path)))
|
|
||||||
|
if not tr.last_modification:
|
||||||
|
tr.last_modification = curmtime
|
||||||
|
|
||||||
if curmtime <= tr.last_modification:
|
if curmtime <= tr.last_modification:
|
||||||
app.logger.debug('\tFile not modified')
|
app.logger.debug('\tFile not modified')
|
||||||
return False
|
return False
|
||||||
@ -88,7 +104,6 @@ class Scanner:
|
|||||||
app.logger.debug('\tFile modified, updating tag')
|
app.logger.debug('\tFile modified, updating tag')
|
||||||
app.logger.debug('\tcurmtime %s / last_mod %s', curmtime, tr.last_modification)
|
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))
|
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')
|
app.logger.debug('\tError retrieving tags, removing track from DB')
|
||||||
@ -106,6 +121,7 @@ class Scanner:
|
|||||||
self.__added_tracks += 1
|
self.__added_tracks += 1
|
||||||
print "Added ", path
|
print "Added ", path
|
||||||
|
|
||||||
|
tr.last_modification = curmtime
|
||||||
tr.disc = self.__try_read_tag(tag, 'discnumber', 1, lambda x: int(x[0].split('/')[0]))
|
tr.disc = self.__try_read_tag(tag, 'discnumber', 1, lambda x: int(x[0].split('/')[0]))
|
||||||
tr.number = self.__try_read_tag(tag, 'tracknumber', 1, lambda x: int(x[0].split('/')[0]))
|
tr.number = self.__try_read_tag(tag, 'tracknumber', 1, lambda x: int(x[0].split('/')[0]))
|
||||||
tr.title = self.__try_read_tag(tag, 'title', '')
|
tr.title = self.__try_read_tag(tag, 'title', '')
|
||||||
|
3
web.py
3
web.py
@ -1,13 +1,14 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from flask import Flask, request, session, flash, render_template, redirect, url_for
|
from flask import Flask, request, session, flash, render_template, redirect, url_for
|
||||||
|
import config
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = '?9huDM\\H'
|
app.secret_key = '?9huDM\\H'
|
||||||
|
|
||||||
|
if config.get('base', 'debug'):
|
||||||
app.debug = True
|
app.debug = True
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user