2017-08-13 18:56:13 -07:00
|
|
|
import os
|
2017-08-13 21:13:46 -07:00
|
|
|
import logging
|
2017-08-13 18:56:13 -07:00
|
|
|
from pysonic.scanner import PysonicFilesystemScanner
|
2017-08-16 00:05:26 -07:00
|
|
|
from pysonic.types import MUSIC_TYPES
|
2017-08-13 18:56:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
LETTER_GROUPS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
|
2017-08-13 21:13:46 -07:00
|
|
|
"u", "v", "w", "xyz", "0123456789"]
|
|
|
|
|
|
|
|
|
|
|
|
logging = logging.getLogger("library")
|
2017-08-13 18:56:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
def memoize(function):
|
|
|
|
memo = {}
|
|
|
|
|
|
|
|
def wrapper(*args):
|
|
|
|
if args in memo:
|
|
|
|
return memo[args]
|
|
|
|
else:
|
|
|
|
rv = function(*args)
|
|
|
|
memo[args] = rv
|
|
|
|
return rv
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
class NoDataException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class PysonicLibrary(object):
|
|
|
|
def __init__(self, database):
|
|
|
|
self.db = database
|
|
|
|
self.scanner = PysonicFilesystemScanner(self)
|
2017-08-13 21:13:46 -07:00
|
|
|
logging.info("library ready")
|
2017-08-13 18:56:13 -07:00
|
|
|
|
|
|
|
def update(self):
|
2018-04-02 21:58:48 -07:00
|
|
|
"""
|
|
|
|
Start the library media scanner and
|
|
|
|
"""
|
2017-08-13 18:56:13 -07:00
|
|
|
self.scanner.init_scan()
|
|
|
|
|
2018-04-02 21:58:48 -07:00
|
|
|
def add_root_dir(self, path):
|
2017-08-13 18:56:13 -07:00
|
|
|
"""
|
2018-04-02 21:58:48 -07:00
|
|
|
The music library consists of a number of root dirs. This adds a new root
|
2017-08-13 18:56:13 -07:00
|
|
|
"""
|
2018-04-02 21:58:48 -07:00
|
|
|
path = os.path.abspath(os.path.normpath(path))
|
|
|
|
self.db.add_root(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-19 22:03:09 -07:00
|
|
|
|