예제 #1
0
 def change_id3_tags(self, dir_tags_v1, dir_tags_v2):
     self.tag_v1.track_num = (dir_tags_v1['Track number'][0], None)
     self.tag_v1.title = dir_tags_v1['Title'] if dir_tags_v1['Title'] != '' else None
     self.tag_v1.artist = dir_tags_v1['Artist'] if dir_tags_v1['Artist'] != '' else None
     self.tag_v1.album = dir_tags_v1['Album'] if dir_tags_v1['Album'] != '' else None
     if 0 < dir_tags_v1['Genre'] < 255:
         self.tag_v1.genre = dir_tags_v1['Genre']
     date = dir_tags_v1['Date']
     self.tag_v1.recording_date = Date(date[2], date[1], date[0])
     self.tag_v1.comments.set(dir_tags_v1['Comments'])
     self.tag_v1.save()
     tn = dir_tags_v2['Track number']
     dn = dir_tags_v2['Disc number']
     self.tag_v2.track_num = (tn[0], tn[1])
     self.tag_v2.disc_num = (dn[0], dn[1])
     self.tag_v2.title = dir_tags_v2['Title'] if dir_tags_v2['Title'] != '' else None
     self.tag_v2.artist = dir_tags_v2['Artist'] if dir_tags_v2['Artist'] != '' else None
     self.tag_v2.album = dir_tags_v2['Album'] if dir_tags_v2['Album'] != '' else None
     self.tag_v2.album_artist = dir_tags_v2['Album artist'] if dir_tags_v2['Album artist'] != '' else None
     if 0 < dir_tags_v2['Genre'] < 255:
         self.tag_v2.genre = dir_tags_v2['Genre']
     date = dir_tags_v2['Date']
     self.tag_v2.recording_date = Date(date[2], date[1], date[0])
     self.tag_v2.comments.set(dir_tags_v1['Comments'])
     self.tag_v2.publisher = dir_tags_v2['Publisher'] if dir_tags_v2['Publisher'] != '' else None
     self.tag_v2.composer = dir_tags_v2['Composer'] if dir_tags_v2['Composer'] != '' else None
     self.tag_v2.bpm = dir_tags_v2['BPM'][0]
     self.tag_v2.save()
예제 #2
0
파일: test_frames.py 프로젝트: haojp/eyeD3
def test_DateFrame():
    from eyed3.id3.frames import DateFrame
    from eyed3.core import Date

    # Default ctor
    df = DateFrame(b"TDRC")
    assert df.text == ""
    assert df.date is None

    # Ctor with eyed3.core.Date arg
    for d in [
            Date(2012),
            Date(2012, 1),
            Date(2012, 1, 4),
            Date(2012, 1, 4, 18),
            Date(2012, 1, 4, 18, 15),
            Date(2012, 1, 4, 18, 15, 30),
    ]:
        df = DateFrame(b"TDRC", d)
        assert df.text == str(d)
        # Comparison is on each member, not reference ID
        assert df.date == d

    # Test ctor str arg is converted
    for d in [
            "2012",
            "2010-01",
            "2010-01-04",
            "2010-01-04T18",
            "2010-01-04T06:20",
            "2010-01-04T06:20:15",
            "2012",
            "2010-01",
            "2010-01-04",
            "2010-01-04T18",
            "2010-01-04T06:20",
            "2010-01-04T06:20:15",
    ]:
        df = DateFrame(b"TDRC", d)
        dt = Date.parse(d)
        assert df.text == str(dt)
        assert df.text == str(d)
        # Comparison is on each member, not reference ID
        assert df.date == dt

    # Technically invalid, but supported
    for d in ["20180215"]:
        df = DateFrame(b"TDRC", d)
        dt = Date.parse(d)
        assert df.text == str(dt)
        # Comparison is on each member, not reference ID
        assert df.date == dt

    # Invalid dates
    for d in ["1234:12"]:
        date = DateFrame(b"TDRL")
        date.date = d
        assert not date.date
