def _launch_extras(self): """All the add-on stuff""" music_database_config = get_config()[SECTION_MUSIC_DATABASE] if music_database_config[DATABASE_ENABLED].get(bool): from mserv import databases get_state().music_database = databases.init_database(music_database_config) get_state().beets_database = databases.init_beets_database(music_database_config) databases.register_callbacks() mpd_config = get_config()[SECTION_MPD_SERVERS] mpd_server_configs = mpd_config.all_contents() for mpd_server_config in mpd_server_configs: mpd_server = MpdServer.create(mpd_server_config.get(MPD_SERVER, None)) mpd_server.init_all() mpdserver.register_callbacks()
def _configure_slimline(): c = get_config()[SECTION_SERVER] slimline_config = slimline.get_config() slimline_config.set_web_bind_address(c[SLIMLINE_BIND_ADDRESS].get(str)) slimline_config.set_web_port(c[SLIMLINE_PORT].get(int)) slimline_config.set_idle_thread_count(c[SLIMLINE_THREADS].get(int)) slimline_config.set_max_extra_threads(c[SLIMLINE_MAX_THREADS].get(int)) slimline.configure(slimline_config)
def match_beets_items_to_music_database_items(mode="all"): if mode == "all": bdb = get_state().beets_database mdb = get_state().music_database beets_base_dir = get_config()[SECTION_MUSIC_DATABASE][BEETS_BASE_DIRECTORY].get() bi_class = bdb.get_model("Items") fe_class = mdb.get_model("FileEntry") bifel_class = mdb.get_model("BeetsItemFileEntryLink") bi_entries = bi_class.select().count() logger.info("Beginning a full BeetsItem -> FileEntry matching for " + str(bi_entries) + " records") for bi in bi_class.select(): beets_id = bi.id # First check it's not got a link already... existing_bifel = bifel_class.select().where(bifel_class.beets_item_id == beets_id).exists() if existing_bifel: logger.debug("Existing match for " + str(beets_id)) else: beets_path = bi.path.decode("utf-8") path_to_find = os.path.relpath(beets_path, beets_base_dir) try: dir_to_find, filename_to_find = os.path.split(path_to_find) fe_instance = fe_class.select()\ .where(fe_class.directory == dir_to_find)\ .where(fe_class.filename == filename_to_find)\ .get() bifel_instance = bifel_class() bifel_instance.file = fe_instance bifel_instance.beets_item_id = beets_id bifel_instance.save() logger.info("Found match for " + str(path_to_find)) except fe_class.DoesNotExist: logger.info("No item found for path " + str(path_to_find) + " from beets item " + str(beets_id)) except ValueError: logger.exception("Problem splitting path " + str(path_to_find)) else: raise Exception("Unsupported mode " + str(mode))
def get_log_file_path(file_key): path = get_config()[SECTION_LOGGING][LOG_DIR].get() file = get_config()[SECTION_LOGGING][file_key].get() return os.path.join(path, file)
def send_logs(reason="unknown"): logger.info("Sending logs") inf = get_log_file_path(LOG_INFO_FILE) subject = " - ".join([str(socket.gethostname()), "mserv", reason]) address = get_config()[SECTION_LOGGING][EMAIL_ADDRESS].get()
def _create_server_temp_dir(): srv_dir = get_config()[SECTION_SERVER][TEMP_DIR].get(str) if not os.path.isdir(srv_dir): logger.debug("Creating " + str(srv_dir)) os.makedirs(srv_dir, exist_ok=True)
def file_scan(): db = get_state().music_database fe_class = db.get_model("FileEntry") base_directory = get_config()[SECTION_MUSIC_DATABASE][MUSIC_BASE_DIRECTORY].get() _scan_dir_recursive_saving_file_entries(base_directory, base_directory, fe_class)