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_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_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_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_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_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_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_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_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 test_tag_album(self): 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-gigi_dagostino-la_passion_(radio_cut).flac")) assert metadata.artist == "Gigi D'Agostino" assert metadata.albumartist == "Various" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2001 assert metadata.disctotal == 2 assert metadata.comp assert metadata.genres == ["Electronic", "Hip Hop", "Pop", "Rock"] assert metadata.freedb_id == "4711" # 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, "20-papa_roach-last_resort_(album_version_explizit).flac")) logger.debug("artist: %s" % metadata.artist_sort) assert metadata.artist == "Papa Roach" assert metadata.artist_sort == "Papa Roach" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2001 assert metadata.disctotal == 2 assert metadata.disc == 1 assert metadata.track == 20 assert metadata.comp assert metadata.genres == ["Electronic", "Hip Hop", "Pop", "Rock"] # 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
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_target_list_multi_disc(self): # copy file to source directory and rename it self.copy_files(self.album) target_file_name = "id.txt" 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) taggerutils._get_target_list() assert self.album.copy_files[0] == "a1.txt" assert self.album.copy_files[1] == "a2.txt" assert self.album.copy_files[2] == "id.txt" assert self.album.sourcedir == self.source_dir assert self.album.discs[0].sourcedir == "disc1" assert self.album.discs[1].sourcedir == "disc2" assert self.album.target_dir == os.path.join( self.target_dir, "various-megahits_2001_die_erste-(560_938-2)-2001") assert self.album.discs[ 0].target_dir == "megahits_2001_die_erste-disc1" assert self.album.discs[ 1].target_dir == "megahits_2001_die_erste-disc2" assert self.album.discs[0].copy_files[0] == "album.cue" assert self.album.discs[0].copy_files[1] == "album.m3u" assert self.album.discs[1].copy_files[0] == "album.cue" assert self.album.discs[1].copy_files[1] == "album.m3u" assert self.album.discs[0].tracks[0].orig_file == "01-song.flac" assert self.album.discs[0].tracks[ 0].new_file == "01-gigi_dagostino-la_passion_(radio_cut).flac" assert self.album.discs[0].tracks[19].orig_file == "20-song.flac" assert self.album.discs[0].tracks[ 19].new_file == "20-papa_roach-last_resort_(album_version_explizit).flac" assert self.album.discs[1].tracks[0].orig_file == "01-song.flac" assert self.album.discs[1].tracks[ 0].new_file == "01-die_3_generation-ich_will_dass_du_mich_liebst_(radio_edit).flac" assert self.album.discs[1].tracks[19].orig_file == "20-song.flac" assert self.album.discs[1].tracks[ 19].new_file == "20-jay-z-i_just_wanna_love_u_(give_it_2_me)_(radio_edit).flac"
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 test_tag_album(self): 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-gigi_dagostino-la_passion_(radio_cut).flac")) assert metadata.artist == "Gigi D'Agostino" assert metadata.albumartist == "Various" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2001 assert metadata.disctotal == 2 assert metadata.comp assert metadata.genres == ["Electronic", "Hip Hop", "Pop", "Rock"] assert metadata.freedb_id == "4711" # 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, "20-papa_roach-last_resort_(album_version_explizit).flac")) logger.debug("artist: %s" % metadata.artist_sort) assert metadata.artist == "Papa Roach" assert metadata.artist_sort == "Papa Roach" assert metadata.discogs_id == self.ogsrelid assert metadata.year == 2001 assert metadata.disctotal == 2 assert metadata.disc == 1 assert metadata.track == 20 assert metadata.comp assert metadata.genres == ["Electronic", "Hip Hop", "Pop", "Rock"] # 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
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_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_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_target_list_multi_disc(self): # copy file to source directory and rename it self.copy_files(self.album) target_file_name = "id.txt" 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) taggerutils._get_target_list() assert self.album.copy_files[0] == "a1.txt" assert self.album.copy_files[1] == "a2.txt" assert self.album.copy_files[2] == "id.txt" assert self.album.sourcedir == self.source_dir assert self.album.discs[0].sourcedir == "disc1" assert self.album.discs[1].sourcedir == "disc2" assert self.album.target_dir == os.path.join(self.target_dir, "various-megahits_2001_die_erste-(560_938-2)-2001") assert self.album.discs[0].target_dir == "megahits_2001_die_erste-disc1" assert self.album.discs[1].target_dir == "megahits_2001_die_erste-disc2" assert self.album.discs[0].copy_files[0] == "album.cue" assert self.album.discs[0].copy_files[1] == "album.m3u" assert self.album.discs[1].copy_files[0] == "album.cue" assert self.album.discs[1].copy_files[1] == "album.m3u" assert self.album.discs[0].tracks[0].orig_file == "01-song.flac" assert self.album.discs[0].tracks[0].new_file == "01-gigi_dagostino-la_passion_(radio_cut).flac" assert self.album.discs[0].tracks[19].orig_file == "20-song.flac" assert self.album.discs[0].tracks[19].new_file == "20-papa_roach-last_resort_(album_version_explizit).flac" assert self.album.discs[1].tracks[0].orig_file == "01-song.flac" assert self.album.discs[1].tracks[0].new_file == "01-die_3_generation-ich_will_dass_du_mich_liebst_(radio_edit).flac" assert self.album.discs[1].tracks[19].orig_file == "20-song.flac" assert self.album.discs[1].tracks[19].new_file == "20-jay-z-i_just_wanna_love_u_(give_it_2_me)_(radio_edit).flac"
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_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_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
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
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 '%s - %s'" % (album.artist, album.title)) taggerUtils = TaggerUtils(source_dir, destdir, tagger_config, album) tagHandler = TagHandler(album, tagger_config) 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 fileHandler.copy_files() logger.debug("Tagging files") tagHandler.tag_album() logger.debug("Copy other interesting files (on request)") fileHandler.copy_other_files()
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 '%s - %s'" % (album.artist, album.title)) taggerUtils = TaggerUtils(source_dir, destdir, tagger_config, album) tagHandler = TagHandler(album, tagger_config) 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 fileHandler.copy_files() 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")
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)