示例#1
0
def test_overload_config():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == None

    config.read(os.path.join(parentdir, "test/track_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == "myself"
示例#2
0
def test_overload_config():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == None

    config.read(os.path.join(parentdir, "test/track_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == "myself"
示例#3
0
    def test_download_image_with_tokens(self):
        """
            test the download of images with authentification

            Because we would like to test this stuff on travis as well, we cannot store the tokens inside the
            usual "env" variables (otherwise the test test_download_images_wo_tokens would not work), as well
            as not in any config file. We do need to attache them from the travis environment to the tagger_config

            for this test to work, you should set the below mentioned environment variables before running the tesst
            with nosetests -s test/test_discogs.py
        """
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        logger.debug('consumer_key %s' % consumer_key)
        logger.debug('config %s' % config.get("discogs", "consumer_key"))

        discogs_connection = DiscogsConnector(config)
        discogs_connection.fetch_image(os.path.join(self.dummy_dir, 'folder.jpg'), "http://api.discogs.com/image/R-3083-1167766285.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))

        os.remove(os.path.join(self.dummy_dir, 'folder.jpg'))

        discogs_connection.fetch_image(os.path.join(self.dummy_dir, 'folder.jpg'), "http://api.discogs.com/image/R-367882-1193559996.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))
示例#4
0
def test_id_tag_name():

    config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf"))

    assert config.id_tag_name == "discogs_id"

    config = TaggerConfig(os.path.join(parentdir, "test/files/discogs_id.txt"))

    assert config.get("source", "name") == "discogs"
    assert config.id_tag_name == "discogs_id"
    assert config.get("source", config.id_tag_name) == "4712"

    config = TaggerConfig(os.path.join(parentdir, "test/files/multiple_id.txt"))

    assert config.get("source", "name") == "amg"
    assert config.id_tag_name == "amg_id"
    assert config.get("source", config.id_tag_name) == "4711"
示例#5
0
def test_default_values():

    config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))

    assert config.getboolean("details", "keep_original")
    assert not config.getboolean("details", "use_style")
    assert config.getboolean("details", "use_lower_filenames")

    assert config.get("file-formatting", "image") == "image"
示例#6
0
def test_id_tag_name():

    config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf"))

    assert config.id_tag_name == "discogs_id"

    config = TaggerConfig(os.path.join(parentdir, "test/files/discogs_id.txt"))

    assert config.get("source", "name") == "discogs"
    assert config.id_tag_name == "discogs_id"
    assert config.get("source", config.id_tag_name) == "4712"

    config = TaggerConfig(os.path.join(parentdir,
                                       "test/files/multiple_id.txt"))

    assert config.get("source", "name") == "amg"
    assert config.id_tag_name == "amg_id"
    assert config.get("source", config.id_tag_name) == "4711"
示例#7
0
def test_default_values():

    config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))

    assert config.getboolean("details", "keep_original")
    assert not config.getboolean("details", "use_style")
    assert config.getboolean("details", "use_lower_filenames")

    assert config.get("file-formatting", "image") == "image"
示例#8
0
def test_set_values():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert not config.getboolean("details", "keep_original")
    assert config.getboolean("details", "use_style")

    assert config.get("file-formatting", "image") == "XXIMGXX"

    # not overwritten value should stay the same
    assert config.getboolean("details", "use_lower_filenames")
示例#9
0
def test_set_values():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert not config.getboolean("details", "keep_original")
    assert config.getboolean("details", "use_style")

    assert config.get("file-formatting", "image") == "XXIMGXX"

    # not overwritten value should stay the same
    assert config.getboolean("details", "use_lower_filenames")
示例#10
0
    def test_download_image_with_tokens(self):
        """
            test the download of images with authentification

            Because we would like to test this stuff on travis as well, we cannot store the tokens inside the
            usual "env" variables (otherwise the test test_download_images_wo_tokens would not work), as well
            as not in any config file. We do need to attache them from the travis environment to the tagger_config

            for this test to work, you should set the below mentioned environment variables before running the tesst
            with nosetests -s test/test_discogs.py
        """
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        logger.debug('consumer_key %s' % consumer_key)
        logger.debug('config %s' % config.get("discogs", "consumer_key"))

        discogs_connection = DiscogsConnector(config)
        discogs_connection.fetch_image(
            os.path.join(self.dummy_dir, 'folder.jpg'),
            "http://api.discogs.com/image/R-3083-1167766285.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))

        os.remove(os.path.join(self.dummy_dir, 'folder.jpg'))

        discogs_connection.fetch_image(
            os.path.join(self.dummy_dir, 'folder.jpg'),
            "http://api.discogs.com/image/R-367882-1193559996.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))
示例#11
0
p.set_defaults(conffile="../conf/default.conf")

if len(sys.argv) == 1:
    p.print_help()
    sys.exit(1)

(options, args) = p.parse_args()

if not options.releaseid:
    p.error("Please specify a valid releaseid ('-r')")

tagger_config = TaggerConfig(options.conffile)

# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

user_agent = tagger_config.get("common", "user_agent")
client = discogs_client.Client(user_agent)

# allow authentication to be able to download images (use key and secret from config options)
consumer_key = tagger_config.get("discogs", "consumer_key")
consumer_secret = tagger_config.get("discogs", "consumer_secret")

# allow config override thru env variables
if os.environ.has_key("DISCOGS_CONSUMER_KEY"):
    consumer_key = os.environ.get('DISCOGS_CONSUMER_KEY')
if os.environ.has_key("DISCOGS_CONSUMER_SECRET"):
示例#12
0
p.set_defaults(conffile="../conf/default.conf")

if len(sys.argv) == 1:
    p.print_help()
    sys.exit(1)

(options, args) = p.parse_args()

if not options.releaseid:
    p.error("Please specify a valid releaseid ('-r')")

tagger_config = TaggerConfig(options.conffile)

# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

user_agent = tagger_config.get("common", "user_agent")
client = discogs_client.Client(user_agent)

# allow authentication to be able to download images (use key and secret from config options)
consumer_key = tagger_config.get("discogs", "consumer_key")
consumer_secret = tagger_config.get("discogs", "consumer_secret")

# allow config override thru env variables
if os.environ.has_key("DISCOGS_CONSUMER_KEY"):
    consumer_key = os.environ.get('DISCOGS_CONSUMER_KEY')
if os.environ.has_key("DISCOGS_CONSUMER_SECRET"):
示例#13
0
p.set_defaults(forceUpdate=False)
p.set_defaults(replaygain=False)

if len(sys.argv) == 1:
    p.print_help()
    sys.exit(1)

(options, args) = p.parse_args()

if not options.sourcedir or not os.path.exists(options.sourcedir):
    p.error("Please specify a valid source directory ('-s')")

tagger_config = TaggerConfig(options.conffile)

# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

# read necessary config options for batch processing
id_file = tagger_config.get("batch", "id_file")

if options.recursive:
    logger.debug("determine sourcedirs")
    source_dirs = walk_dir_tree(options.sourcedir, id_file)
else:
    logger.debug("using sourcedir: %s" % options.sourcedir)
    source_dirs = [options.sourcedir]

# initialize connection (could be a problem if using multiple sources...)
示例#14
0
p.set_defaults(forceUpdate=False)
p.set_defaults(replaygain=False)

if len(sys.argv) == 1:
    p.print_help()
    sys.exit(1)

(options, args) = p.parse_args()

if not options.sourcedir or not os.path.exists(options.sourcedir):
    p.error("Please specify a valid source directory ('-s')")

tagger_config = TaggerConfig(options.conffile)

# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

# read necessary config options for batch processing
id_file = tagger_config.get("batch", "id_file")

if options.recursive:
    logger.debug("determine sourcedirs")
    source_dirs = walk_dir_tree(options.sourcedir, id_file)
else:
    logger.debug("using sourcedir: %s" % options.sourcedir)
    source_dirs = [options.sourcedir]

# initialize connection (could be a problem if using multiple sources...)
示例#15
0
def test_get():

    config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf"))

    # if the value is emtpy in the config file, it is returned as None
    assert config.get("tags", "encoder") == None
示例#16
0
def processSourceDirs(source_dirs, tagger_config):
    # initialize connection (could be a problem if using multiple sources...)
    discogs_connector = DiscogsConnector(tagger_config)
    local_discogs_connector = LocalDiscogsConnector(discogs_connector)
    # try to re-use search, may be useful if working with several releases by the same artist
    discogsSearch = DiscogsSearch(tagger_config)

    logger.info("start tagging")
    discs_with_errors = []

    converted_discs = 0

    for source_dir in source_dirs:
        releaseid = None
        release = None
        connector = None

        try:
            done_file = tagger_config.get("details", "done_file")
            done_file_path = os.path.join(source_dir, done_file)

            if os.path.exists(done_file_path) and not options.forceUpdate:
                logger.warn(
                    'Do not read {}, because {} exists and forceUpdate is false'
                    .format(source_dir, done_file))
                continue

            # reread config to make sure, that the album specific options are reset for each
            # album
            tagger_config = TaggerConfig(options.conffile)

            if options.releaseid is not None:
                releaseid = options.releaseid
            else:
                releaseid = file_utils.read_id_file(source_dir, id_file,
                                                    options)

            if not releaseid:
                searchParams = discogsSearch.getSearchParams(source_dir)
                # release = discogsSearch.search_discogs(searchParams)
                release = discogsSearch.search_discogs()
                # reuse the Discogs Release class, it saves re-fetching later
                if release is not None and type(release).__name__ in (
                        'Release', 'Version'):
                    releaseid = release.id
                    connector = discogs_connector

            if not releaseid:
                logger.warn('No releaseid for {}'.format(source_dir))
                continue

            # if not releaseid:
            #     p.error("Please specify the discogs.com releaseid ('-r')")

            logger.info('Found release ID: {} for source dir: {}'.format(
                releaseid, source_dir))

            # read destination directory
            # !TODO if both are the same, we are not copying anything,
            # this should be "configurable"
            if not options.destdir:
                destdir = source_dir
            else:
                destdir = options.destdir
                logger.debug('destdir set to {}'.format(options.destdir))

            logger.info('Using destination directory: {}'.format(destdir))
            logger.debug("starting tagging...")

            if releaseid is not None and release is None:
                #! TODO this is dirty, refactor it to be able to reuse it for later enhancements
                if tagger_config.get("source", "name") == "local":
                    release = local_discogs_connector.fetch_release(
                        releaseid, source_dir)
                    connector = local_discogs_connector
                else:
                    release = discogs_connector.fetch_release(releaseid)
                    connector = discogs_connector

            discogs_album = DiscogsAlbum(release)

            try:
                album = discogs_album.map()
            except AlbumError as ae:
                msg = "Error during mapping ({0}), {1}: {2}".format(
                    releaseid, source_dir, ae)
                logger.error(msg)
                discs_with_errors.append(msg)
                continue

            logger.info('Tagging album "{} - {}"'.format(
                album.artist, album.title))

            tagHandler = TagHandler(album, tagger_config)

            taggerUtils = TaggerUtils(source_dir, destdir, tagger_config,
                                      album)

            fileHandler = FileHandler(album, tagger_config)

            try:
                taggerUtils._get_target_list()
            except TaggerError as te:
                msg = "Error during Tagging ({0}), {1}: {2}".format(
                    releaseid, source_dir, te)
                logger.error(msg)
                discs_with_errors.append(msg)
                continue

            tagHandler.tag_album()
            taggerUtils.gather_addional_properties()
            # reset the target directory now that we have discogs metadata and
            #  filedata - otherwise this is declared too early in the process
            album.target_dir = taggerUtils.dest_dir_name

            fileHandler.copy_files()

            logger.debug("Tagging files")

            # Do replaygain analysis before copying other files, the directory
            #  contents are cleaner, less prone to mistakes
            if options.replaygain:
                logger.debug("Add ReplayGain tags (if requested)")
                fileHandler.add_replay_gain_tags()

            logger.debug("Copy other interesting files (on request)")
            fileHandler.copy_other_files()

            logger.debug("Downloading and storing images")
            fileHandler.get_images(connector)

            logger.debug("Embedding Albumart")
            fileHandler.embed_coverart_album()

            # !TODO make this more generic to use different templates and files,
            # furthermore adopt to reflect multi-disc-albums
            logger.debug("Generate m3u")
            taggerUtils.create_m3u(album.target_dir)

            logger.debug("Generate nfo")
            taggerUtils.create_nfo(album.target_dir)

            fileHandler.create_done_file()
        except Exception as ex:
            if releaseid:
                msg = "Error during tagging ({0}), {1}: {2}".format(
                    releaseid, source_dir, ex)
            else:
                msg = "Error during tagging (no relid) {0}: {1}".format(
                    source_dir, ex)
            logger.error(msg)
            discs_with_errors.append(msg)
            continue

        # !TODO - make this a check during the taggerutils run
        # ensure we were able to map the release appropriately.
        #if not release.tag_map:
        #    logger.error("Unable to match file list to discogs release '%s'" %
        #                  releaseid)
        #    sys.exit()
        converted_discs = converted_discs + 1
        logger.info("Converted %d/%d" % (converted_discs, len(source_dirs)))

    logger.info("Tagging complete.")
    logger.info("converted successful: %d" % converted_discs)
    logger.info("converted with Errors %d" % len(discs_with_errors))
    logger.info("releases touched: %s" % len(source_dirs))

    if discs_with_errors:
        logger.error("The following discs could not get converted.")
        for msg in discs_with_errors:
            logger.error(msg)
示例#17
0
(options, args) = p.parse_args()

if not options.sourcedir or not os.path.exists(options.sourcedir):
    p.error("Please specify a valid source directory ('-s')")
else:
    options.sourcedir = os.path.abspath(options.sourcedir)

if options.destdir and os.path.exists(options.destdir):
    options.destdir = os.path.abspath(options.destdir)

tagger_config = TaggerConfig(options.conffile)
# options.replaygain = tagger_config.get("batch", "replaygain")
tagger_config.set('details', 'source_dir', options.sourcedir)
# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

# read necessary config options for batch processing
id_file = tagger_config.get("batch", "id_file")
options.searchDiscogs = tagger_config.get('batch', 'searchDiscogs')
# options.parse_cue_files = tagger_config.get('cue', 'parse_cue_files')

file_utils = FileUtils(tagger_config, options)


def getSourceDirs():
    source_dirs = None
    if options.recursive:
示例#18
0
def test_get():

    config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf"))

# if the value is emtpy in the config file, it is returned as None
    assert config.get("tags", "encoder") == None