Move to mp3 as the default audio type
* Also adds aac as an allowed audio type, fixing a bug where I could edit those posts * To convert old audio to mp3, the following commands were used: ls *.aac | xargs -I {} bash -c 'ffmpeg -y -i {} -acodec mp3 $(echo {} | sed s/aac/mp3/)' for t in Thought.objects.filter(media__endswith=".aac"): t.file.name = f"{t.uuid}.mp3" t.save() And ditto with m4a.
This commit is contained in:
parent
292a464f11
commit
58dc4d62b0
|
@ -55,7 +55,8 @@ ALLOWED_MEDIA_TYPES = {
|
|||
"image/png": "png",
|
||||
"image/jpeg": "jpeg",
|
||||
"audio/x-m4a": "m4a",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mpegaudio/mpeg": "mp3",
|
||||
"audio/x-hx-aac-adts": "aac",
|
||||
"video/mp4": "mp4",
|
||||
"video/quicktime": "mov",
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ def post(request):
|
|||
|
||||
thought.media.name = f"{thought.uuid}.{ALLOWED_MEDIA_TYPES[media_type]}"
|
||||
|
||||
if media_type == "audio/x-m4a":
|
||||
if media_type == "audio/x-m4a" or media_type == "audio/x-hx-aac-adts":
|
||||
# This is a hack-fix because I want to be able to upload audio
|
||||
# In the future, this should be refactored to convert file types
|
||||
# using ffmpeg.js on the client side (so there are 0 security concerns)
|
||||
|
@ -142,11 +142,11 @@ def post(request):
|
|||
thought.save() # Save so that we have a file to work with
|
||||
subprocess.run(["ffmpeg",
|
||||
"-i", thought.media.path,
|
||||
"-codec:a", "aac", "-vn",
|
||||
os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.aac")
|
||||
"-codec:a", "mp3", "-vn",
|
||||
os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.mp3")
|
||||
], check=True)
|
||||
os.remove(os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.m4a")) # Remove the original file
|
||||
thought.media.name = f"{thought.uuid}.aac" # Update the file in the DB
|
||||
os.remove(os.path.join(settings.MEDIA_ROOT, thought.media.name)) # Remove the original file
|
||||
thought.media.name = f"{thought.uuid}.mp3" # Update the file in the DB
|
||||
|
||||
# We need to make sure that if we remove an image, the alt text is removed with it
|
||||
if not thought.media:
|
||||
|
|
Loading…
Reference in New Issue