mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Support more mime types for add_extension_based_on_mime (#2562)
* Support more mime types for add_extension_based_on_mime * Add myself to CONTRIBUTORS
This commit is contained in:
parent
df3fa5a0be
commit
14bc02b431
2 changed files with 9 additions and 1 deletions
|
@ -125,6 +125,7 @@ Austin Siew <github.com/Aquafina-water-bottle>
|
|||
Joel Koen <mail@joelkoen.com>
|
||||
Christopher Woggon <christopher.woggon@gmail.com>
|
||||
Kavel Rao <github.com/kavelrao>
|
||||
Ben Yip <github.com/bennyyip>
|
||||
|
||||
********************
|
||||
|
||||
|
|
|
@ -101,14 +101,21 @@ class MediaManager(DeprecatedNamesMixin):
|
|||
return self.col._backend.add_media_file(desired_name=desired_fname, data=data)
|
||||
|
||||
def add_extension_based_on_mime(self, fname: str, content_type: str) -> str:
|
||||
"If jpg or png mime, add .png/.jpg if missing extension."
|
||||
"Add extension based on mime for common audio and image format if missing extension."
|
||||
if not os.path.splitext(fname)[1]:
|
||||
# mimetypes is returning '.jpe' even after calling .init(), so we'll do
|
||||
# it manually instead
|
||||
type_map = {
|
||||
"audio/mpeg": ".mp3",
|
||||
"audio/ogg": ".oga",
|
||||
"audio/opus": ".opus",
|
||||
"audio/wav": ".wav",
|
||||
"audio/webm": ".weba",
|
||||
"audio/aac": ".aac",
|
||||
"image/jpeg": ".jpg",
|
||||
"image/png": ".png",
|
||||
"image/svg+xml": ".svg",
|
||||
"image/webp": ".webp",
|
||||
}
|
||||
if content_type in type_map:
|
||||
fname += type_map[content_type]
|
||||
|
|
Loading…
Reference in a new issue