Esempio n. 1
0
def testTagDates():
    tag = Tag()
    tag.release_date = 2004
    assert tag.release_date == Date(2004)

    tag.release_date = None
    assert tag.release_date is None

    tag = Tag()
    for date in [
            Date(2002),
            Date(2002, 11, 26),
            Date(2002, 11, 26),
            Date(2002, 11, 26, 4),
            Date(2002, 11, 26, 4, 20),
            Date(2002, 11, 26, 4, 20),
            Date(2002, 11, 26, 4, 20, 10)
    ]:

        tag.encoding_date = date
        assert (tag.encoding_date == date)
        tag.encoding_date = str(date)
        assert (tag.encoding_date == date)

        tag.release_date = date
        assert (tag.release_date == date)
        tag.release_date = str(date)
        assert (tag.release_date == date)

        tag.original_release_date = date
        assert (tag.original_release_date == date)
        tag.original_release_date = str(date)
        assert (tag.original_release_date == date)

        tag.recording_date = date
        assert (tag.recording_date == date)
        tag.recording_date = str(date)
        assert (tag.recording_date == date)

        tag.tagging_date = date
        assert (tag.tagging_date == date)
        tag.tagging_date = str(date)
        assert (tag.tagging_date == date)

        try:
            tag._setDate(2.4)
        except TypeError:
            pass  # expected
        else:
            assert not ("Invalid date type, expected TypeError")
Esempio n. 2
0
def testTagDates():
    tag = Tag()
    tag.release_date = 2004
    assert tag.release_date == Date(2004)

    tag.release_date = None
    assert tag.release_date is None

    tag = Tag()
    for date in [Date(2002), Date(2002, 11, 26), Date(2002, 11, 26),
                 Date(2002, 11, 26, 4), Date(2002, 11, 26, 4, 20),
                 Date(2002, 11, 26, 4, 20), Date(2002, 11, 26, 4, 20, 10)]:

        tag.encoding_date = date
        assert (tag.encoding_date == date)
        tag.encoding_date = str(date)
        assert (tag.encoding_date == date)

        tag.release_date = date
        assert (tag.release_date == date)
        tag.release_date = str(date)
        assert (tag.release_date == date)

        tag.original_release_date = date
        assert (tag.original_release_date == date)
        tag.original_release_date = str(date)
        assert (tag.original_release_date == date)

        tag.recording_date = date
        assert (tag.recording_date == date)
        tag.recording_date = str(date)
        assert (tag.recording_date == date)

        tag.tagging_date = date
        assert (tag.tagging_date == date)
        tag.tagging_date = str(date)
        assert (tag.tagging_date == date)


        try:
            tag._setDate(2.4)
        except TypeError:
            pass # expected
        else:
            assert not("Invalid date type, expected TypeError")
Esempio n. 3
0
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/")

t.bpm = 187
t.play_count = 125
t.unique_file_ids.set(b"43e888e067ea107f964916af6259cbe7", "md5sum")
t.cd_id = b"\x3c\x33\x4d\x41\x43\x59\x3c\x33"
t.privates.set("Secrets", "Billy Danzenie")
Esempio n. 4
0
    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)
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/")

t.bpm = 187
t.play_count = 125
t.unique_file_ids.set(b"43e888e067ea107f964916af6259cbe7", "md5sum")
t.cd_id = b"\x3c\x33\x4d\x41\x43\x59\x3c\x33"
t.privates.set("Secrets", "Billy Danzenie")