See #272: added preference and base logic for transcoding

This commit is contained in:
Eliot Berriot 2018-10-24 19:14:51 +02:00
parent baf5a350b3
commit 2fe1e7c950
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
6 changed files with 161 additions and 9 deletions

View file

@ -2,8 +2,10 @@ import mimetypes
import magic
import mutagen
import pydub
from funkwhale_api.common.search import normalize_query, get_query # noqa
from funkwhale_api.common import utils
def guess_mimetype(f):
@ -68,3 +70,10 @@ def get_actor_from_request(request):
actor = request.user.actor
return actor
def transcode_file(input, output, input_format, output_format, **kwargs):
with input.open("rb"):
audio = pydub.AudioSegment.from_file(input, format=input_format)
with output.open("wb"):
return audio.export(output, format=output_format, **kwargs)