예제 #3
0
파일: orm.py 프로젝트: nicfit/mishmash
 def process_bind_param(self, value, dialect):
     if isinstance(value, Eyed3Date):
         return str(value)
     elif value:
         return str(Eyed3Date.parse(value))
     else:
         return None
예제 #4
0
 def process_bind_param(self, value, dialect):
     if isinstance(value, Eyed3Date):
         return str(value)
     elif value:
         return str(Eyed3Date.parse(value))
     else:
         return None
예제 #5
0
def fix_id3_for_show(show_info: RefinedShow):
    log.info(f"Fixing ID3 tags for {show_info.id}")

    tx_date = show_info.tx_date()
    id3_date = Date(year=tx_date.year, month=tx_date.month, day=tx_date.day)

    audio: AudioFile = show_info.get_audio_file()
    metadata = audio.get_metadata()

    if not metadata.tag:
        metadata.initTag()

    metadata.tag.title = show_info.title()
    metadata.tag.album = show_info.album()

    metadata.tag.album_artist = "Frank Key"
    metadata.tag.artist = "Frank Key"
    metadata.tag.recording_date = id3_date
    metadata.tag.encoding_date = id3_date
    metadata.tag.genre = "Humour"

    for story in show_info.stories:
        story_info = story.get_story_info()
        start_time = story.time_code
        story_title = story_info.story.title
        end_time = (
            story.next_story.time_code if story.next_story else show_info.get_duration()
        )
        metadata.tag.chapters.set(story_title.encode("utf-8"), (start_time, end_time))

    metadata.tag.save(version=ID3_DEFAULT_VERSION)

    log.info(f"Finished: {show_info.id}")
예제 #6
0
        def apply(self, mp3, config):
            if config.tmpl==None: return False

            # pull properties from mp3
            tag_props={ x:getattr(mp3.tag, x) for x in dir(mp3.tag) if x[0]!='_' if not any(c.isupper() for c in x) }

            tag_props['inc_index']=self.inc_index
            m=re.match(config.re_fileindex, os.path.basename(mp3.path))
            tag_props['file_index']=int(m.group(1)) if m else self.inc_index
            tag_props['file_name']=os.path.basename(mp3.path)
            tag_props['file_path']=mp3.path
            tag_props['none']=None

            if self.opts.renumber and tag_props['title'] != None:
                tit=tag_props['title']
                titm=re.match(self.opts.rere, tit)
                if titm != None:
                    print("  modify title: {} -> {}".format(tit, titm.group(1)))
                    tag_props['title']=titm.group(1)

            for k in config.tmpl:
                cmd=None
                ck=Config.CondKey(k)
                if ck.re != None and ck.value_tmpl != None and not ck.match(tag_props):
                    #print("{} did not match {} (-> {})".format(k, ck.value_tmpl.templ, ck.value_tmpl.resolve(tag_props)))
                    continue

                templ=config.tmpl[k]
                new_data=templ.resolve(tag_props)

                # some special handling
                if "date" in ck.key:
                    new_data=Date.parse(str(new_data))
                else:
                    # if we find '(' in data, means it's a tuple and so convert it to actual tuple doing eval
                    if isinstance(new_data, str) and '(' in new_data: new_data=eval(new_data)

                if args.all: print("  {}: {} -> ({}){}".format(ck.key, getattr(mp3.tag, ck.key), type(new_data), new_data))
                else: print("  {}: {} -> {}".format(ck.key, getattr(mp3.tag, ck.key), new_data))
                if not self.opts.dryrun:
                    setattr(mp3.tag, ck.key, new_data)

            for i in config.images:
                if not i.does_match(tag_props):
                    continue

                if i.is_nil():
                    mp3.tag.images.remove(i.key.key)
                else:
                    pic_type=eyed3.id3.frames.ImageFrame.stringToPicType(i.key.key.upper())
                    imgdat=i.resolve_image_data(tag_props)
                    print("  Setting {} picture {} bytes for {}".format(i.mime, len(imgdat), i.key.key))
                    mp3.tag.images.set(pic_type, imgdat, i.mime, "", )

            self.inc_index+=1
