def gen_tag(self, track, fake_art=False): tag = Tag() if track.has_key('album'): tag.album = track['album'] if track.has_key('artist'): tag.artist = track['artist'] if track.has_key('title'): tag.title = track['title'] if track.has_key('discNumber'): tag.disc_num = int(track['discNumber']) if track.has_key('trackNumber'): tag.track_num = int(track['trackNumber']) if track.has_key('genre'): tag.genre = track['genre'] if track.has_key('albumArtist') and track['albumArtist'] != track['artist']: tag.album_artist = track['albumArtist'] if track.has_key('year') and int(track['year']) != 0: tag.recording_date = track['year'] if track.has_key('albumArtRef'): art = None if self.__art is None: if fake_art: art = '\0' * self.__art_size else: if self.load_art(): art = self.__art else: art = None else: art = self.__art if art is not None: tag.images.set(0x03, art, 'image/jpeg', u'Front cover') return tag
def gen_tag(self, track, fake_art=False): tag = Tag() if track.has_key('album'): tag.album = track['album'] if track.has_key('artist'): tag.artist = track['artist'] if track.has_key('title'): tag.title = track['title'] if track.has_key('discNumber'): tag.disc_num = int(track['discNumber']) if track.has_key('trackNumber'): tag.track_num = int(track['trackNumber']) if track.has_key('genre'): tag.genre = track['genre'] if track.has_key( 'albumArtist') and track['albumArtist'] != track['artist']: tag.album_artist = track['albumArtist'] if track.has_key('year') and int(track['year']) != 0: tag.recording_date = track['year'] if track.has_key('albumArtRef'): art = None if self.__art is None: if fake_art: art = '\0' * self.__art_size else: if self.load_art(): art = self.__art else: art = None else: art = self.__art if art is not None: tag.images.set(0x03, art, 'image/jpeg', u'Front cover') return tag
def testNumStringConvert(): t = Tag() t.track_num = "1" assert t.track_num == (1, None) t.disc_num = ("2", "6") assert t.disc_num == (2, 6)
def set_mp3_album_tags(data: Dict[str, str], tag: id3.Tag, episode_num: int): # set album title and cover image tag.album = data["album"] image_type = id3.frames.ImageFrame.FRONT_COVER image_file = os.path.join("/srv", data["cover"].lstrip("/")) image_mime = mimetype.guessMimetype(image_file) # set cover image with open(image_file, "rb") as f: tag.images.set(image_type, f.read(), image_mime, "") # set various meta info tag.artist = data["artist"] tag.track_num = (episode_num, episode_num) tag.title = Template(data["title"]).substitute(episode_num=episode_num) tag.release_date = str(date.today()) tag.genre = "Podcast"
def testTagMainProps(): tag = Tag() # No version yet assert tag.version == ID3_DEFAULT_VERSION assert not (tag.isV1()) assert tag.isV2() assert tag.artist is None tag.artist = u"Autolux" assert tag.artist == u"Autolux" assert len(tag.frame_set) == 1 tag.artist = u"" assert len(tag.frame_set) == 0 tag.artist = u"Autolux" assert tag.album is None tag.album = u"Future Perfect" assert tag.album == u"Future Perfect" assert tag.album_artist is None tag.album_artist = u"Various Artists" assert (tag.album_artist == u"Various Artists") assert (tag.title is None) tag.title = u"Robots in the Garden" assert (tag.title == u"Robots in the Garden") assert (tag.track_num == (None, None)) tag.track_num = 7 assert (tag.track_num == (7, None)) tag.track_num = (7, None) assert (tag.track_num == (7, None)) tag.track_num = (7, 15) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "07/15") assert (tag.track_num == (7, 15)) tag.track_num = (7, 150) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "007/150") assert (tag.track_num == (7, 150)) tag.track_num = (1, 7) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "01/07") assert (tag.track_num == (1, 7)) tag.track_num = None assert (tag.track_num == (None, None)) tag.track_num = None, None
def testTagMainProps(): tag = Tag() # No version yet assert_equal(tag.version, ID3_DEFAULT_VERSION) assert_false(tag.isV1()) assert_true(tag.isV2()) assert_equal(tag.artist, None) tag.artist = u"Autolux" assert_equal(tag.artist, u"Autolux") assert_equal(len(tag.frame_set), 1) tag.artist = u"" assert_equal(len(tag.frame_set), 0) tag.artist = u"Autolux" assert_equal(tag.album, None) tag.album = u"Future Perfect" assert_equal(tag.album, u"Future Perfect") assert_equal(tag.album_artist, None) tag.album_artist = u"Various Artists" assert_equal(tag.album_artist, u"Various Artists") assert_equal(tag.title, None) tag.title = u"Robots in the Garden" assert_equal(tag.title, u"Robots in the Garden") assert_equal(tag.track_num, (None, None)) tag.track_num = 7 assert_equal(tag.track_num, (7, None)) tag.track_num = (7, None) assert_equal(tag.track_num, (7, None)) tag.track_num = (7, 15) assert_equal(tag.frame_set[frames.TRACKNUM_FID][0].text, "07/15") assert_equal(tag.track_num, (7, 15)) tag.track_num = (7, 150) assert_equal(tag.frame_set[frames.TRACKNUM_FID][0].text, "007/150") assert_equal(tag.track_num, (7, 150)) tag.track_num = (1, 7) assert_equal(tag.frame_set[frames.TRACKNUM_FID][0].text, "01/07") assert_equal(tag.track_num, (1, 7)) tag.track_num = None assert_equal(tag.track_num, (None, None)) tag.track_num = None, None
def testTagMainProps(): tag = Tag() # No version yet assert tag.version == ID3_DEFAULT_VERSION assert not(tag.isV1()) assert tag.isV2() assert tag.artist is None tag.artist = "Autolux" assert tag.artist == "Autolux" assert len(tag.frame_set) == 1 tag.artist = "" assert len(tag.frame_set) == 0 tag.artist = "Autolux" assert tag.album is None tag.album = "Future Perfect" assert tag.album == "Future Perfect" assert tag.album_artist is None tag.album_artist = "Various Artists" assert (tag.album_artist == "Various Artists") assert (tag.title is None) tag.title = "Robots in the Garden" assert (tag.title == "Robots in the Garden") assert (tag.track_num == (None, None)) tag.track_num = 7 assert (tag.track_num == (7, None)) tag.track_num = (7, None) assert (tag.track_num == (7, None)) tag.track_num = (7, 15) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "07/15") assert (tag.track_num == (7, 15)) tag.track_num = (7, 150) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "007/150") assert (tag.track_num == (7, 150)) tag.track_num = (1, 7) assert (tag.frame_set[frames.TRACKNUM_FID][0].text == "01/07") assert (tag.track_num == (1, 7)) tag.track_num = None assert (tag.track_num == (None, None)) tag.track_num = None, None
def gen_tag(self, track, fake_art=False): tag = Tag() if track.has_key('album'): tag.album = track['album'] if track.has_key('artist'): tag.artist = " / ".join(track['artist']) if len(track['artist']) == 2: print track['artist'] if track.has_key('title'): tag.title = track['title'] if track.has_key('discNumber') and self.show_discnum: tag.disc_num = int(track['discNumber']) if track.has_key('trackNumber'): tag.track_num = int(track['trackNumber']) if track.has_key('genre'): tag.genre = track['genre'] if track.has_key('albumArtist') and (len(track['artist']) != 1 or track['albumArtist'] != track['artist'][0]): tag.setTextFrame('TPE2', track['albumArtist']) if track.has_key('year') and int(track['year']) != 0: tag.recording_date = track['year'] if track.has_key('albumArtRef'): art = None if self.__art is None: if fake_art: art = '\0' * self.__art_size else: if self.load_art(): art = self.__art else: art = None else: art = self.__art if art is not None: tag.images.set(0x03, art, 'image/jpeg', u'Front cover') return tag
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> ################################################################################ from eyed3.id3 import Tag from eyed3.id3 import ID3_V1_0, ID3_V1_1, ID3_V2_3, ID3_V2_4 import logging from eyed3 import log log.setLevel(logging.DEBUG) t = Tag() t.artist = u"M.O.P." t.title = u"How About Some Hardcore" t.album = u"To The Death" t.genre = u"Hip-Hop" t.track_num = (3, 5) t.disc_num = (1, 1) t.original_release_date = "1994-04-07" t.release_date = "1994-04-07" t.encoding_date = "2002-03" t.recording_date = 1996 t.tagging_date = "2012-2-5" t.comments.set(u"Gritty, yo!") t.comments.set(u"Brownsville, Brooklyn", u"Origin") t.user_text_frames.set(u"****", u"Rating") t.artist_url = b"http://allmusic.com/artist/mop-p194909" t.user_url_frames.set(b"http://eyed3.nicfit.net/")
def download_song(self, id) -> bytes: from gmusiccache.service.context import StatusInteraction from urllib.request import urlretrieve, urlopen from tempfile import mkstemp import os import eyed3 from eyed3.id3 import Tag from eyed3.id3.frames import ImageFrame from datetime import datetime self.__context.interact(StatusInteraction("Retrieving song info...")) song_info = Service.__make_song_info( self.__gmusic_client.get_track_info(id)) album_art = None if song_info.album_art: self.__context.interact( StatusInteraction("Reading album cover...")) try: with urlopen(song_info.album_art) as stream: album_art = stream.read() except: self.__context.interact( StatusInteraction("Album art download failed!")) self.__context.interact(StatusInteraction("Making id3 tags...")) id3_tags = Tag() id3_tags.title = song_info.name id3_tags.artist = song_info.artist id3_tags.album = song_info.album id3_tags.release_date = song_info.year id3_tags.recording_date = song_info.year id3_tags.original_release_date = song_info.year id3_tags.tagging_date = datetime.now().year id3_tags.encoding_date = datetime.now().year id3_tags.track_num = song_info.track_number, song_info.tracks_in_album if album_art: id3_tags.images.set(ImageFrame.FRONT_COVER, album_art, 'image/jpeg') self.__context.interact(StatusInteraction("Downloading stream...")) stream_url = self.__gmusic_client.get_stream_url(song_info.id) fd, path = None, None try: try: fd, path = mkstemp(prefix='gmusiccache_') urlretrieve(stream_url, path) finally: if fd: os.close(fd) self.__context.interact( StatusInteraction( "Fixing metadata on file {0}...".format(path))) mp3_file = eyed3.load(path) mp3_file.initTag() # update to the newest version mp3_file.tag = id3_tags mp3_file.tag.save() self.__context.interact( StatusInteraction("Done. Returning file with metadata.")) with open(path, 'rb') as file: return file.read() finally: self.__context.interact( StatusInteraction("Removing temp file {0}...".format(path))) if path: os.remove(path)
def testSetNumExceptions(): t = Tag() with pytest.raises(ValueError) as ex: t.track_num = (1, 2, 3)
def testSetNumExceptions(): t = Tag() with pytest.raises(ValueError) as ex: t.track_num = (1, 2, 3) with pytest.raises(TypeError) as ex: t.track_num = "1"
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> ################################################################################ from eyed3.id3 import Tag from eyed3.id3 import ID3_V1_0, ID3_V1_1, ID3_V2_3, ID3_V2_4 import logging from eyed3 import log log.setLevel(logging.DEBUG) t = Tag() t.artist = u"M.O.P." t.title = u"How About Some Hardcore" t.album = u"To The Death" t.genre = u"Hip-Hop" t.track_num = (3,5) t.disc_num = (1,1) t.original_release_date = "1994-04-07" t.release_date = "1994-04-07" t.encoding_date = "2002-03" t.recording_date = 1996 t.tagging_date = "2012-2-5" t.comments.set(u"Gritty, yo!") t.comments.set(u"Brownsville, Brooklyn", u"Origin") t.user_text_frames.set(u"****", u"Rating") t.artist_url = b"http://allmusic.com/artist/mop-p194909" t.user_url_frames.set(b"http://eyed3.nicfit.net/")