Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_parser_for_filename(cls, filename, exception=False):
mapping = {
('.mp3',): ID3,
('.oga', '.ogg', '.opus'): Ogg,
('.wav',): Wave,
('.flac',): Flac,
('.wma',): Wma,
('.m4b', '.m4a', '.mp4'): MP4,
}
for fileextension, tagclass in mapping.items():
if filename.lower().endswith(fileextension):
return tagclass
if exception:
raise TinyTagException('No tag reader found to support filetype! ')
def get(cls, filename, tags=True, duration=True):
parser_class = None
size = os.path.getsize(filename)
if not size > 0:
return TinyTag(None, 0)
if cls == TinyTag:
"""choose which tag reader should be used by file extension"""
mapping = {
('.mp3',): ID3,
('.oga', '.ogg', '.opus'): Ogg,
('.wav'): Wave,
('.flac'): Flac,
}
for fileextension, tagclass in mapping.items():
if filename.lower().endswith(fileextension):
parser_class = tagclass
else:
# use class on which the method was invoked as parser
parser_class = cls
if parser_class is None:
raise LookupError('No tag reader found to support filetype! ')
with open(filename, 'rb') as af:
tag = parser_class(af, size)
tag.load(tags=tags, duration=duration)
return tag