Ejemplo n.º 1
0
def _configure(options):
    """Amend the global configuration object with command line options.
    """
    # Add any additional config files specified with --config. This
    # special handling lets specified plugins get loaded before we
    # finish parsing the command line.
    if getattr(options, 'config', None) is not None:
        config_path = options.config
        del options.config
        config.set_file(config_path)
    config.set_args(options)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    config_path = config.user_config_path()
    if os.path.isfile(config_path):
        log.debug('user configuration: {0}'.format(
            util.displayable_path(config_path)))
    else:
        log.debug('no user configuration found at {0}'.format(
            util.displayable_path(config_path)))

    log.debug(u'data directory: {0}'
              .format(util.displayable_path(config.config_dir())))
    return config
Ejemplo n.º 2
0
def _raw_main(args):
    """A helper function for `main` without top-level exception
    handling.
    """
    # Temporary: Migrate from 1.0-style configuration.
    from beets.ui import migrate

    migrate.automigrate()

    # Get the default subcommands.
    from beets.ui.commands import default_commands

    # Add plugin paths.
    sys.path += get_plugin_paths()
    # Load requested plugins.
    plugins.load_plugins(config["plugins"].as_str_seq())
    plugins.send("pluginload")

    # Construct the root parser.
    commands = list(default_commands)
    commands += plugins.commands()
    commands.append(migrate.migrate_cmd)  # Temporary.
    parser = SubcommandsOptionParser(subcommands=commands)
    parser.add_option("-l", "--library", dest="library", help="library database file to use")
    parser.add_option("-d", "--directory", dest="directory", help="destination music directory")
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="print debugging information")

    # Parse the command-line!
    options, subcommand, suboptions, subargs = parser.parse_args(args)
    config.set_args(options)

    # Open library file.
    dbpath = config["library"].as_filename()
    try:
        lib = library.Library(dbpath, config["directory"].as_filename(), get_path_formats(), get_replacements())
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(util.displayable_path(dbpath)))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config["verbose"].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(
        u"data directory: {0}\n"
        u"library database: {1}\n"
        u"library directory: {2}".format(
            util.displayable_path(config.config_dir()),
            util.displayable_path(lib.path),
            util.displayable_path(lib.directory),
        )
    )

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send("cli_exit", lib=lib)
Ejemplo n.º 3
0
def _configure(options):
    """Amend the global configuration object with command line options.
    """
    # Add any additional config files specified with --config. This
    # special handling lets specified plugins get loaded before we
    # finish parsing the command line.
    if getattr(options, 'config', None) is not None:
        overlay_path = options.config
        del options.config
        config.set_file(overlay_path)
    else:
        overlay_path = None
    config.set_args(options)

    # Configure the logger.
    if config['verbose'].get(int):
        log.set_global_level(logging.DEBUG)
    else:
        log.set_global_level(logging.INFO)

    if overlay_path:
        log.debug(u'overlaying configuration: {0}',
                  util.displayable_path(overlay_path))

    config_path = config.user_config_path()
    if os.path.isfile(config_path):
        log.debug(u'user configuration: {0}',
                  util.displayable_path(config_path))
    else:
        log.debug(u'no user configuration found at {0}',
                  util.displayable_path(config_path))

    log.debug(u'data directory: {0}',
              util.displayable_path(config.config_dir()))
    return config
