def test_remove_source_dir(self): self.album.sourcedir = self.source_dir assert self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) target_file = os.path.join(self.album.sourcedir, "id.txt") shutil.copyfile(self.source_copy_file, target_file) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert os.path.exists(self.album.sourcedir) assert os.path.exists(target_file) # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/test_values.conf")) assert not self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert not os.path.exists(self.album.sourcedir) assert not os.path.exists(target_file)
def test_get_without_quotation(): config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf")) # if the value in the config file contains quotation marks, remove those assert config.get_without_quotation("details", "join_genres_and_styles") == " & "
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"
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")
def test_copy_other_files(self): assert not self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir assert not os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/test_values.conf")) assert self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir logger.debug("album_target_dir: %s" % album_target_dir) assert os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))
def test_get_character_exceptions(): config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) assert len(config.get_character_exceptions) == 10 assert config.get_character_exceptions[" "] == "_" assert config.get_character_exceptions["\xc3\xb6"] == "oe" config = TaggerConfig(os.path.join(parentdir, "test/track_values.conf")) logger.debug("config: %s" % config.get_character_exceptions) assert len(config.get_character_exceptions) == 11 assert config.get_character_exceptions["\xc3\xa2"] == "a"
def test_get_target_list_with_multiple_release_artists(self): """ Some releases do have multiple release-artists (see 2452735), the release artists are treated differently from the track artists, check it in here, to make sure it is really working (should be in test_discogs.py usually) """ self.ogsrelid = "2454735" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() assert len(self.album.artists) == 2 assert self.album.artists[0] == "Frank Zappa" assert self.album.artists[1] == "Ensemble Modern" assert self.album.artist == "Frank Zappa" assert self.album.discs[0].tracks[0].new_file == "01-frank_zappa-intro"
def test_remove_source_dir(self): self.album.sourcedir = self.source_dir assert self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) target_file = os.path.join(self.album.sourcedir, "id.txt") shutil.copyfile(self.source_copy_file, target_file) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert os.path.exists(self.album.sourcedir) assert os.path.exists(target_file) # construct config with only default values self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) assert not self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert not os.path.exists(self.album.sourcedir) assert not os.path.exists(target_file)
def test_get_target_list_single_disc_with_subtracks(self): """ Some releases do have "subtracks" (see 513904, track 15), which means that there are two tracks assigned to one position (e.g. 15.1 and 15.2). This gets quite complicated, because this is rather similar to the multi-disc handling """ self.ogsrelid = "513904" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() # copy file to source directory and rename it self.copy_files_single_album(14) target_file_name = "513904.json" shutil.copyfile(self.source_copy_file, os.path.join(self.source_dir, target_file_name)) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) try: taggerutils._get_target_list() except TaggerError as te: assert True return assert False
def test_create_file_from_template(self): self.ogsrelid = "3083" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) create_file = os.path.join(self.target_dir, "info.nfo") assert taggerutils.create_file_from_template("/info.txt", create_file) assert os.path.exists(create_file) assert taggerutils.create_nfo(self.target_dir) # copy file to source directory and rename it self.copy_files_single_album(17) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() assert self.album.discs[0].tracks[ 0].new_file == "01-yonderboi-intro.flac" assert taggerutils.create_m3u(self.target_dir)
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"
def test_get_configured_tags(): config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) logger.debug("config.get_configured_tags %s" % config.get_configured_tags) assert len(config.get_configured_tags) == 3 assert config.get_configured_tags["year"] == "1901" assert config.get_configured_tags["title"] == "Title" assert config.get_configured_tags["encoder"] == ""
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"
def setUp(self): self.ogsrelid = "1448190" # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map()
def test_tag_single_album_with_video_tracks(self): self.ogsrelid = "13748" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() # copy file to source directory and rename it self.copy_files_single_album(7) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() testTagHandler = TagHandler(self.album, self.tagger_config) testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_files() testTagHandler.tag_album() target_dir = os.path.join(self.target_dir, self.album.target_dir) metadata = MediaFile( os.path.join(target_dir, "01-coldcut-timber_(chopped_down_radio_edit).flac")) assert metadata.artist == "Coldcut" assert metadata.albumartists == ["Coldcut", "Hexstatic"] assert metadata.discogs_id == self.ogsrelid assert metadata.year == 1998 assert metadata.disctotal == 1 assert metadata.genre == "Electronic" assert metadata.tracktotal == 7 # obviously the encoder element is not in the file, but it is returned # empty anyway, no need to check this then... assert metadata.encoder == None assert metadata.country == "Canada" metadata = MediaFile( os.path.join( target_dir, "07-coldcut-timber_(the_cheech_wizards_polythump_requiem_for_the_ancient_forests_mix).flac" )) assert metadata.artist == "Coldcut" assert metadata.albumartists == ["Coldcut", "Hexstatic"] assert metadata.discogs_id == self.ogsrelid assert metadata.tracktotal == 7
def setUp(self): self.ogsrelid = "1448190" # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/empty.conf")) self.dummy_dir = "/tmp/dummy_test_dir" if not os.path.exists(self.dummy_dir): os.makedirs(self.dummy_dir)
def test_map_singledisc(): ogsrelid = "3083" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(ogsrelid) dummy_discogs_album = DummyDiscogsAlbum(dummy_response) album = dummy_discogs_album.map() assert len(album.labels) == 2 assert album.labels[0] == "Mole Listening Pearls" assert len(album.catnumbers) == len(album.labels) assert album.catnumbers[0] == "MOLECD023-2" assert len(album.images) == 4 assert album.images[ 0] == "http://api.discogs.com/image/R-3083-1167766285.jpeg" assert album.title == "Shallow And Profound" assert len(album.artists) == 1 assert album.artists[0] == "Yonderboi" assert len(album.genres) == 1 assert len(album.styles) == 2 assert not album.is_compilation assert album.disctotal == 1 assert len(album.discs) == album.disctotal assert len(album.discs[0].tracks) == 17 # first track on first disc track = album.discs[0].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 1 assert track.title == "Intro" assert track.artists[0] == "Yonderboi" assert track.non_existent_tag == None # last track on first disc track = album.discs[0].tracks[16] assert track.tracknumber == 17 assert track.discnumber == 1 assert track.title == "Outro" assert track.artists[0] == "Yonderboi" assert track.non_existent_tag == None
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'))
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"
def test_get_images_wo_folderjpg(self): """ Downloads several images from discogs, using authentication This test needs network connection, as well as authentication support """ # construct config with only default values config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( 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.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f))] logger.debug("files: %s " % onlyfiles) logger.debug('checking %s' % self.album.target_dir) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-01.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-02.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-03.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-04.jpg"))
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"
def test_read_token(self): """read the token file, if it exists """ config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) config.set("discogs", "skip_auth", True) discogs_connection = DiscogsConnector(self.tagger_config) filename = discogs_connection.construct_token_file() if os.path.exists(filename): os.remove(filename) access_token, access_secret = discogs_connection.read_token() assert not access_token assert not access_secret with open(filename, 'w') as fh: fh.write('{0},{1}'.format("token", "secret")) access_token, access_secret = discogs_connection.read_token() assert access_token assert access_secret
def test_read_token(self): """read the token file, if it exists """ config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) config.set("discogs", "skip_auth", True) discogs_connection = DiscogsConnector(self.tagger_config) filename = discogs_connection.construct_token_file() if os.path.exists(filename): os.remove(filename) access_token, access_secret = discogs_connection.read_token() assert not access_token assert not access_secret with open(filename, 'w') as fh: fh.write('{0},{1}'.format("token", "secret")) access_token, access_secret = discogs_connection.read_token() assert access_token assert access_secret
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")
def test_copy_other_files(self): assert not self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir assert not os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) # construct config with only default values self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) assert self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir logger.debug("album_target_dir: %s" % album_target_dir) assert os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))
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"
def test_tag_album_wo_country(self): self.ogsrelid = "543030" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() # copy file to source directory and rename it self.copy_files_single_album(11) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() testTagHandler = TagHandler(self.album, self.tagger_config) testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_files() testTagHandler.tag_album() target_dir = os.path.join(self.target_dir, self.album.target_dir) metadata = MediaFile( os.path.join(target_dir, "01-front_242-masterhit.flac")) assert metadata.artist == "Front 242" assert metadata.albumartist == "Front 242" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 1992 assert metadata.disctotal == 1 assert metadata.genre == "Electronic" # obviously the encoder element is not in the file, but it is returned # empty anyway, no need to check this then... assert metadata.encoder == None assert metadata.country == ""
def test_get_images_wo_folderjpg(self): """ Downloads several images from discogs, using authentication This test needs network connection, as well as authentication support """ # construct config with only default values config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( 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.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f)) ] logger.debug("files: %s " % onlyfiles) logger.debug('checking %s' % self.album.target_dir) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-01.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-02.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-03.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-04.jpg"))
def test_get_target_list_single_disc(self): self.ogsrelid = "3083" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() # copy file to source directory and rename it self.copy_files_single_album(17) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() assert self.album.sourcedir == self.source_dir assert self.album.discs[0].sourcedir == None assert self.album.target_dir == os.path.join( self.target_dir, "yonderboi-shallow_and_profound-(molecd023-2)-2000") assert self.album.discs[0].target_dir == None assert self.album.discs[0].tracks[0].orig_file == "01-song.flac" assert self.album.discs[0].tracks[ 0].new_file == "01-yonderboi-intro.flac" assert self.album.discs[0].tracks[16].orig_file == "17-song.flac" assert self.album.discs[0].tracks[ 16].new_file == "17-yonderboi-outro.flac" assert self.album.discs[0].copy_files[0] == "album.cue" assert self.album.discs[0].copy_files[1] == "album.m3u" assert self.album.discs[0].copy_files[2] == "id.txt"
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'))
def test_map_multidisc_with_disctitle_for_tracks(): ogsrelid = "282923" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(ogsrelid) dummy_discogs_album = DummyDiscogsAlbum(dummy_response) album = dummy_discogs_album.map() assert len(album.labels) == 1 assert album.labels[0] == "Columbia" assert len(album.catnumbers) == len(album.labels) assert album.catnumbers[0] == "COL 513783 2" assert album.title == "Live In Concert 2002" assert len(album.artists) == 1 logger.debug("album.artists %s" % album.artists[0]) assert album.artists[0] == "Deine Lakaien" assert len(album.genres) == 1 assert album.genres[0] == "Electronic" assert len(album.styles) == 1 assert album.styles[0] == "Synth-pop" assert not album.is_compilation assert album.disctotal == 2 assert len(album.discs) == album.disctotal assert len(album.discs[0].tracks) == 9 assert len(album.discs[1].tracks) == 13 # first track on first disc track = album.discs[0].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 1 assert not track.discsubtitle assert track.title == "Colour-Ize" assert track.artists[0] == "Deine Lakaien" assert track.non_existent_tag == None # first track on second disc track = album.discs[1].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 2 assert track.title == "Silence In Your Eyes" assert track.discsubtitle == None assert track.artists[0] == "Deine Lakaien" assert track.non_existent_tag == None # last track without disctitle on second disc track = album.discs[1].tracks[10] assert track.tracknumber == 11 assert track.discnumber == 2 assert track.title == "Sometimes" assert track.discsubtitle == None assert track.artists[0] == "Deine Lakaien" assert track.non_existent_tag == None # first track with disctitle on second disc track = album.discs[1].tracks[11] assert track.tracknumber == 12 assert track.discnumber == 2 assert track.title == "Stupid" assert track.discsubtitle == "Bonustracks" assert track.artists[0] == "Deine Lakaien" assert track.non_existent_tag == None
def test_map_multidisc(): ogsrelid = "1448190" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(ogsrelid) dummy_discogs_album = DummyDiscogsAlbum(dummy_response) album = dummy_discogs_album.map() assert len(album.labels) == 1 assert album.labels[0] == "Polystar" assert len(album.catnumbers) == len(album.labels) assert album.catnumbers[0] == "560 938-2" assert len(album.images) == 4 assert album.images[ 0] == "http://api.discogs.com/image/R-1448190-1220476110.jpeg" assert album.title == "Megahits 2001 Die Erste" assert len(album.artists) == 1 assert album.artists[0] == "Various" assert len(album.genres) == 4 assert len(album.styles) == 4 assert album.is_compilation assert album.disctotal == 2 assert len(album.discs) == album.disctotal assert len(album.discs[0].tracks) == 20 assert len(album.discs[1].tracks) == 20 # first track on first disc track = album.discs[0].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 1 assert track.title == "La Passion (Radio Cut)" assert track.artists[0] == "Gigi D'Agostino" assert track.non_existent_tag == None # last track on first disc track = album.discs[0].tracks[19] assert track.tracknumber == 20 assert track.discnumber == 1 assert track.title == "Last Resort (Album Version Explizit)" assert track.artists[0] == "Papa Roach" assert track.non_existent_tag == None # first track on second disc track = album.discs[1].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 2 assert track.title == "Ich Will, Dass Du Mich Liebst (Radio Edit)" assert track.artists[0] == "Die 3. Generation" assert track.non_existent_tag == None # last track on first disc track = album.discs[1].tracks[19] assert track.tracknumber == 20 assert track.discnumber == 2 assert track.title == "I Just Wanna Love U (Give It 2 Me) (Radio Edit)" assert track.artists[0] == "Jay-Z" assert track.non_existent_tag == None # special character handling track = album.discs[1].tracks[18] logger.debug("track.artists: %s" % track.artists[0]) assert track.artists[0] == "D-Flame Feat. Eißfeldt"
help="The directory to copy the json file to") p.add_option("-c", "--conf", action="store", dest="conffile", help="The discogstagger configuration file.") 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
action="store", dest="conffile", help="The discogstagger configuration file.") 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
p.set_defaults(conffile="conf/default.conf") p.set_defaults(recursive=False) 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)
p.set_defaults(conffile="conf/default.conf") p.set_defaults(recursive=False) 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)
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)
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
def test_get_without_quotation(): config = TaggerConfig(os.path.join(parentdir, "test/emtpy.conf")) # if the value in the config file contains quotation marks, remove those assert config.get_without_quotation("details", "join_genres_and_styles") == " & "
class TestFileHandler(TestTaggerUtilFiles): def setUp(self): TestTaggerUtilFiles.setUp(self) self.target_file_name = "test.flac" def tearDown(self): TestTaggerUtilFiles.tearDown(self) self.tagger_config = None def test_remove_source_dir(self): self.album.sourcedir = self.source_dir assert self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) target_file = os.path.join(self.album.sourcedir, "id.txt") shutil.copyfile(self.source_copy_file, target_file) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert os.path.exists(self.album.sourcedir) assert os.path.exists(target_file) # construct config with only default values self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) assert not self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert not os.path.exists(self.album.sourcedir) assert not os.path.exists(target_file) def test_copy_files(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) disc_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir) assert os.path.exists(disc_dir) disc_dir = os.path.join(self.album.target_dir, self.album.disc(2).target_dir) assert os.path.exists(disc_dir) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, self.album.disc(1).track(1).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, self.album.disc(1).track(20).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(2).target_dir, self.album.disc(2).track(1).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(2).target_dir, self.album.disc(2).track(20).new_file) assert os.path.exists(track_file) def test_embed_coverart_track(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) track = self.album.disc(1).track(1) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) source_file = "test/files/cover.jpeg" target_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir) image_file = os.path.join(target_dir, "cover.jpeg") shutil.copyfile(source_file, image_file) imgdata = open(image_file).read() testFileHandler.embed_coverart_track(self.album.disc(1), track, imgdata) assert os.path.exists(track_file) metadata = MediaFile(track_file) assert not metadata.art == None track = self.album.disc(1).track(2) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) metadata = MediaFile(track_file) assert metadata.art == None def test_embed_coverart_album(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) source_file = "test/files/cover.jpeg" image_file = os.path.join(self.album.target_dir, "folder.jpg") shutil.copyfile(source_file, image_file) testFileHandler.embed_coverart_album() track = self.album.disc(1).track(1) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) metadata = MediaFile(track_file) assert not metadata.art == None def test_copy_other_files(self): assert not self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir assert not os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) # construct config with only default values self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) assert self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir logger.debug("album_target_dir: %s" % album_target_dir) assert os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) def test_create_done_file(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testFileHandler = FileHandler(self.album, self.tagger_config) assert not os.path.exists(os.path.join(self.album.sourcedir, "dt.done")) testFileHandler.create_done_file() assert os.path.exists(os.path.join(self.album.sourcedir, "dt.done")) def test_get_images(self): """ It downloads only one image, since this is the default configuration This test needs network connection, as well as authentication support """ testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( consumer_key = None consumer_secret = None 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 = self.tagger_config config.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f))] logger.debug("files: %s " % onlyfiles) assert os.path.exists(os.path.join(self.album.target_dir, "folder.jpg")) assert not os.path.exists(os.path.join(self.album.target_dir, "image-01.jpg")) def test_get_images_wo_folderjpg(self): """ Downloads several images from discogs, using authentication This test needs network connection, as well as authentication support """ # construct config with only default values config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( 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.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f))] logger.debug("files: %s " % onlyfiles) logger.debug('checking %s' % self.album.target_dir) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-01.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-02.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-03.jpg")) assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-04.jpg")) test_get_images.needs_network = True test_get_images.needs_authentication = True test_get_images_wo_folderjpg.needs_network = True test_get_images_wo_folderjpg.needs_authentication = True
class TestFileHandler(TestTaggerUtilFiles): def setUp(self): TestTaggerUtilFiles.setUp(self) self.target_file_name = "test.flac" def tearDown(self): TestTaggerUtilFiles.tearDown(self) self.tagger_config = None def test_remove_source_dir(self): self.album.sourcedir = self.source_dir assert self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) target_file = os.path.join(self.album.sourcedir, "id.txt") shutil.copyfile(self.source_copy_file, target_file) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert os.path.exists(self.album.sourcedir) assert os.path.exists(target_file) # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/test_values.conf")) assert not self.tagger_config.getboolean("details", "keep_original") testFileHandler = FileHandler(self.album, self.tagger_config) assert os.path.exists(target_file) testFileHandler.remove_source_dir() assert not os.path.exists(self.album.sourcedir) assert not os.path.exists(target_file) def test_copy_files(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) disc_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir) assert os.path.exists(disc_dir) disc_dir = os.path.join(self.album.target_dir, self.album.disc(2).target_dir) assert os.path.exists(disc_dir) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, self.album.disc(1).track(1).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, self.album.disc(1).track(20).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(2).target_dir, self.album.disc(2).track(1).new_file) assert os.path.exists(track_file) track_file = os.path.join(self.album.target_dir, self.album.disc(2).target_dir, self.album.disc(2).track(20).new_file) assert os.path.exists(track_file) def test_embed_coverart_track(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) track = self.album.disc(1).track(1) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) source_file = "test/files/cover.jpeg" target_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir) image_file = os.path.join(target_dir, "cover.jpeg") shutil.copyfile(source_file, image_file) imgdata = open(image_file).read() testFileHandler.embed_coverart_track(self.album.disc(1), track, imgdata) assert os.path.exists(track_file) metadata = MediaFile(track_file) assert not metadata.art == None track = self.album.disc(1).track(2) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) metadata = MediaFile(track_file) assert metadata.art == None def test_embed_coverart_album(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler.copy_files() assert os.path.exists(self.album.sourcedir) assert os.path.exists(self.album.target_dir) source_file = "test/files/cover.jpeg" image_file = os.path.join(self.album.target_dir, "folder.jpg") shutil.copyfile(source_file, image_file) testFileHandler.embed_coverart_album() track = self.album.disc(1).track(1) track_file = os.path.join(self.album.target_dir, self.album.disc(1).target_dir, track.new_file) metadata = MediaFile(track_file) assert not metadata.art == None def test_copy_other_files(self): assert not self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir assert not os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert not os.path.exists(os.path.join(disc_target_dir, "album.cue")) # construct config with only default values self.tagger_config = TaggerConfig( os.path.join(parentdir, "test/test_values.conf")) assert self.tagger_config.getboolean("details", "copy_other_files") testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) testFileHandler = FileHandler(self.album, self.tagger_config) self.copy_files(self.album) testFileHandler.copy_other_files() album_target_dir = self.album.target_dir logger.debug("album_target_dir: %s" % album_target_dir) assert os.path.exists(os.path.join(album_target_dir, "id.txt")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir) assert os.path.exists(os.path.join(disc_target_dir, "album.cue")) def test_create_done_file(self): testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testFileHandler = FileHandler(self.album, self.tagger_config) assert not os.path.exists(os.path.join(self.album.sourcedir, "dt.done")) testFileHandler.create_done_file() assert os.path.exists(os.path.join(self.album.sourcedir, "dt.done")) def test_get_images(self): """ It downloads only one image, since this is the default configuration This test needs network connection, as well as authentication support """ testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( consumer_key = None consumer_secret = None 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 = self.tagger_config config.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f)) ] logger.debug("files: %s " % onlyfiles) assert os.path.exists(os.path.join(self.album.target_dir, "folder.jpg")) assert not os.path.exists( os.path.join(self.album.target_dir, "image-01.jpg")) def test_get_images_wo_folderjpg(self): """ Downloads several images from discogs, using authentication This test needs network connection, as well as authentication support """ # construct config with only default values config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf")) testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config, self.album) self.copy_files(self.album) testTagUtils._get_target_list() # the following stuff is only needed in the test, since we cannot use # a config option for these values ;-( # we are unfortunately treated to login every time this method is called ;-( 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.set("discogs", "consumer_key", consumer_key) config.set("discogs", "consumer_secret", consumer_secret) discogs_connection = DiscogsConnector(config) testFileHandler = FileHandler(self.album, config) testFileHandler.get_images(discogs_connection) onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f)) ] logger.debug("files: %s " % onlyfiles) logger.debug('checking %s' % self.album.target_dir) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-01.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-02.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-03.jpg")) assert os.path.exists( os.path.join(self.album.target_dir, "XXIMGXX-04.jpg")) test_get_images.needs_network = True test_get_images.needs_authentication = True test_get_images_wo_folderjpg.needs_network = True test_get_images_wo_folderjpg.needs_authentication = True
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')") 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 test_map_multidisc_with_disctitle(): ogsrelid = "288308" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(ogsrelid) dummy_discogs_album = DummyDiscogsAlbum(dummy_response) album = dummy_discogs_album.map() assert len(album.labels) == 1 assert album.labels[0] == "Epic" assert len(album.catnumbers) == len(album.labels) assert album.catnumbers[0] == "E2K 69635" assert len(album.images) == 4 assert album.images[ 0] == "http://api.discogs.com/image/R-288308-1333554422.jpeg" assert album.title == "Ladies & Gentlemen - The Best Of George Michael" assert len(album.artists) == 1 logger.debug("album.artists %s" % album.artists[0]) assert album.artists[0] == "George Michael" assert len(album.genres) == 2 assert album.genres[0] == "Electronic" assert album.genres[1] == "Pop" assert len(album.styles) == 2 assert album.styles[0] == "Downtempo" assert album.styles[1] == "Synth-pop" # in discogs it is a compilation assert album.is_compilation assert album.disctotal == 2 assert len(album.discs) == album.disctotal assert len(album.discs[0].tracks) == 14 assert len(album.discs[1].tracks) == 14 # first track on first disc track = album.discs[0].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 1 assert track.discsubtitle == "For The Heart" assert track.title == "Jesus To A Child" assert track.artists[0] == "George Michael" assert track.non_existent_tag == None # last track on first disc track = album.discs[0].tracks[13] assert track.tracknumber == 14 assert track.discnumber == 1 assert track.discsubtitle == "For The Heart" assert track.title == "A Different Corner" assert track.artists[0] == "George Michael" assert track.non_existent_tag == None # first track on second disc track = album.discs[1].tracks[0] assert track.tracknumber == 1 assert track.discnumber == 2 assert track.title == "Outside" assert track.discsubtitle == "For The Feet" assert track.artists[0] == "George Michael" assert track.non_existent_tag == None logger.debug("1discsubtitle: %s " % track.discsubtitle) # last track on first disc track = album.discs[1].tracks[13] logger.debug("2discsubtitle: %s " % track.discsubtitle) assert track.tracknumber == 14 assert track.discnumber == 2 assert track.title == "Somebody To Love" assert track.discsubtitle == "For The Feet" assert track.artists[0] == "George Michael With Queen" assert track.non_existent_tag == None
def test_tag_album_with_specific_track_artists(self): self.ogsrelid = "112146" # construct config with only default values tagger_config = TaggerConfig(os.path.join(parentdir, "test/empty.conf")) dummy_response = TestDummyResponse(self.ogsrelid) discogs_album = DummyDiscogsAlbum(dummy_response) self.album = discogs_album.map() self.copy_files(self.album) taggerutils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album) taggerutils._get_target_list() testTagHandler = TagHandler(self.album, self.tagger_config) testFileHandler = FileHandler(self.album, self.tagger_config) testFileHandler.copy_files() testTagHandler.tag_album() target_dir = os.path.join(self.target_dir, self.album.target_dir, self.album.disc(1).target_dir) metadata = MediaFile( os.path.join( target_dir, "01-artful_dodger-re-rewind_the_crowd_say_bo_selecta_(radio_edit).flac" )) assert metadata.artist == "Artful Dodger" assert metadata.albumartist == "Artful Dodger" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2000 assert metadata.disctotal == 2 assert metadata.genre == "Electronic" # obviously the encoder element is not in the file, but it is returned # empty anyway, no need to check this then... assert metadata.encoder == None metadata = MediaFile( os.path.join( target_dir, "04-artful_dodger_feat_romina_johnson-movin_too_fast_(artful_dodger_original_mix).flac" )) assert metadata.artist == "Artful Dodger Feat. Romina Johnson" assert metadata.albumartist == "Artful Dodger" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2000 assert metadata.disctotal == 2 assert metadata.track == 4 assert metadata.genre == "Electronic" # obviously the encoder element is not in the file, but it is returned # empty anyway, no need to check this then... assert metadata.encoder == None target_dir = os.path.join(self.target_dir, self.album.target_dir, self.album.disc(2).target_dir) metadata = MediaFile( os.path.join(target_dir, "20-paul_johnson-get_get_down_(illicit_remix).flac")) assert metadata.artist == "Paul Johnson" assert metadata.albumartist == "Artful Dodger" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2000 assert metadata.disctotal == 2 assert metadata.disc == 2 assert metadata.track == 20 assert metadata.genre == "Electronic" # obviously the encoder element is not in the file, but it is returned # empty anyway, no need to check this then... assert metadata.encoder == None