예제 #7
0
파일: test_frames.py 프로젝트: nicfit/eyed3
def test_DateFrame():
    from eyed3.id3.frames import DateFrame
    from eyed3.core import Date

    # Default ctor
    df = DateFrame(b"TDRC")
    assert df.text == ""
    assert df.date is None

    # Ctor with eyed3.core.Date arg
    for d in [Date(2012),
              Date(2012, 1),
              Date(2012, 1, 4),
              Date(2012, 1, 4, 18),
              Date(2012, 1, 4, 18, 15),
              Date(2012, 1, 4, 18, 15, 30),
             ]:
        df = DateFrame(b"TDRC", d)
        assert (df.text == str(d))
        # Comparison is on each member, not reference ID
        assert (df.date == d)

    # Test ctor str arg is converted
    for d in ["2012",
              "2010-01",
              "2010-01-04",
              "2010-01-04T18",
              "2010-01-04T06:20",
              "2010-01-04T06:20:15",
              "2012",
              "2010-01",
              "2010-01-04",
              "2010-01-04T18",
              "2010-01-04T06:20",
              "2010-01-04T06:20:15",
             ]:
        df = DateFrame(b"TDRC", d)
        dt = Date.parse(d)
        assert (df.text == str(dt))
        assert (df.text == str(d))
        # Comparison is on each member, not reference ID
        assert (df.date == dt)

    # Invalid dates
    for d in ["1234:12"]:
        date = DateFrame(b"TDRL")
        date.date = d
        assert not date.date

        try:
            date.date = 9
        except TypeError:
            pass
        else:
            pytest.fail("TypeError not thrown")
예제 #8
0
def test_DateFrame():
    from eyed3.id3.frames import DateFrame
    from eyed3.core import Date

    # Default ctor
    df = DateFrame(b"TDRC")
    assert_equal(df.text, u"")
    assert_is_none(df.date)

    # Ctor with eyed3.core.Date arg
    for d in [
            Date(2012),
            Date(2012, 1),
            Date(2012, 1, 4),
            Date(2012, 1, 4, 18),
            Date(2012, 1, 4, 18, 15),
            Date(2012, 1, 4, 18, 15, 30),
    ]:
        df = DateFrame(b"TDRC", d)
        assert_equal(df.text, unicode(str(d)))
        # Comparison is on each member, not reference ID
        assert_equal(df.date, d)

    # Test ctor str arg is converted
    for d in [
            "2012",
            "2010-01",
            "2010-01-04",
            "2010-01-04T18",
            "2010-01-04T06:20",
            "2010-01-04T06:20:15",
            u"2012",
            u"2010-01",
            u"2010-01-04",
            u"2010-01-04T18",
            u"2010-01-04T06:20",
            u"2010-01-04T06:20:15",
    ]:
        df = DateFrame(b"TDRC", d)
        dt = Date.parse(d)
        assert_equal(df.text, unicode(str(dt)))
        assert_equal(df.text, unicode(d))
        # Comparison is on each member, not reference ID
        assert_equal(df.date, dt)

    # Invalid dates
    for d in ["1234:12"]:
        date = DateFrame(b"TDRL")
        date.date = d
        assert_false(date.date)

        try:
            date.date = 9
        except TypeError:
            pass
        else:
            assert_false("TypeError not thrown")