Ejemplo n.º 4
0
def _raw_main(args, lib=None):
    """A helper function for `main` without top-level exception
    handling.
    """
    subcommand, suboptions, subargs = _configure(args)

    if lib is None:
        # Open library file.
        dbpath = config['library'].as_filename()
        try:
            lib = library.Library(
                dbpath,
                config['directory'].as_filename(),
                get_path_formats(),
                get_replacements(),
            )
        except sqlite3.OperationalError:
            raise UserError(u"database file {0} could not be opened".format(
                util.displayable_path(dbpath)))
        plugins.send("library_opened", lib=lib)

    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'.format(
                  util.displayable_path(config.config_dir()),
                  util.displayable_path(lib.path),
                  util.displayable_path(lib.directory),
              ))

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send('cli_exit', lib=lib)
Ejemplo n.º 5
0
def _raw_main(args, lib=None):
    """A helper function for `main` without top-level exception
    handling.
    """
    subcommand, suboptions, subargs = _configure(args)

    if lib is None:
        # Open library file.
        dbpath = config["library"].as_filename()
        try:
            lib = library.Library(dbpath, config["directory"].as_filename(), get_path_formats(), get_replacements())
        except sqlite3.OperationalError:
            raise UserError(u"database file {0} could not be opened".format(util.displayable_path(dbpath)))
        plugins.send("library_opened", lib=lib)

    log.debug(
        u"data directory: {0}\n"
        u"library database: {1}\n"
        u"library directory: {2}".format(
            util.displayable_path(config.config_dir()),
            util.displayable_path(lib.path),
            util.displayable_path(lib.directory),
        )
    )

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send("cli_exit", lib=lib)
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        """Set default values

        `self.config['youtubedl_options']` is a dict with a lot of options
        available from youtube-dl: https://git.io/fN0c7
        """
        super(YdlPlugin, self).__init__()

        self.search_query = "https://www.youtube.com/results?search_query="
        self.config_dir = config.config_dir()
        self.cache_dir = self.config_dir + "/ydl-cache"
        self.outtmpl = self.cache_dir + "/%(id)s/%(id)s.%(ext)s"

        # Default options
        self._config = {
            'urls': [],
            'verbose': False,
            'youtubedl_options': {
                'verbose':
                False,
                'keepvideo':
                False,
                'cachedir':
                self.cache_dir,
                'outtmpl':
                self.outtmpl,
                'restrictfilenames':
                True,
                'ignoreerrors':
                True,
                'nooverwrites':
                True,
                'writethumbnail':
                True,
                'quiet':
                True,
                'usenetrc':
                os.path.exists(os.path.join(str(Path.home()), ".netrc")),
                'format':
                'bestaudio/best',
                'postprocessors': [{
                    'key': 'FFmpegExtractAudio',
                    'preferredcodec': 'mp3',
                    'preferredquality': '192',
                    'nopostoverwrites': True
                }]
            }
        }
        self._config.update(self.config)
        self.config = self._config

        # be verbose if beets is verbose
        if not self.config.get('verbose'):
            self.config['verbose'] = True
Ejemplo n.º 7
0
def _configure(options):
    """Amend the global configuration object with command line options.
    """
    # Add any additional config files specified with --config. This
    # special handling lets specified plugins get loaded before we
    # finish parsing the command line.
    if getattr(options, b'config', None) is not None:
        config_path = options.config
        del options.config
        config.set_file(config_path)
    config.set_args(options)

    # Configure the logger.
    if config['verbose'].get(int):
        log.set_global_level(logging.DEBUG)
    else:
        log.set_global_level(logging.INFO)

    # Ensure compatibility with old (top-level) color configuration.
    # Deprecation msg to motivate user to switch to config['ui']['color].
    if config['color'].exists():
        log.warning(u'Warning: top-level configuration of `color` '
                    u'is deprecated. Configure color use under `ui`. '
                    u'See documentation for more info.')
        config['ui']['color'].set(config['color'].get(bool))

    # Compatibility from list_format_{item,album} to format_{item,album}
    for elem in ('item', 'album'):
        old_key = 'list_format_{0}'.format(elem)
        if config[old_key].exists():
            new_key = 'format_{0}'.format(elem)
            log.warning(
                u'Warning: configuration uses "{0}" which is deprecated'
                u' in favor of "{1}" now that it affects all commands. '
                u'See changelog & documentation.',
                old_key,
                new_key,
            )
            config[new_key].set(config[old_key])

    config_path = config.user_config_path()
    if os.path.isfile(config_path):
        log.debug(u'user configuration: {0}',
                  util.displayable_path(config_path))
    else:
        log.debug(u'no user configuration found at {0}',
                  util.displayable_path(config_path))

    log.debug(u'data directory: {0}',
              util.displayable_path(config.config_dir()))
    return config
Ejemplo n.º 8
0
def _configure(options):
    """Amend the global configuration object with command line options.
    """
    # Add any additional config files specified with --config. This
    # special handling lets specified plugins get loaded before we
    # finish parsing the command line.
    if getattr(options, 'config', None) is not None:
        config_path = options.config
        del options.config
        config.set_file(config_path)
    config.set_args(options)

    # Configure the logger.
    if config['verbose'].get(int):
        log.set_global_level(logging.DEBUG)
    else:
        log.set_global_level(logging.INFO)

    # Ensure compatibility with old (top-level) color configuration.
    # Deprecation msg to motivate user to switch to config['ui']['color].
    if config['color'].exists():
        log.warning(u'Warning: top-level configuration of `color` '
                    u'is deprecated. Configure color use under `ui`. '
                    u'See documentation for more info.')
        config['ui']['color'].set(config['color'].get(bool))

    # Compatibility from list_format_{item,album} to format_{item,album}
    for elem in ('item', 'album'):
        old_key = 'list_format_{0}'.format(elem)
        if config[old_key].exists():
            new_key = 'format_{0}'.format(elem)
            log.warning(
                u'Warning: configuration uses "{0}" which is deprecated'
                u' in favor of "{1}" now that it affects all commands. '
                u'See changelog & documentation.',
                old_key,
                new_key,
            )
            config[new_key].set(config[old_key])

    config_path = config.user_config_path()
    if os.path.isfile(config_path):
        log.debug(u'user configuration: {0}',
                  util.displayable_path(config_path))
    else:
        log.debug(u'no user configuration found at {0}',
                  util.displayable_path(config_path))

    log.debug(u'data directory: {0}',
              util.displayable_path(config.config_dir()))
    return config
