54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
import os
|
|
import logging
|
|
from pysonic.scanner import PysonicFilesystemScanner
|
|
from pysonic.types import MUSIC_TYPES
|
|
|
|
|
|
LETTER_GROUPS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
|
|
"u", "v", "w", "xyz", "0123456789"]
|
|
|
|
|
|
logging = logging.getLogger("library")
|
|
|
|
|
|
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)
|
|
logging.info("library ready")
|
|
|
|
def update(self):
|
|
"""
|
|
Start the library media scanner and
|
|
"""
|
|
self.scanner.init_scan()
|
|
|
|
def add_root_dir(self, path):
|
|
"""
|
|
The music library consists of a number of root dirs. This adds a new root
|
|
"""
|
|
path = os.path.abspath(os.path.normpath(path))
|
|
self.db.add_root(path)
|
|
|
|
|
|
|
|
|
|
|