示例#1
0
        logger.debug("Tagging files")
        tagHandler.tag_album()

        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()

        if options.replaygain:
            logger.debug("Add ReplayGain tags (if necessary)")
            fileHandler.add_replay_gain_tags()

    # !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:
示例#2
0
        logger.debug("Tagging files")
        tagHandler.tag_album()

        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()

        if options.replaygain:
            logger.debug("Add ReplayGain tags (if necessary)")
            fileHandler.add_replay_gain_tags()

    # !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)
示例#3
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)