コード例 #1
0
ファイル: scanner.py プロジェクト: rattboi/mopidy
def main():
    options = parse_options()

    log.setup_root_logger()
    log.setup_console_logging(options.verbosity_level)

    tracks = []

    def store(data):
        track = translator(data)
        tracks.append(track)
        logging.debug("Added %s", track.uri)

    def debug(uri, error, debug):
        logging.warning("Failed %s: %s", uri, error)
        logging.debug("Debug info for %s: %s", uri, debug)

    logging.info("Scanning %s", settings.LOCAL_MUSIC_PATH)

    scanner = Scanner(settings.LOCAL_MUSIC_PATH, store, debug)
    try:
        scanner.start()
    except KeyboardInterrupt:
        scanner.stop()

    logging.info("Done scanning; writing tag cache...")

    for row in mpd_translator.tracks_to_tag_cache_format(tracks):
        if len(row) == 1:
            print("%s" % row).encode("utf-8")
        else:
            print("%s: %s" % row).encode("utf-8")

    logging.info("Done writing tag cache")
コード例 #2
0
ファイル: scanner.py プロジェクト: AndreaCrotti/mopidy
def main():
    log.setup_root_logger()
    log.setup_console_logging(2)

    tracks = []

    def store(data):
        track = translator(data)
        tracks.append(track)
        logging.debug('Added %s', track.uri)

    def debug(uri, error, debug):
        logging.error('Failed %s: %s - %s', uri, error, debug)

    logging.info('Scanning %s', settings.LOCAL_MUSIC_PATH)
    scanner = Scanner(settings.LOCAL_MUSIC_PATH, store, debug)
    try:
        scanner.start()
    except KeyboardInterrupt:
        scanner.stop()

    logging.info('Done')

    for row in mpd_translator.tracks_to_tag_cache_format(tracks):
        if len(row) == 1:
            print ('%s' % row).encode('utf-8')
        else:
            print ('%s: %s' % row).encode('utf-8')
コード例 #3
0
ファイル: scanner.py プロジェクト: Halfnhav/mopidy
def main():
    options = parse_options()
    # TODO: support config files and overrides (shared from main?)
    config_files = [b'/etc/mopidy/mopidy.conf',
                    b'$XDG_CONFIG_DIR/mopidy/mopidy.conf']
    config_overrides = []

    # TODO: decide if we want to avoid this boilerplate some how.
    # Initial config without extensions to bootstrap logging.
    logging_config, _ = config_lib.load(config_files, [], config_overrides)
    log.setup_root_logger()
    log.setup_console_logging(logging_config, options.verbosity_level)

    extensions = ext.load_extensions()
    config, errors = config_lib.load(
        config_files, extensions, config_overrides)
    log.setup_log_levels(config)

    if not config['local']['media_dir']:
        logging.warning('Config value local/media_dir is not set.')
        return

    # TODO: missing error checking and other default setup code.

    tracks = []

    def store(data):
        track = translator(data)
        tracks.append(track)
        logging.debug('Added %s', track.uri)

    def debug(uri, error, debug):
        logging.warning('Failed %s: %s', uri, error)
        logging.debug('Debug info for %s: %s', uri, debug)

    logging.info('Scanning %s', config['local']['media_dir'])

    scanner = Scanner(config['local']['media_dir'], store, debug)
    try:
        scanner.start()
    except KeyboardInterrupt:
        scanner.stop()

    logging.info('Done scanning; writing tag cache...')

    for row in mpd_translator.tracks_to_tag_cache_format(
            tracks, config['local']['media_dir']):
        if len(row) == 1:
            print ('%s' % row).encode('utf-8')
        else:
            print ('%s: %s' % row).encode('utf-8')

    logging.info('Done writing tag cache')
コード例 #4
0
ファイル: scanner.py プロジェクト: enraknes/Pi-MusicBox
def main():
    args = parse_args()
    # TODO: support config files and overrides (shared from main?)
    config_files = [b'/etc/mopidy/mopidy.conf',
                    b'$XDG_CONFIG_DIR/mopidy/mopidy.conf']
    config_overrides = []

    # TODO: decide if we want to avoid this boilerplate some how.
    # Initial config without extensions to bootstrap logging.
    logging_config, _ = config_lib.load(config_files, [], config_overrides)
    log.setup_root_logger()
    log.setup_console_logging(logging_config, args.verbosity_level)

    extensions = ext.load_extensions()
    config, errors = config_lib.load(
        config_files, extensions, config_overrides)
    log.setup_log_levels(config)

    if not config['local']['media_dir']:
        logging.warning('Config value local/media_dir is not set.')
        return

    if not config['local']['scan_timeout']:
        logging.warning('Config value local/scan_timeout is not set.')
        return

    # TODO: missing config error checking and other default setup code.

    updaters = {}
    for e in extensions:
        for updater_class in e.get_library_updaters():
            if updater_class and 'local' in updater_class.uri_schemes:
                updaters[e.ext_name] = updater_class

    if not updaters:
        logging.error('No usable library updaters found.')
        return
    elif len(updaters) > 1:
        logging.error('More than one library updater found. '
                      'Provided by: %s', ', '.join(updaters.keys()))
        return

    local_updater = updaters.values()[0](config)  # TODO: switch to actor?

    media_dir = config['local']['media_dir']

    uris_library = set()
    uris_update = set()
    uris_remove = set()

    logging.info('Checking tracks from library.')
    for track in local_updater.load():
        try:
            stat = os.stat(path.uri_to_path(track.uri))
            if int(stat.st_mtime) > track.last_modified:
                uris_update.add(track.uri)
            uris_library.add(track.uri)
        except OSError:
            uris_remove.add(track.uri)

    logging.info('Removing %d moved or deleted tracks.', len(uris_remove))
    for uri in uris_remove:
        local_updater.remove(uri)

    logging.info('Checking %s for new or modified tracks.', media_dir)
    for uri in path.find_uris(config['local']['media_dir']):
        if uri not in uris_library:
            uris_update.add(uri)

    logging.info('Found %d new or modified tracks.', len(uris_update))

    def store(data):
        track = translator(data)
        local_updater.add(track)
        logging.debug('Added %s', track.uri)

    def debug(uri, error, debug):
        logging.warning('Failed %s: %s', uri, error)
        logging.debug('Debug info for %s: %s', uri, debug)

    scan_timeout = config['local']['scan_timeout']

    logging.info('Scanning new and modified tracks.')
    # TODO: just pass the library in instead?
    scanner = Scanner(uris_update, store, debug, scan_timeout)
    try:
        scanner.start()
    except KeyboardInterrupt:
        scanner.stop()
        raise

    logging.info('Done scanning; commiting changes.')
    local_updater.commit()