예제 #9
0
def test_DateFrame():
    from eyed3.id3.frames import DateFrame
    from eyed3.core import Date

    # Default ctor
    df = DateFrame(b"TDRC")
    assert df.text == ""
    assert df.date is None

    # Ctor with eyed3.core.Date arg
    for d in [
            Date(2012),
            Date(2012, 1),
            Date(2012, 1, 4),
            Date(2012, 1, 4, 18),
            Date(2012, 1, 4, 18, 15),
            Date(2012, 1, 4, 18, 15, 30),
    ]:
        df = DateFrame(b"TDRC", d)
        assert (df.text == str(d))
        # Comparison is on each member, not reference ID
        assert (df.date == d)

    # Test ctor str arg is converted
    for d in [
            "2012",
            "2010-01",
            "2010-01-04",
            "2010-01-04T18",
            "2010-01-04T06:20",
            "2010-01-04T06:20:15",
            "2012",
            "2010-01",
            "2010-01-04",
            "2010-01-04T18",
            "2010-01-04T06:20",
            "2010-01-04T06:20:15",
    ]:
        df = DateFrame(b"TDRC", d)
        dt = Date.parse(d)
        assert (df.text == str(dt))
        assert (df.text == str(d))
        # Comparison is on each member, not reference ID
        assert (df.date == dt)

    # Invalid dates
    for d in ["1234:12"]:
        date = DateFrame(b"TDRL")
        date.date = d
        assert not date.date

        try:
            date.date = 9
        except TypeError:
            pass
        else:
            pytest.fail("TypeError not thrown")
예제 #10
0
파일: test_tag.py 프로젝트: haojp/eyeD3
def testReleaseDate_v23_v24():
    """v23 does not have release date, only original release date."""
    date = Date.parse("1980-07-03")
    date2 = Date.parse("1926-07-05")
    year = Date(1966)

    tag = Tag()
    assert tag.version == ID3_DEFAULT_VERSION

    tag.version = ID3_V2_3
    assert tag.version == ID3_V2_3

    # Setting release date sets original release date
    # v2.3 TORY get the year, XDOR get the full date; getter prefers XDOR
    tag.release_date = "2020-03-08"
    assert b"TORY" in tag.frame_set
    assert b"XDOR" in tag.frame_set
    assert tag.release_date == Date.parse("2020-03-08")
    assert tag.original_release_date == Date(year=2020, month=3, day=8)

    # Setting original release date sets release date
    tag.original_release_date = year
    assert tag.original_release_date == Date(1966)
    assert tag.release_date == Date.parse("1966")
    assert b"TORY" in tag.frame_set
    # Year only value should clean up XDOR
    assert b"XDOR" not in tag.frame_set

    # Version convert to 2.4 converts original release date only
    tag.release_date = date
    assert b"TORY" in tag.frame_set
    assert b"XDOR" in tag.frame_set
    assert tag.original_release_date == date
    assert tag.release_date == date
    tag.version = ID3_V2_4
    assert tag.original_release_date == date
    assert tag.release_date is None

    # v2.4 has both date types
    tag.release_date = date2
    assert tag.original_release_date == date
    assert tag.release_date == date2
    assert b"TORY" not in tag.frame_set
    assert b"XDOR" not in tag.frame_set

    # Convert back to 2.3 loses release date, only the year is copied to TORY
    tag.version = ID3_V2_3
    assert b"TORY" in tag.frame_set
    assert b"XDOR" in tag.frame_set
    assert tag.original_release_date == date
    assert tag.release_date == Date.parse(str(date))
예제 #11
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")
예제 #12
0
 def id3_date(self):
     d = self._fake.date_object()
     full_date = random.choices(["y", "n"], cum_weights=[15, 85]) == "y"
     return Date(year=d.year,
                 month=d.month if full_date else None,
                 day=d.day if full_date else None)
예제 #13
0
        ydl.download([url])

for file in os.listdir('./'):
    if file.lower().endswith('.mp3'):
        file_name = file[:-4]
        info_json = file_name + '.info.json'
        if os.path.exists(info_json):
            with open(info_json) as jf:
                info = json.load(jf)
            thumbnail = info.get('thumbnail', '')
            upl = simplify_string(info.get('uploader', '-'))
            title = simplify_string(info.get('title', '-'))
            print('Setting id3 tags to ', title)
            audiofile = eyed3.load(file)
            audiofile.tag.recording_date = Date(
                int(info['upload_date'][:4]),
                month=int(info['upload_date'][4:6]),
                day=int(info['upload_date'][6:]))
            audiofile.tag.title = title
            audiofile.tag.artist = upl
            audiofile.tag.album = simplify_string(
                info.get('uploader', file_name))
            audiofile.tag.album_artist = upl if not info.get(
                'tags', '') else info.get('tags', ['-'])[0]
            audiofile.tag.save()
            simpl_name = simplify_string(
                (title.replace(' - ', '_') + '.mp3').replace('..', '.'))
            os.rename(file, simpl_name)
            os.remove(info_json)

