def _audio_tden(atuple): audio, atag, advanced, _, _ = atuple if advanced: param = ast.literal_eval(atag) audio.add(TDEN(3, param[1])) else: audio.add(TDEN(3, atag))
def test_save_off_spec_frames(self): # These are not defined in v2.3 and shouldn't be written. # Still make sure reading them again works and the encoding # is at least changed audio = ID3(self.filename) dates = ["2013", "2014"] frame = TDEN(text=dates, encoding=3) audio.add(frame) tipl_frame = TIPL(people=[("a", "b"), ("c", "d")], encoding=2) audio.add(tipl_frame) audio.save(v2_version=3) id3 = ID3(self.filename, translate=False) self.assertEqual(id3.version, (2, 3, 0)) self.assertEqual([stamp.text for stamp in id3["TDEN"].text], dates) self.assertEqual(id3["TDEN"].encoding, 1) self.assertEqual(id3["TIPL"].people, tipl_frame.people) self.assertEqual(id3["TIPL"].encoding, 1)
def insert_id3_tags(disc_number, track_number, artist, title, album): disc_number_string = format_disc_number_string(disc_number) track_number_string = format_track_number_string(track_number) disco_filename = disc_number_string + '_' + track_number_string encoded_file_path = os.path.join(ENCODED_PATH_NUMBERED, disco_filename + '.' + ENCODER_FORMAT) if os.path.isfile(encoded_file_path): if DEBUG: print("Updating ID3 tags for " + encoded_file_path) try: audio = ID3(encoded_file_path) except ID3NoHeaderError: print("Adding ID3 header") audio = ID3() audio['TPE1'] = TPE1(encoding=3, text=artist) audio['TIT2'] = TIT2(encoding=3, text=title) audio['TRCK'] = TRCK(encoding=3, text=track_number_string) audio['TALB'] = TALB(encoding=3, text=album) audio['TDTG'] = TDTG(encoding=3, text=strftime('%Y-%m-%d %H:%M:%S %z', localtime())) if not 'TDEN' in audio: # Only include the encoding time the first time we tag the file audio['TDEN'] = TDEN(encoding=3, text=strftime('%Y-%m-%d %H:%M:%S %z', localtime())) album_art_path = os.path.join(ART_DIR, disc_number_string + '.' + IMAGE_FORMAT) if os.path.isfile(album_art_path): with open(album_art_path, 'rb') as albumart: audio['APIC'] = APIC(encoding=3, mime='image/' + IMAGE_FORMAT, type=3, desc=u'Cover', data=albumart.read()) return audio.save(encoded_file_path) return False