PK!]Zа artworks.pyimport mutagen import mutagen.mp3 import mutagen.mp4 import mutagen.id3 import mutagen.easyid3 import mutagen.easymp4 _SUPPORTED_MUTAGEN_FILE_TYPES = ( mutagen.mp3.EasyMP3, mutagen.easymp4.EasyMP4, ) def _id3tags_to_artwork(id3tags, _): tag = next((pic for pic in id3tags.getall('APIC') if pic.type == mutagen.id3.PictureType.COVER_FRONT), None) if not isinstance(tag, mutagen.id3.APIC): return None return Artwork(tag.mime, tag.data) def _mp4tags_to_artwork(mp4tags, _): tag = mp4tags.get("covr", None) if not isinstance(tag, list) or len(tag) < 1: return None c = tag[0] if not isinstance(c, mutagen.mp4.MP4Cover): return None return Artwork(_mp4_cover_to_mime_type(c), bytes(c)) def _mp4_cover_to_mime_type(mp4_cover): return { mutagen.mp4.MP4Cover.FORMAT_JPEG: "image/jpeg", mutagen.mp4.MP4Cover.FORMAT_PNG: "image/png", }.get(mp4_cover.imageformat, None) def _get_mime_type(mutagen_file: mutagen.FileType): if len(mutagen_file.mime) > 0: return mutagen_file.mime[0] raise Exception("mime/type not found: " + mutagen_file.filename) mutagen.easyid3.EasyID3.RegisterKey("artwork", _id3tags_to_artwork) mutagen.easymp4.EasyMP4.RegisterKey("artwork", _mp4tags_to_artwork) class Artwork: def __init__(self, mime_type, data_bytes): self.mime_type = mime_type self.data_bytes = data_bytes def from_file(file) -> Artwork: return mutagen.File(file, easy=True).get("artwork", None) PK!vm** artworks-0.2.0.dist-info/LICENSEMIT License Copyright (c) 2019 castaneai Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUartworks-0.2.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HPÙ!artworks-0.2.0.dist-info/METADATAMO1sԄm`!4@$z ?׉];m3}]P-&,)D@{BK0/ޣ:]bPwR`-Su_-_*5 (b9``1#CREɯOv}d^pO}=ba$d` ,36MmϢ?Zˮ9:-cj=q[ɀI0qOH>R}PK!H>2martworks-0.2.0.dist-info/RECORDur0лi˜z"K0*e-K9>%4R;%2&_](zſyZFjM% ,U$KP_u|ڎYcJ1zq!IFj1wt!/@882f8w{!g7a^ɾny}v[Wo9T-PQכw --+CVQz{/ [Ae;zPK!]Zа artworks.pyPK!vm** artworks-0.2.0.dist-info/LICENSEPK!HڽTU artworks-0.2.0.dist-info/WHEELPK!HPÙ! artworks-0.2.0.dist-info/METADATAPK!H>2m3 artworks-0.2.0.dist-info/RECORDPKoe