mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
WIP rewrite config.py: change several files to use new config
This commit is contained in:
parent
6a6bc577cb
commit
8fe9f9b715
@ -26,7 +26,8 @@ import subprocess
|
||||
import codecs
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from supysonic import config, scanner
|
||||
from supysonic import scanner
|
||||
from supysonic.config import Config
|
||||
from supysonic.web import app, store
|
||||
from supysonic.db import Track, Album, Artist, Folder, User, ClientPrefs, now
|
||||
from . import get_entity
|
||||
@ -70,14 +71,14 @@ def stream_media():
|
||||
|
||||
if format and format != 'raw' and format != src_suffix:
|
||||
dst_suffix = format
|
||||
dst_mimetype = scanner.get_mime(dst_suffix)
|
||||
dst_mimetype = Config().get_mime(dst_suffix)
|
||||
|
||||
if format != 'raw' and (dst_suffix != src_suffix or dst_bitrate != res.bitrate):
|
||||
transcoder = config.get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix))
|
||||
decoder = config.get('transcoding', 'decoder_' + src_suffix) or config.get('transcoding', 'decoder')
|
||||
encoder = config.get('transcoding', 'encoder_' + dst_suffix) or config.get('transcoding', 'encoder')
|
||||
transcoder = Config().get('transcoding', 'transcoder_{}_{}'.format(src_suffix, dst_suffix))
|
||||
decoder = Config().get('transcoding', 'decoder_' + src_suffix) or Config().get('transcoding', 'decoder')
|
||||
encoder = Config().get('transcoding', 'encoder_' + dst_suffix) or Config().get('transcoding', 'encoder')
|
||||
if not transcoder and (not decoder or not encoder):
|
||||
transcoder = config.get('transcoding', 'transcoder')
|
||||
transcoder = Config().get('transcoding', 'transcoder')
|
||||
if not transcoder:
|
||||
message = 'No way to transcode from {} to {}'.format(src_suffix, dst_suffix)
|
||||
app.logger.info(message)
|
||||
@ -153,7 +154,7 @@ def cover_art():
|
||||
if size > im.size[0] and size > im.size[1]:
|
||||
return send_file(os.path.join(res.path, 'cover.jpg'))
|
||||
|
||||
size_path = os.path.join(config.get('webapp', 'cache_dir'), str(size))
|
||||
size_path = os.path.join(Config().get('webapp', 'cache_dir'), str(size))
|
||||
path = os.path.join(size_path, str(res.id))
|
||||
if os.path.exists(path):
|
||||
return send_file(path)
|
||||
|
@ -27,7 +27,7 @@ from storm.variables import Variable
|
||||
import uuid, datetime, time
|
||||
import os.path
|
||||
|
||||
from supysonic import get_mime
|
||||
from supysonic.config import Config
|
||||
|
||||
def now():
|
||||
return datetime.datetime.now().replace(microsecond = 0)
|
||||
@ -213,7 +213,7 @@ class Track(object):
|
||||
|
||||
if prefs and prefs.format and prefs.format != self.suffix():
|
||||
info['transcodedSuffix'] = prefs.format
|
||||
info['transcodedContentType'] = get_mime(prefs.format)
|
||||
info['transcodedContentType'] = Config().get_mime(prefs.format)
|
||||
|
||||
return info
|
||||
|
||||
|
@ -24,7 +24,7 @@ from supysonic.web import app, store
|
||||
from supysonic.managers.user import UserManager
|
||||
from supysonic.db import User, ClientPrefs
|
||||
import uuid, csv
|
||||
from supysonic import config
|
||||
from supysonic.config import Config
|
||||
from supysonic.lastfm import LastFm
|
||||
|
||||
@app.before_request
|
||||
@ -43,12 +43,12 @@ def user_index():
|
||||
def user_profile(uid):
|
||||
if uid == 'me':
|
||||
prefs = store.find(ClientPrefs, ClientPrefs.user_id == uuid.UUID(session.get('userid')))
|
||||
return render_template('profile.html', user = UserManager.get(store, session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
|
||||
return render_template('profile.html', user = UserManager.get(store, session.get('userid'))[1], api_key = Config().get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
|
||||
else:
|
||||
if not UserManager.get(store, session.get('userid'))[1].admin or not UserManager.get(store, uid)[0] is UserManager.SUCCESS:
|
||||
return redirect(url_for('index'))
|
||||
prefs = store.find(ClientPrefs, ClientPrefs.user_id == uuid.UUID(uid))
|
||||
return render_template('profile.html', user = UserManager.get(store, uid)[1], api_key = config.get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
|
||||
return render_template('profile.html', user = UserManager.get(store, uid)[1], api_key = Config().get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin)
|
||||
|
||||
@app.route('/user/<uid>', methods = [ 'POST' ])
|
||||
def update_clients(uid):
|
||||
|
@ -19,13 +19,13 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import requests, hashlib
|
||||
from supysonic import config
|
||||
from supysonic.config import Config
|
||||
|
||||
class LastFm:
|
||||
def __init__(self, user, logger):
|
||||
self.__user = user
|
||||
self.__api_key = config.get('lastfm', 'api_key')
|
||||
self.__api_secret = config.get('lastfm', 'secret')
|
||||
self.__api_key = Config().get('lastfm', 'api_key')
|
||||
self.__api_secret = Config().get('lastfm', 'secret')
|
||||
self.__enabled = self.__api_key is not None and self.__api_secret is not None
|
||||
self.__logger = logger
|
||||
|
||||
|
@ -25,7 +25,7 @@ import mutagen
|
||||
from storm.expr import ComparableExpr, compile, Like
|
||||
from storm.exceptions import NotSupportedError
|
||||
|
||||
from supysonic import config, get_mime
|
||||
from supysonic.config import Config
|
||||
from supysonic.db import Folder, Artist, Album, Track, User, PlaylistTrack
|
||||
from supysonic.db import StarredFolder, StarredArtist, StarredAlbum, StarredTrack
|
||||
from supysonic.db import RatingFolder, RatingTrack
|
||||
@ -63,7 +63,7 @@ class Scanner:
|
||||
self.__deleted_albums = 0
|
||||
self.__deleted_tracks = 0
|
||||
|
||||
extensions = config.get('base', 'scanner_extensions')
|
||||
extensions = Config().get('base', 'scanner_extensions')
|
||||
self.__extensions = map(str.lower, extensions.split()) if extensions else None
|
||||
|
||||
self.__folders_to_check = set()
|
||||
@ -166,7 +166,7 @@ class Scanner:
|
||||
tr.duration = int(tag.info.length)
|
||||
|
||||
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 = Config().get_mime(os.path.splitext(path)[1][1:])
|
||||
tr.last_modification = os.path.getmtime(path)
|
||||
|
||||
tralbum = self.__find_album(albumartist, album)
|
||||
|
@ -26,7 +26,8 @@ from logging.handlers import TimedRotatingFileHandler
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
|
||||
from supysonic import config, db
|
||||
from supysonic import db
|
||||
from supysonic.config import Config
|
||||
from supysonic.scanner import Scanner
|
||||
|
||||
OP_SCAN = 1
|
||||
@ -35,7 +36,7 @@ OP_MOVE = 4
|
||||
|
||||
class SupysonicWatcherEventHandler(PatternMatchingEventHandler):
|
||||
def __init__(self, queue, logger):
|
||||
extensions = config.get('base', 'scanner_extensions')
|
||||
extensions = Config().get('base', 'scanner_extensions')
|
||||
patterns = map(lambda e: "*." + e.lower(), extensions.split()) if extensions else None
|
||||
super(SupysonicWatcherEventHandler, self).__init__(patterns = patterns, ignore_directories = True)
|
||||
|
||||
@ -132,7 +133,7 @@ class ScannerProcessingQueue(Thread):
|
||||
continue
|
||||
|
||||
self.__logger.debug("Instantiating scanner")
|
||||
store = db.get_store(config.get('base', 'database_uri'))
|
||||
store = db.get_store(Config().get('base', 'database_uri'))
|
||||
scanner = Scanner(store)
|
||||
|
||||
item = self.__next_item()
|
||||
@ -200,17 +201,17 @@ class ScannerProcessingQueue(Thread):
|
||||
|
||||
class SupysonicWatcher(object):
|
||||
def run(self):
|
||||
if not config.check():
|
||||
if not Config().check():
|
||||
return
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
if config.get('daemon', 'log_file'):
|
||||
log_handler = TimedRotatingFileHandler(config.get('daemon', 'log_file'), when = 'midnight')
|
||||
if Config().get('daemon', 'log_file'):
|
||||
log_handler = TimedRotatingFileHandler(Config().get('daemon', 'log_file'), when = 'midnight')
|
||||
else:
|
||||
log_handler = logging.NullHandler()
|
||||
log_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
|
||||
logger.addHandler(log_handler)
|
||||
if config.get('daemon', 'log_level'):
|
||||
if Config().get('daemon', 'log_level'):
|
||||
mapping = {
|
||||
'DEBUG': logging.DEBUG,
|
||||
'INFO': logging.INFO,
|
||||
@ -218,9 +219,9 @@ class SupysonicWatcher(object):
|
||||
'ERROR': logging.ERROR,
|
||||
'CRTICAL': logging.CRITICAL
|
||||
}
|
||||
logger.setLevel(mapping.get(config.get('daemon', 'log_level').upper(), logging.NOTSET))
|
||||
logger.setLevel(mapping.get(Config().get('daemon', 'log_level').upper(), logging.NOTSET))
|
||||
|
||||
store = db.get_store(config.get('base', 'database_uri'))
|
||||
store = db.get_store(Config().get('base', 'database_uri'))
|
||||
folders = store.find(db.Folder, db.Folder.root == True)
|
||||
|
||||
if not folders.count():
|
||||
|
Loading…
Reference in New Issue
Block a user