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
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))
def process_bind_param(self, value, dialect): if isinstance(value, Eyed3Date): return str(value) elif value: return str(Eyed3Date.parse(value)) else: return None
def process_bind_param(self, value, dialect): if isinstance(value, Eyed3Date): return str(value) elif value: return str(Eyed3Date.parse(value)) else: return None
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")
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")
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
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")
def process_result_value(self, value, dialect): return Eyed3Date.parse(value) if value else None
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)
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)
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)
def process_result_value(self, value, dialect): return Eyed3Date.parse(value) if value else None