Ejemplo n.º 9
0
def _raw_main(args):
    """A helper function for `main` without top-level exception
    handling.
    """
    subcommand, suboptions, subargs = _configure(args)

    # Open library file.
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            get_replacements(),
        )
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)
        ))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'
        .format(
            util.displayable_path(config.config_dir()),
            util.displayable_path(lib.path),
            util.displayable_path(lib.directory),
        )
    )

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send('cli_exit', lib=lib)
Ejemplo n.º 10
0
def _configure(options):
    """Amend the global configuration object with command line options.
    """
    # Add any additional config files specified with --config. This
    # special handling lets specified plugins get loaded before we
    # finish parsing the command line.
    if getattr(options, b'config', None) is not None:
        config_path = options.config
        del options.config
        config.set_file(config_path)
    config.set_args(options)

    # Configure the logger.
    if config['verbose'].get(int):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    # Ensure compatibility with old (top-level) color configuration.
    # Deprecation msg to motivate user to switch to config['ui']['color].
    if config['color'].exists():
        log.warning(u'Warning: top-level configuration of `color` '
                    u'is deprecated. Configure color use under `ui`. '
                    u'See documentation for more info.')
        config['ui']['color'].set(config['color'].get(bool))

    config_path = config.user_config_path()
    if os.path.isfile(config_path):
        log.debug(u'user configuration: {0}',
                  util.displayable_path(config_path))
    else:
        log.debug(u'no user configuration found at {0}',
                  util.displayable_path(config_path))

    log.debug(u'data directory: {0}',
              util.displayable_path(config.config_dir()))
    return config
Ejemplo n.º 11
0
def _raw_main(args):
    """A helper function for `main` without top-level exception
    handling.
    """
    # Temporary: Migrate from 1.0-style configuration.
    from beets.ui import migrate
    migrate.automigrate()

    # Get the default subcommands.
    from beets.ui.commands import default_commands

    # Add plugin paths.
    sys.path += get_plugin_paths()
    # Load requested plugins.
    plugins.load_plugins(config['plugins'].as_str_seq())
    plugins.send("pluginload")

    # Construct the root parser.
    commands = list(default_commands)
    commands += plugins.commands()
    commands.append(migrate.migrate_cmd)  # Temporary.
    parser = SubcommandsOptionParser(subcommands=commands)
    parser.add_option('-l',
                      '--library',
                      dest='library',
                      help='library database file to use')
    parser.add_option('-d',
                      '--directory',
                      dest='directory',
                      help="destination music directory")
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='print debugging information')

    # Parse the command-line!
    options, subcommand, suboptions, subargs = parser.parse_args(args)
    config.set_args(options)

    # Open library file.
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            get_replacements(),
        )
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'.format(
                  util.displayable_path(config.config_dir()),
                  util.displayable_path(lib.path),
                  util.displayable_path(lib.directory),
              ))

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send('cli_exit', lib=lib)
Ejemplo n.º 12
0
def _raw_main(args, load_config=True):
    """A helper function for `main` without top-level exception
    handling.
    """
    # Load global configuration files.
    if load_config:
        config.read()

    # Temporary: Migrate from 1.0-style configuration.
    from beets.ui import migrate
    if load_config:
        migrate.automigrate()

    # Get the default subcommands.
    from beets.ui.commands import default_commands

    # Add plugin paths.
    sys.path += get_plugin_paths()
    # Load requested plugins.
    plugins.load_plugins(config['plugins'].as_str_seq())
    plugins.send("pluginload")

    # Construct the root parser.
    commands = list(default_commands)
    commands += plugins.commands()
    commands.append(migrate.migrate_cmd)  # Temporary.
    parser = SubcommandsOptionParser(subcommands=commands)
    parser.add_option('-l', '--library', dest='library',
                      help='library database file to use')
    parser.add_option('-d', '--directory', dest='directory',
                      help="destination music directory")
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      help='print debugging information')

    # Parse the command-line!
    options, subcommand, suboptions, subargs = parser.parse_args(args)
    config.set_args(options)

    # Open library file.
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            Template(config['art_filename'].get(unicode)),
            config['timeout'].as_number(),
            get_replacements(),
        )
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)
        ))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'.format(
        util.displayable_path(config.config_dir()),
        util.displayable_path(lib.path),
        util.displayable_path(lib.directory),
    ))

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)