def test_plain_disc(self): """Addis Black Widow - Wait in Summer (single): Nothing fancy, just two tracks with regular separation. """ d = model.DbDisc.from_discid_disc(discid.put( 1, 2, 17357 + 14263, [150, 17357])) tocd = self.read_toc('abw-waitinsummer.toc') tocd.disc_id = d.disc_id toc.merge_full_toc(d, tocd) self.assertEqual(d.catalog, "5099767123812") self.assertEqual(len(d.tracks), 2) t = d.tracks[0] self.assertEqual(t.number, 1) self.assertEqual(t.file_offset, 0) self.assertEqual(t.length, msf_to_frames('03:47:50')) self.assertEqual(t.length, t.file_length) self.assertEqual(t.isrc, "GBDKA0100022") t = d.tracks[1] self.assertEqual(t.number, 2) self.assertEqual(t.file_offset, msf_to_frames('03:47:50')) self.assertEqual(t.pregap_offset, msf_to_frames('00:01:57')) self.assertEqual(t.length, msf_to_frames('03:11:70')) self.assertEqual(t.length, t.file_length) self.assertEqual(t.isrc, "GBDKA0100054")
def test_tracks(self): raw = discid.put(1, 3, 72250 + 9037, [150, 34780, 72250]) d = model.DbDisc.from_discid_disc(raw, 'test.cdr') self.assertEqual(d.disc_id, raw.id) self.assertEqual(d.catalog, None) self.assertEqual(d.data_file_name, "test.cdr") self.assertEqual(d.data_file_format, model.RAW_CD) self.assertEqual(d.audio_format, model.PCM) self.assertEqual(len(d.tracks), 3) # The pregap will not be read by cdrdao t = d.tracks[0] self.assertEqual(t.number, 1) self.assertEqual(t.file_offset, 0) self.assertEqual(t.length, 34630 * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, t.file_length) t = d.tracks[1] self.assertEqual(t.number, 2) self.assertEqual(t.file_offset, (34780 - 150) * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, 37470 * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, t.file_length) t = d.tracks[2] self.assertEqual(t.number, 3) self.assertEqual(t.file_offset, (72250 - 150) * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, 9037 * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, t.file_length)
def test_read_put(self): # a read followed with a put, which should clear the features disc = discid.read(features=["mcn", "isrc"]) # read from default drive test_disc = test_discs[0] disc = discid.put(test_disc["first"], test_disc["last"], test_disc["sectors"], test_disc["offsets"]) self.assertTrue(disc.mcn is None) for track in disc.tracks: self.assertTrue(track.isrc is None)
def read_eac_log(self): try: fh = codecs.open(self.wizard.eac_log_file, encoding='utf-16-le').readlines() toc = eac_log_to_musicbrainz_discid.calculate_mb_toc_numbers(eac_log_to_musicbrainz_discid.filter_toc_entries(iter(fh))) disc = discid.put(toc[0], toc[1], toc[2], toc[3:]) except: self.status_label.setText('Unable to parse EAC log file') return None return disc
def test_read_simple(self): disc = discid.read() # read from default drive self.assertEqual(len(disc.id), 28, "Invalid Disc ID") self.assertEqual(len(disc.freedb_id), 8, "Invalid FreeDB Disc ID") self.assertTrue(disc.submission_url, "Invalid submission url") self.assertTrue(disc.toc_string, "Invalid toc string") self.assertEqual(disc.last_track_num, len(disc.tracks), "Wrong amount of tracks") self.assertEqual(disc.sectors, disc.tracks[-1].offset + disc.tracks[-1].sectors) for track in disc.tracks: self.assertTrue(track.offset <= disc.sectors, "Invalid offset") if track.number > 1: previous_offset = disc.tracks[track.number - 2].offset self.assertTrue(track.offset >= previous_offset, "Invalid offset series") # additional features should be unset, not empty self.assertTrue(disc.mcn is None) for track in disc.tracks: self.assertTrue(track.isrc is None) # check idempotence (use output again as input to put) disc_id = disc.id freedb_id = disc.freedb_id submission_url = disc.submission_url toc_string = disc.toc_string first = disc.first_track_num last = disc.last_track_num sectors = disc.sectors track_sectors = [track.sectors for track in disc.tracks] track_offsets = [track.offset for track in disc.tracks] disc = discid.put(first, last, sectors, track_offsets) self.assertEqual(disc.id, disc_id, "different id after put") self.assertEqual(disc.freedb_id, freedb_id, "different freedb id after put") self.assertEqual(disc.submission_url, submission_url, "different submission_url after put") self.assertEqual(disc.toc_string, toc_string, "different toc_string after put") self.assertEqual(disc.first_track_num, first, "different first track after put") self.assertEqual(disc.last_track_num, last, "different last track after put") self.assertEqual(disc.sectors, sectors, "different sector count after put") new_offsets = [track.offset for track in disc.tracks] self.assertEqual(new_offsets, track_offsets, "different offsets after put") new_sectors = [track.sectors for track in disc.tracks] self.assertEqual(new_sectors, track_sectors, "different lengths after put")
def test_read_simple(self): disc = discid.read() # read from default drive self.assertEqual(len(disc.id), 28, "Invalid Disc ID") self.assertEqual(len(disc.freedb_id), 8, "Invalid FreeDB Disc ID") self.assertTrue(disc.submission_url, "Invalid submission url") self.assertTrue(disc.toc_string, "Invalid toc string") self.assertEqual(disc.last_track_num, len(disc.tracks), "Wrong amount of tracks") self.assertEqual(disc.sectors, disc.tracks[-1].offset + disc.tracks[-1].sectors) for track in disc.tracks: self.assertTrue(track.offset <= disc.sectors, "Invalid offset") if track.number > 1: previous_offset = disc.tracks[track.number-2].offset self.assertTrue(track.offset >= previous_offset, "Invalid offset series") # additional features should be unset, not empty self.assertTrue(disc.mcn is None) for track in disc.tracks: self.assertTrue(track.isrc is None) # check idempotence (use output again as input to put) disc_id = disc.id freedb_id = disc.freedb_id submission_url = disc.submission_url toc_string = disc.toc_string first = disc.first_track_num last = disc.last_track_num sectors = disc.sectors track_sectors = [track.sectors for track in disc.tracks] track_offsets = [track.offset for track in disc.tracks] disc = discid.put(first, last, sectors, track_offsets) self.assertEqual(disc.id, disc_id, "different id after put") self.assertEqual(disc.freedb_id, freedb_id, "different freedb id after put") self.assertEqual(disc.submission_url, submission_url, "different submission_url after put") self.assertEqual(disc.toc_string, toc_string, "different toc_string after put") self.assertEqual(disc.first_track_num, first, "different first track after put") self.assertEqual(disc.last_track_num, last, "different last track after put") self.assertEqual(disc.sectors, sectors, "different sector count after put") new_offsets = [track.offset for track in disc.tracks] self.assertEqual(new_offsets, track_offsets, "different offsets after put") new_sectors = [track.sectors for track in disc.tracks] self.assertEqual(new_sectors, track_sectors, "different lengths after put")
def com_discid_caclulate_dir(dir_to_calculate): """ Calculate the discid from specified directory """ last = len(os.listdir(dir_to_calculate)) # number of files in directory could be used # https://python-discid.readthedocs.io/en/latest/usage/ # os.stat could get the numbers I think sectors = 258725 offsets = [150, 17510, 235590] disc = discid.put(1, last, sectors, offsets) common_global.es_inst.com_elastic_index('info', {"id": disc.id}) last_track = disc.tracks[disc.last_track_num - 1] common_global.es_inst.com_elastic_index('info', {"last track length seconds": last_track.seconds}) return disc
def test_hidden_track_at_start(self): """Kylie Minogue - Light Years: Has a hidden first track which is marked as silence in the full TOC. It should be turned into track 0. """ d = model.DbDisc.from_discid_disc(discid.put( 1, 14, 240680 + 21557, [17285, 32875, 48862, 65165, 82972, 101780, 119790, 135820, 154455, 171182, 189892, 205185, 221177, 240680])) tocd = self.read_toc('kylie-lightyears.toc') tocd.disc_id = d.disc_id toc.merge_full_toc(d, tocd) self.assertEqual(d.catalog, "0724352840021") self.assertEqual(len(d.tracks), 15) # Hidden track t = d.tracks[0] self.assertEqual(t.number, 0) self.assertEqual(t.file_offset, 0) self.assertEqual(t.pregap_offset, 0) self.assertEqual(t.length, msf_to_frames('03:48:35')) self.assertEqual(t.length, t.file_length) self.assertEqual(t.isrc, None) # First regular track t = d.tracks[1] self.assertEqual(t.number, 1) self.assertEqual(t.file_offset, msf_to_frames('03:48:35')) self.assertEqual(t.length, msf_to_frames('03:27:10')) self.assertEqual(t.length, t.file_length) self.assertEqual(t.pregap_silence, 0) self.assertEqual(t.pregap_offset, 0) self.assertEqual(t.isrc, "GBAYE0000351") # Subsequent tracks should have offsets somewhat changed t = d.tracks[2] self.assertEqual(t.number, 2) self.assertEqual(t.file_offset, msf_to_frames('07:15:45')) self.assertEqual(t.length, msf_to_frames('03:32:42')) self.assertEqual(t.length, t.file_length) self.assertEqual(t.pregap_silence, 0) self.assertEqual(t.pregap_offset, msf_to_frames('00:00:55')) self.assertEqual(t.isrc, "GBAYE0000642")
def test_use_cdtext(self): d = model.DbDisc.from_discid_disc(discid.put( 1, 10, 143134 + 25354, [150, 14585, 29141, 44041, 58307, 80687, 96388, 112208, 128048, 143134])) tocd = self.read_toc('cocteautwins-heavenorlasvegas.toc') tocd.disc_id = d.disc_id toc.merge_full_toc(d, tocd) self.assertEqual(d.title, 'HEAVEN OR LAS VEGAS') self.assertEqual(d.artist, 'THE COCTEAU TWINS') t = d.tracks[9] self.assertEqual(t.title, 'FROU-FROU FOXES IN MIDSUMMER FIRES') self.assertEqual(t.artist, None)
def test_put_success(self): test_disc = test_discs[0] disc = discid.put(test_disc["first"], test_disc["last"], test_disc["sectors"], test_disc["offsets"]) self.assertEqual(disc.id, test_disc["id"]) self.assertEqual(disc.freedb_id, test_disc["freedb"]) self.assertEqual(disc.first_track_num, test_disc["first"]) self.assertEqual(disc.last_track_num, test_disc["last"]) self.assertEqual(disc.sectors, test_disc["sectors"]) track_offsets = [track.offset for track in disc.tracks] self.assertEqual(track_offsets, test_disc["offsets"]) self.assertEqual(disc.sectors, disc.tracks[-1].offset + disc.tracks[-1].sectors) self.assertEqual(disc.seconds, disc.sectors // discid.util.SECTORS_PER_SECOND) for track in disc.tracks: self.assertEqual(track.seconds, track.sectors // discid.util.SECTORS_PER_SECOND)
def getMusicBrainzDiscId(self): """ Calculate the MusicBrainz disc ID. :returns: the 28-character base64-encoded disc ID :rtype: str """ if self.mbdiscid: logger.debug('getMusicBrainzDiscId: returning cached %r', self.mbdiscid) return self.mbdiscid from discid import put values = self._getMusicBrainzValues() disc = put(values[0], values[1], values[2], values[3:]) logger.debug('getMusicBrainzDiscId: returning %r', disc.id) self.mbdiscid = disc.id return disc.id
def test_put_success(self): test_disc = test_discs[0] disc = discid.put(test_disc["first"], test_disc["last"], test_disc["sectors"], test_disc["offsets"]) self.assertEqual(disc.id, test_disc["id"]) self.assertEqual(disc.freedb_id, test_disc["freedb"]) self.assertEqual(disc.first_track_num, test_disc["first"]) self.assertEqual(disc.last_track_num, test_disc["last"]) self.assertEqual(disc.sectors, test_disc["sectors"]) track_offsets = [track.offset for track in disc.tracks] self.assertEqual(track_offsets, test_disc["offsets"]) self.assertEqual(disc.sectors, disc.tracks[-1].offset + disc.tracks[-1].sectors) self.assertEqual(disc.seconds, math.floor((disc.sectors / 75.0) + 0.5)) self.assertEqual(type(disc.seconds), int) for track in disc.tracks: self.assertEqual(track.seconds, math.floor((track.sectors / 75.0) + 0.5)) self.assertEqual(type(track.seconds), int) toc_string = ["1", disc.last_track_num, disc.sectors] + track_offsets toc_string = " ".join(map(str, toc_string)) self.assertEqual(disc.toc_string, toc_string)
def test_do_not_overwrite_track_info_with_cdtext(self): d = model.DbDisc.from_discid_disc(discid.put( 1, 10, 143134 + 25354, [150, 14585, 29141, 44041, 58307, 80687, 96388, 112208, 128048, 143134])) # Set some TOC info d.title = 'foo' d.artist = 'bar' d.tracks[0].title = 'gazonk' d.tracks[0].artist = 'bar' tocd = self.read_toc('cocteautwins-heavenorlasvegas.toc') tocd.disc_id = d.disc_id toc.merge_full_toc(d, tocd) self.assertEqual(d.title, 'foo') self.assertEqual(d.artist, 'bar') t = d.tracks[0] self.assertEqual(t.title, 'gazonk') self.assertEqual(t.artist, 'bar')
def test_overwrite_offsets(self): # This is one of the rare discs that actually have indices on # one track. So we use that to make sure they are dropped # when merging, natch. d = model.DbDisc.from_string(resource_string( 'codplayer.test', 'data/sonicyouth-daydreamnation.cod')) basic_disc = model.DbDisc.from_discid_disc(discid.put( 1, 12, 255430 + 63503, [183, 31560, 48640, 83328, 114868, 132020, 166038, 185768, 197898, 220320, 241283, 255430])) toc.merge_basic_toc(d, basic_disc) t = d.tracks[0] self.assertEqual(t.number, 1) self.assertEqual(t.file_offset, (183 - 2 * model.PCM.cd_frames_per_second) * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, 31377 * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, t.file_length) self.assertEqual(t.pregap_offset, 0) self.assertEqual(t.pregap_silence, 0) self.assertListEqual(t.index, []) self.assertEqual(t.title, 'Teen Age Riot') t = d.tracks[11] self.assertEqual(t.number, 12) self.assertEqual(t.file_offset, (255430 - 2 * model.PCM.cd_frames_per_second) * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, 63503 * model.PCM.audio_frames_per_cd_frame) self.assertEqual(t.length, t.file_length) self.assertEqual(t.pregap_offset, 0) self.assertEqual(t.pregap_silence, 0) self.assertListEqual(t.index, []) self.assertEqual(t.title, 'Trilogy: The Wonder / Hyperstation / Eliminator Jr.')
def id_cddb(self) -> str: disc = discid.put(self.first_track, self.last_track, self.num_frames(), self.tracks_lba()) return disc.freedb_id
def id_musicbrainz(self) -> str: disc = discid.put(self.first_track, self.last_track, self.num_frames(), self.tracks_lba()) return disc.id