input('Press enter to exit...')
예제 #14
0
def test_Date():
    from eyed3.core import Date

    for d in [Date(1973), Date(year=1973), Date.parse("1973")]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, None)
        assert_equal(d.day, None)
        assert_equal(d.hour, None)
        assert_equal(d.minute, None)
        assert_equal(d.second, None)
        assert_equal(str(d), "1973")

    for d in [Date(1973, 3), Date(year=1973, month=3), Date.parse("1973-03")]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, 3)
        assert_equal(d.day, None)
        assert_equal(d.hour, None)
        assert_equal(d.minute, None)
        assert_equal(d.second, None)
        assert_equal(str(d), "1973-03")

    for d in [
            Date(1973, 3, 6),
            Date(year=1973, month=3, day=6),
            Date.parse("1973-3-6")
    ]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, 3)
        assert_equal(d.day, 6)
        assert_equal(d.hour, None)
        assert_equal(d.minute, None)
        assert_equal(d.second, None)
        assert_equal(str(d), "1973-03-06")

    for d in [
            Date(1973, 3, 6, 23),
            Date(year=1973, month=3, day=6, hour=23),
            Date.parse("1973-3-6T23")
    ]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, 3)
        assert_equal(d.day, 6)
        assert_equal(d.hour, 23)
        assert_equal(d.minute, None)
        assert_equal(d.second, None)
        assert_equal(str(d), "1973-03-06T23")

    for d in [
            Date(1973, 3, 6, 23, 20),
            Date(year=1973, month=3, day=6, hour=23, minute=20),
            Date.parse("1973-3-6T23:20")
    ]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, 3)
        assert_equal(d.day, 6)
        assert_equal(d.hour, 23)
        assert_equal(d.minute, 20)
        assert_equal(d.second, None)
        assert_equal(str(d), "1973-03-06T23:20")

    for d in [
            Date(1973, 3, 6, 23, 20, 15),
            Date(year=1973, month=3, day=6, hour=23, minute=20, second=15),
            Date.parse("1973-3-6T23:20:15")
    ]:
        assert_equal(d.year, 1973)
        assert_equal(d.month, 3)
        assert_equal(d.day, 6)
        assert_equal(d.hour, 23)
        assert_equal(d.minute, 20)
        assert_equal(d.second, 15)
        assert_equal(str(d), "1973-03-06T23:20:15")

    assert_raises(ValueError, Date.parse, "")
    assert_raises(ValueError, Date.parse, "ABC")
    assert_raises(ValueError, Date.parse, "2010/1/24")

    assert_raises(ValueError, Date, 2012, 0)
    assert_raises(ValueError, Date, 2012, 1, 35)
    assert_raises(ValueError, Date, 2012, 1, 4, -1)
    assert_raises(ValueError, Date, 2012, 1, 4, 24)
    assert_raises(ValueError, Date, 2012, 1, 4, 18, 60)
    assert_raises(ValueError, Date, 2012, 1, 4, 18, 14, 61)
