mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Merge branch 'master' into daemon-rework
This commit is contained in:
commit
970ee6ee3c
@ -12,6 +12,7 @@ import mimetypes
|
|||||||
import mutagen
|
import mutagen
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from pony.orm import db_session
|
from pony.orm import db_session
|
||||||
|
|
||||||
from .covers import find_cover_in_folder, CoverFile
|
from .covers import find_cover_in_folder, CoverFile
|
||||||
@ -114,8 +115,9 @@ class Scanner:
|
|||||||
raise TypeError('Expecting string, got ' + str(type(path)))
|
raise TypeError('Expecting string, got ' + str(type(path)))
|
||||||
|
|
||||||
tr = Track.get(path = path)
|
tr = Track.get(path = path)
|
||||||
|
mtime = int(os.path.getmtime(path)) if os.path.exists(path) else 0 # condition for some tests
|
||||||
if tr is not None:
|
if tr is not None:
|
||||||
if not self.__force and not int(os.path.getmtime(path)) > tr.last_modification:
|
if not self.__force and not mtime > tr.last_modification:
|
||||||
return
|
return
|
||||||
|
|
||||||
tag = self.__try_load_tag(path)
|
tag = self.__try_load_tag(path)
|
||||||
@ -144,7 +146,7 @@ class Scanner:
|
|||||||
|
|
||||||
trdict['bitrate'] = int(tag.info.bitrate if hasattr(tag.info, 'bitrate') else os.path.getsize(path) * 8 / tag.info.length) // 1000
|
trdict['bitrate'] = int(tag.info.bitrate if hasattr(tag.info, 'bitrate') else os.path.getsize(path) * 8 / tag.info.length) // 1000
|
||||||
trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream'
|
trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream'
|
||||||
trdict['last_modification'] = int(os.path.getmtime(path))
|
trdict['last_modification'] = mtime
|
||||||
|
|
||||||
tralbum = self.__find_album(albumartist, album)
|
tralbum = self.__find_album(albumartist, album)
|
||||||
trartist = self.__find_artist(artist)
|
trartist = self.__find_artist(artist)
|
||||||
@ -154,6 +156,7 @@ class Scanner:
|
|||||||
trdict['folder'] = self.__find_folder(path)
|
trdict['folder'] = self.__find_folder(path)
|
||||||
trdict['album'] = tralbum
|
trdict['album'] = tralbum
|
||||||
trdict['artist'] = trartist
|
trdict['artist'] = trartist
|
||||||
|
trdict['created'] = datetime.fromtimestamp(mtime)
|
||||||
|
|
||||||
Track(**trdict)
|
Track(**trdict)
|
||||||
self.__stats.added.tracks += 1
|
self.__stats.added.tracks += 1
|
||||||
@ -284,7 +287,8 @@ class Scanner:
|
|||||||
if folder is not None:
|
if folder is not None:
|
||||||
break
|
break
|
||||||
|
|
||||||
children.append(dict(root = False, name = os.path.basename(path), path = path))
|
created = datetime.fromtimestamp(os.path.getmtime(path))
|
||||||
|
children.append(dict(root = False, name = os.path.basename(path), path = path, created = created))
|
||||||
path = os.path.dirname(path)
|
path = os.path.dirname(path)
|
||||||
|
|
||||||
assert folder is not None
|
assert folder is not None
|
||||||
|
23
supysonic/utils.py
Normal file
23
supysonic/utils.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
#
|
||||||
|
# This file is part of Supysonic.
|
||||||
|
# Supysonic is a Python implementation of the Subsonic server API.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2019 Alban 'spl0k' Féron
|
||||||
|
#
|
||||||
|
# Distributed under terms of the GNU AGPLv3 license.
|
||||||
|
|
||||||
|
from base64 import b64encode, b64decode
|
||||||
|
from os import urandom
|
||||||
|
from pony.orm import db_session, ObjectNotFound
|
||||||
|
|
||||||
|
from supysonic.db import Meta
|
||||||
|
|
||||||
|
@db_session
|
||||||
|
def get_secret_key(keyname):
|
||||||
|
try:
|
||||||
|
key = b64decode(Meta[keyname].value)
|
||||||
|
except ObjectNotFound:
|
||||||
|
key = urandom(128)
|
||||||
|
Meta(key = keyname, value = b64encode(key).decode())
|
||||||
|
return key
|
@ -14,12 +14,13 @@ import logging
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from os import makedirs, path, urandom
|
from os import makedirs, path
|
||||||
from pony.orm import db_session
|
from pony.orm import db_session
|
||||||
|
|
||||||
from .config import IniConfig
|
from .config import IniConfig
|
||||||
from .cache import Cache
|
from .cache import Cache
|
||||||
from .db import init_database
|
from .db import init_database
|
||||||
|
from .utils import get_secret_key
|
||||||
|
|
||||||
logger = logging.getLogger(__package__)
|
logger = logging.getLogger(__package__)
|
||||||
|
|
||||||
@ -69,15 +70,7 @@ def create_application(config = None):
|
|||||||
makedirs(cache_path) # pragma: nocover
|
makedirs(cache_path) # pragma: nocover
|
||||||
|
|
||||||
# Read or create secret key
|
# Read or create secret key
|
||||||
secret_path = path.join(cache_path, 'secret')
|
app.secret_key = get_secret_key('cookies_secret')
|
||||||
if path.exists(secret_path):
|
|
||||||
with io.open(secret_path, 'rb') as f:
|
|
||||||
app.secret_key = f.read()
|
|
||||||
else:
|
|
||||||
secret = urandom(128)
|
|
||||||
with io.open(secret_path, 'wb') as f:
|
|
||||||
f.write(secret)
|
|
||||||
app.secret_key = secret
|
|
||||||
|
|
||||||
# Import app sections
|
# Import app sections
|
||||||
if app.config['WEBAPP']['mount_webui']:
|
if app.config['WEBAPP']['mount_webui']:
|
||||||
|
Loading…
Reference in New Issue
Block a user