# XXX: revist, but this going away is nice import warnings warnings.filterwarnings("ignore", message="The psycopg2 wheel package will be renamed") from nicfit import getLogger # noqa: E402 from .orm import VARIOUS_ARTISTS_NAME # noqa: E402 from .__about__ import __version__ as version # noqa: E402 log = getLogger(__package__) __all__ = ["log", "getLogger", "version", "VARIOUS_ARTISTS_NAME"]
from sqlalchemy_utils.functions import (database_exists, create_database, drop_database) from .orm import TYPES, TABLES from .orm import Base, Artist, Track, Album DEFAULT_ENGINE_ARGS = {"convert_unicode": True, "encoding": "utf8", "echo": False, } DEFAULT_SESSION_ARGS = { } log = nicfit.getLogger(__name__) def init(config, engine_args=None, session_args=None, trans_mgr=None): url = config.db_url log.debug("Checking for database '%s'" % url) if not database_exists(url): log.info("Creating database '%s'" % url) create_database(url, template="template0") log.debug("Connecting to database '%s'" % url) args = engine_args or DEFAULT_ENGINE_ARGS engine = create_engine(url, **args) engine.connect()
import multiprocessing from time import time from pathlib import Path from itertools import chain from inotify.adapters import Inotify from inotify.constants import (IN_ACCESS, IN_ALL_EVENTS, IN_ATTRIB, IN_CLOSE_WRITE, IN_CLOSE_NOWRITE, IN_CREATE, IN_DELETE, IN_ISDIR, IN_OPEN, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM) from nicfit import getLogger log = getLogger(__name__) SYNC_INTERVAL = 10 class Monitor(multiprocessing.Process): def __init__(self): self._inotify = Inotify() self._inotify_mask = IN_ALL_EVENTS & (~IN_ACCESS & ~IN_OPEN & ~IN_CLOSE_NOWRITE & ~IN_CLOSE_WRITE) self._dir_queue = multiprocessing.Queue() self._sync_queue = multiprocessing.Queue() self._watched_dirs = {} # {lib_name: set(dirs)} super().__init__(target=self._main, args=(self._dir_queue,
import os import nicfit from nicfit.console import pout from nicfit.console.ansi import Fg from ...orm import VARIOUS_ARTISTS_ID from ...orm import Artist, Track, Album log = nicfit.getLogger(__name__) def deleteOrphans(session): num_orphaned_artists = 0 num_orphaned_albums = 0 num_orphaned_tracks = 0 found_ids = set() # Tracks for track in session.query(Track).all(): if not os.path.exists(track.path): pout(Fg.red("Removing track") + ": " + track.path) session.delete(track) num_orphaned_tracks += 1 log.warn("Deleting track: %s" % str(track)) session.flush() # Artists found_ids.clear() for artist in session.query(Artist).all(): if (artist.id == VARIOUS_ARTISTS_ID or artist.id in found_ids):
# -*- coding: utf-8 -*- from nicfit import getLogger from .__about__ import __version__ as version log = getLogger(__package__) __all__ = ["log", "getLogger", "version"]
from eyed3.core import (TXXX_ALBUM_TYPE, VARIOUS_TYPE, LP_TYPE, SINGLE_TYPE, EP_TYPE) from nicfit.console.ansi import Fg from nicfit.console import pout, perr from ...orm import (Track, Artist, Album, Meta, Image, Library, VARIOUS_ARTISTS_ID, MAIN_LIB_NAME) from ... import console from ... import database as db from ...core import Command, EP_MAX_SIZE_HINT from ...config import MusicLibrary from ._inotify import Monitor, SYNC_INTERVAL from .utils import syncImage, deleteOrphans log = getLogger(__name__) IMAGE_TYPES = { "artist": (Image.LOGO_TYPE, Image.ARTIST_TYPE, Image.LIVE_TYPE), "album": (Image.FRONT_COVER_TYPE, Image.BACK_COVER_TYPE, Image.MISC_COVER_TYPE), } class SyncPlugin(LoaderPlugin): """An eyeD3 file scanner/loader plugin.""" NAMES = ['mishmash-sync'] SUMMARY = u"Synchronize files/directories with a Mishmash database." DESCRIPTION = u"" def __init__(self, arg_parser):