예제 #15
0
파일: test_core.py 프로젝트: haojp/eyeD3
def test_Date():
    from eyed3.core import Date

    for d in [Date(1965), Date(year=1965), Date.parse("1965")]:
        assert d.year == 1965
        assert d.month is None
        assert d.day is None
        assert d.hour is None
        assert d.minute is None
        assert d.second is None
        assert str(d) == "1965"

    for d in [Date(1965, 3), Date(year=1965, month=3), Date.parse("1965-03")]:
        assert d.year == 1965
        assert d.month == 3
        assert d.day is None
        assert d.hour is None
        assert d.minute is None
        assert d.second is None
        assert str(d) == "1965-03"

    for d in [
            Date(1965, 3, 6),
            Date(year=1965, month=3, day=6),
            Date.parse("1965-3-6")
    ]:
        assert d.year == 1965
        assert d.month == 3
        assert d.day == 6
        assert d.hour is None
        assert d.minute is None
        assert d.second is None
        assert (str(d) == "1965-03-06")

    for d in [
            Date(1965, 3, 6, 23),
            Date(year=1965, month=3, day=6, hour=23),
            Date.parse("1965-3-6T23")
    ]:
        assert d.year == 1965
        assert d.month == 3
        assert d.day == 6
        assert d.hour == 23
        assert d.minute is None
        assert d.second is None
        assert str(d) == "1965-03-06T23"

    for d in [
            Date(1965, 3, 6, 23, 20),
            Date(year=1965, month=3, day=6, hour=23, minute=20),
            Date.parse("1965-3-6T23:20")
    ]:
        assert d.year == 1965
        assert d.month == 3
        assert d.day == 6
        assert d.hour == 23
        assert d.minute == 20
        assert d.second is None
        assert str(d) == "1965-03-06T23:20"

    for d in [
            Date(1965, 3, 6, 23, 20, 15),
            Date(year=1965, month=3, day=6, hour=23, minute=20, second=15),
            Date.parse("1965-3-6T23:20:15")
    ]:
        assert d.year == 1965
        assert d.month == 3
        assert d.day == 6
        assert d.hour == 23
        assert d.minute == 20
        assert d.second == 15
        assert str(d) == "1965-03-06T23:20:15"

    with pytest.raises(ValueError):
        Date.parse("")
    with pytest.raises(ValueError):
        Date.parse("ABC")
    with pytest.raises(ValueError):
        Date.parse("2010/1/24")

    with pytest.raises(ValueError):
        Date(2012, 0)
    with pytest.raises(ValueError):
        Date(2012, 1, 35)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, -1)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 24)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 18, 60)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 18, 14, 61)

    dt = Date(1965, 3, 6, 23, 20, 15)
    dp = Date(1980, 7, 3, 10, 5, 1)
    assert dt != dp
    assert dt < dp
    assert not dp < dt
    assert None < dp
    assert not dp < dp
    assert dp <= dp

    assert hash(dt) != hash(dp)
예제 #16
0
 def process_result_value(self, value, dialect):
     return Eyed3Date.parse(value) if value else None
예제 #17
0
        fetchFlag = (args.missing is True) and (len(tag.images) == 0)
        fetchFlag = fetchFlag or (args.missing is False)

        if fetchFlag is True:
            search_response = youtube.search().list(
                type='video',
                q='{} - {}'.format(tag.artist.encode(ENCODING),
                                   tag.title.encode(ENCODING)),
                part='snippet',
                maxResults=1).execute()

            imgURL = None
            for item in search_response['items']:
                if (tag.recording_date is None) or (tag.recording_date == ''):
                    year = item['snippet']['publishedAt'][0:4]
                    tag.recording_date = Date(int(year))

                imgURL = item['snippet']['thumbnails']['high']['url']

            if imgURL is not None:
                # update image
                # remove existing images
                for img in tag.images:
                    tag.images.remove(img.description)

                imgData = urllib.urlopen(imgURL).read()
                tag.images.set(ImageFrame.FRONT_COVER, imgData, "image/jpeg")

                tag.save('{}/{}'.format(args.folderName, fname),
                         version=ID3_DEFAULT_VERSION,
                         encoding=ENCODING.lower())
