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_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])
frame = mutagen.id3.APIC(encoding=encoding, mime=mime,
desc=desc, type=picture_type, data=data)
id3.add(frame)
elif frame == "COMM":
for value in vlist:
values = string_split(value, ":")
if len(values) == 1:
value, desc, lang = values[0], "", "eng"
elif len(values) == 2:
desc, value, lang = values[0], values[1], "eng"
else:
value = ":".join(values[1:-1])
desc, lang = values[0], values[-1]
frame = mutagen.id3.COMM(
encoding=3, text=value, lang=lang, desc=desc)
id3.add(frame)
elif frame == "USLT":
for value in vlist:
values = string_split(value, ":")
if len(values) == 1:
value, desc, lang = values[0], "", "eng"
elif len(values) == 2:
desc, value, lang = values[0], values[1], "eng"
else:
value = ":".join(values[1:-1])
desc, lang = values[0], values[-1]
frame = mutagen.id3.USLT(
encoding=3, text=value, lang=lang, desc=desc)
id3.add(frame)
elif frame == "UFID":
remove_v1 = options.remove_v1
def conv(uni):
return uni.encode('iso-8859-1').decode(encoding)
for filename in filenames:
with _sig.block():
if verbose != "quiet":
print_(u"Updating", filename)
if has_id3v1(filename) and not noupdate and force_v1:
mutagen.id3.delete(filename, False, True)
try:
id3 = mutagen.id3.ID3(filename)
except mutagen.id3.ID3NoHeaderError:
if verbose != "quiet":
print_(u"No ID3 header found; skipping...")
continue
except Exception as err:
print_(str(err), file=sys.stderr)
continue
for tag in filter(lambda t: t.startswith(("T", "COMM")), id3):
frame = id3[tag]
if isinstance(frame, mutagen.id3.TimeStampTextFrame):
# non-unicode fields
continue
try:
text = frame.text
except AttributeError:
continue
return obj.value
if isinstance(obj, mutagen.mp4.MP4FreeForm):
try:
if obj.FORMAT_TEXT == mutagen.mp4.AtomDataType.UTF8:
return obj.decode('utf-8').replace('\x00','')
elif obj.FORMAT_TEXT == mutagen.mp4.AtomDataType.UTF16:
return obj.decode('utf-16').replace('\x00','')
except UnicodeDecodeError:
print(f'Wrong unicode data found in tag {tag}: {obj}')
return None
return str(obj)
if isinstance(obj, (mutagen.id3.TCON, mutagen.id3.TPUB, mutagen.id3.TSRC,
mutagen.id3.TSOC, mutagen.id3.TCOM, mutagen.id3.TEXT,
mutagen.id3.TPE3, mutagen.id3.TPE4, mutagen.id3.TLAN,
mutagen.id3.TMOO)):
return obj.text
if isinstance(obj, (mutagen.id3.TMCL, mutagen.id3.TIPL)):
return [role + ':' + name for role, name in obj.people]
if isinstance(obj, mutagen.id3.COMM):
text = obj.text
if isinstance(text, list):
text = ','.join(text)
return text
if (isinstance(obj, mutagen.id3.TXXX) and
obj.desc.lower() in ['musicbrainz album type',
'musicbrainz artist id',
'musicbrainz album artist id',
f.write(stringIO.getvalue())
try:
audio = MP3(tmpfile)
break
except EOFError: # We still didn't fetch all the ID3 data.
pass
# log.debug("metadata is not in this %d KB chunk or not supported." % len(stringIO.getvalue()))
except mutagen.mp3.HeaderNotFoundError:
log.debug("HeaderNotFoundError: can't sync to an MPEG frame")
stringIO.close()
return [0, "", "", ""]
stringIO.close()
try:
audioID3 = EasyID3(tmpfile)
except mutagen.id3.ID3NoHeaderError:
log.debug("no ID3data found (mutagen.id3.ID3NoHeaderError).")
return [audio.info.bitrate, "", "", ""]
except mutagen.id3.ID3BadUnsynchData:
log.debug("Bad ID3 Unsynch Data (mutagen.id3.ID3BadUnsynchData)")
return [audio.info.bitrate, "", "", ""]
title = utils.fix_faulty_unicode(audioID3.get('title')[0]) if audioID3.get('title') else ""
artist = utils.fix_faulty_unicode(audioID3.get('artist')[0]) if audioID3.get('artist') else ""
return [audio.info.bitrate, title, artist, tmpfile]
def embed_image():
id3_dict.add(
id3.APIC(
encoding=3,
mime='image/jpeg',
type=3,
desc='Front Cover',
data=image.data
)
def list_genres(option, opt, value, parser):
for i, genre in enumerate(mutagen.id3.TCON.GENRES):
print_(u"%3d: %s" % (i, genre))
raise SystemExit
id3_version + Fore.RESET)
print("-" * 79)
elif args.output_type == "m4a":
bit_rate = ((audio.info.bits_per_sample * audio.info.sample_rate) *
audio.info.channels)
print("Time: " + format_time(audio.info.length) +
"\tMPEG-4 Part 14 Audio" +
"\t[ " + bit_rate_str(bit_rate / 1000) +
" @ " + str(audio.info.sample_rate) + " Hz - " +
channel_str(audio.info.channels) + " ]")
print("-" * 79)
print(Fore.YELLOW + "Writing Apple iTunes metadata - " +
str(audio.info.codec) + Fore.RESET)
print("-" * 79)
except id3.error:
print(Fore.YELLOW + "Warning: exception while saving id3 tag: " +
str(id3.error) + Fore.RESET)
artworks = media_file.mg_file.tags.getall("APIC")
return self.ArtworkList(self.make_artwork(a) for a in artworks)
def __set__(self, media_file, artwork):
apic = ID3.APIC(data=artwork.data, mime=artwork.mime)
media_file.mg_file["APIC"] = apic
class MediaFile(object):
"""
Representation of a media file with it's assorted meta data
"""
artist = TextField(ID3.TPE1)
title = TextField(ID3.TIT2)
album = TextField(ID3.TALB)
remixer = TextField(ID3.TPE4)
publisher = TextField(ID3.TPUB)
release = TextField(ID3.COMM)
bpm = TextField(ID3.TBPM)
key = TextField(ID3.TKEY)
year = TextField(ID3.TDRC)
genre = TextField(ID3.TCON)
track = SizeField(ID3.TRCK)
disc = SizeField(ID3.TPOS)
artwork = ArtworkField()
def __init__(self, filename):
self.file_path = os.path.realpath(filename)
self.reload()