Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_write_popm_long_counter(self):
from mutagen.id3 import POPM
f = ID3(self.newfilename)
f.add(POPM(email="foo@example.com", rating=125, count=2**32+1))
f.save()
f = ID3(self.newfilename)
self.failUnless("POPM:foo@example.com" in f)
self.failUnless("POPM:Windows Media Player 9 Series" in f)
popm = f["POPM:foo@example.com"]
self.assertEquals(popm.rating, 125)
self.assertEquals(popm.count, 2**32+1)
def _test_text_frame(self, short, longer, frame):
new_value = "TEST"
for arg in [short, longer]:
orig = ID3(self.filename)
frame_class = mutagen.id3.Frames[frame]
orig[frame] = frame_class(text=[u"BLAH"], encoding=3)
orig.save()
res, out = self.call(arg, new_value, self.filename)
self.failUnlessEqual(res, 0)
self.failIf(out)
self.failUnlessEqual(ID3(self.filename)[frame].text, [new_value])
def test_header_2_4_extended_unsynch_size(self):
id3 = ID3()
id3._fileobj = cBytesIO(
b'ID3\x04\x00\x40\x00\x00\x00\x00\x00\x00\x00\xFF\x5a')
self.assertRaises(ValueError, id3._load_header)
def test_header_2_4_allow_footer(self):
id3 = ID3()
id3._fileobj = cBytesIO(b'ID3\x04\x00\x10\x00\x00\x00\x00')
id3._load_header()
def _test_text_frame(self, short, longer, frame):
new_value = fsn(u"TEST")
for arg in [short, longer]:
orig = ID3(self.filename)
frame_class = mutagen.id3.Frames[frame]
orig[frame] = frame_class(text=[u"BLAH"], encoding=3)
orig.save()
res, out = self.call(arg, new_value, self.filename)
self.failUnlessEqual(res, 0)
self.failIf(out)
self.failUnlessEqual(ID3(self.filename)[frame].text, [new_value])
def test_write_popm_long_counter(self):
from mutagen.id3 import POPM
f = ID3(self.newfilename)
f.add(POPM(email="foo@example.com", rating=125, count=2**32+1))
f.save()
f = ID3(self.newfilename)
self.failUnless("POPM:foo@example.com" in f)
self.failUnless("POPM:Windows Media Player 9 Series" in f)
popm = f["POPM:foo@example.com"]
self.assertEquals(popm.rating, 125)
self.assertEquals(popm.count, 2**32+1)
def test_header_2_4_invalid_flags(self):
id3 = ID3()
id3._fileobj = cBytesIO(b'ID3\x04\x00\x1f\x00\x00\x00\x00')
self.assertRaises(ValueError, id3._load_header)
def setUp(self):
from tempfile import mkstemp
fd, self.filename = mkstemp(suffix='.mp3')
os.close(fd)
shutil.copy(self.SILENCE, self.filename)
self.audio = ID3(self.filename)
def check_dir(path):
from traceback import print_exc
from mutagen.id3 import ID3NoHeaderError, ID3UnsupportedVersionError
rep = Report(path)
print "Scanning", path
for path, dirs, files in os.walk(path):
files.sort()
for fn in files:
if not fn.lower().endswith('.mp3'): continue
ffn = os.path.join(path, fn)
try:
id3 = ID3()
id3.PEDANTIC = False
id3.load(ffn)
except KeyboardInterrupt: raise
except ID3NoHeaderError: rep.missing(ffn)
except Exception, err: rep.error(ffn)
else: rep.success(id3)
print str(rep)
def embed_artwork(track_filename, artwork_filename):
audio = MP3(track_filename, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
audio.add_tags()
except error:
pass
audio.tags.add(
APIC(
encoding=3, # 3 is for utf-8
mime='image/jpg', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(artwork_filename).read()
)
)
audio.save()