예제 #18
0
def test_Date():
    from eyed3.core import Date

    for d in [Date(1973),
              Date(year=1973),
              Date.parse("1973")]:
        assert (d.year == 1973)
        assert (d.month == None)
        assert (d.day == None)
        assert (d.hour == None)
        assert (d.minute == None)
        assert (d.second == None)
        assert (str(d) == "1973")

    for d in [Date(1973, 3),
              Date(year=1973, month=3),
              Date.parse("1973-03")]:
        assert (d.year == 1973)
        assert (d.month == 3)
        assert (d.day == None)
        assert (d.hour == None)
        assert (d.minute == None)
        assert (d.second == None)
        assert (str(d) == "1973-03")

    for d in [Date(1973, 3, 6),
              Date(year=1973, month=3, day=6),
              Date.parse("1973-3-6")]:
        assert (d.year == 1973)
        assert (d.month == 3)
        assert (d.day == 6)
        assert (d.hour == None)
        assert (d.minute == None)
        assert (d.second == None)
        assert (str(d) == "1973-03-06")

    for d in [Date(1973, 3, 6, 23),
              Date(year=1973, month=3, day=6, hour=23),
              Date.parse("1973-3-6T23")]:
        assert (d.year == 1973)
        assert (d.month == 3)
        assert (d.day == 6)
        assert (d.hour == 23)
        assert (d.minute == None)
        assert (d.second == None)
        assert (str(d) == "1973-03-06T23")

    for d in [Date(1973, 3, 6, 23, 20),
              Date(year=1973, month=3, day=6, hour=23, minute=20),
              Date.parse("1973-3-6T23:20")]:
        assert (d.year == 1973)
        assert (d.month == 3)
        assert (d.day == 6)
        assert (d.hour == 23)
        assert (d.minute == 20)
        assert (d.second == None)
        assert (str(d) == "1973-03-06T23:20")

    for d in [Date(1973, 3, 6, 23, 20, 15),
              Date(year=1973, month=3, day=6, hour=23, minute=20,
                   second=15),
              Date.parse("1973-3-6T23:20:15")]:
        assert (d.year == 1973)
        assert (d.month == 3)
        assert (d.day == 6)
        assert (d.hour == 23)
        assert (d.minute == 20)
        assert (d.second == 15)
        assert (str(d) == "1973-03-06T23:20:15")

    with pytest.raises(ValueError):
        Date.parse("")
    with pytest.raises(ValueError):
        Date.parse("ABC")
    with pytest.raises(ValueError):
        Date.parse("2010/1/24")

    with pytest.raises(ValueError):
        Date(2012, 0)
    with pytest.raises(ValueError):
        Date(2012, 1, 35)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, -1)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 24)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 18, 60)
    with pytest.raises(ValueError):
        Date(2012, 1, 4, 18, 14, 61)

    dt = Date(1973, 3, 6, 23, 20, 15)
    assert not dt == None
    dp = Date(1980, 7, 3, 10, 5, 1)
    assert dt != dp
    assert dt < dp
    assert not dp < dt
    assert None < dp
    assert not dp < dp
    assert dp <= dp

    assert hash(dt) != hash(dp)
예제 #19
0
파일: orm.py 프로젝트: nicfit/mishmash
 def process_result_value(self, value, dialect):
     return Eyed3Date.parse(value) if value else None
예제 #20
0
        tag.album_artist = unicode(song.getArtist())
        tag.title = unicode(song.getTitle())
        tag.album = unicode(song.getAlbum())
        tag.genre = unicode(song.getGenre())

        # remove comments
        for c in tag.comments:
            tag.comments.remove(c.description)

        for key in frameSetKeys:
            if key in tag.frame_set:
                while len(tag.frame_set[key]) > 0:
                    del tag.frame_set[key][0]

        if song.getYear().isdigit():
            tag.recording_date = Date(int(song.getYear()))

        # update image
        # remove existing images
        for img in tag.images:
            tag.images.remove(img.description)

        # set new image
        imgURL = song.getImageURL()
        if imgURL is not None:
            imgData = urllib.urlopen(imgURL).read()
            tag.images.set(ImageFrame.FRONT_COVER, imgData, "image/jpeg")

        tag.save('{}/{}'.format(args.folderName, fname), version=ID3_DEFAULT_VERSION, encoding='utf-8')

        if i % nFilesPerPercent == 0: