funquail/api/funkwhale_api/downloader/downloader.py

19 lines
566 B
Python
Raw Normal View History

import os
2018-06-10 10:55:16 +02:00
import youtube_dl
from django.conf import settings
def download(
2018-06-09 15:36:16 +02:00
url, target_directory=settings.MEDIA_ROOT, name="%(id)s.%(ext)s", bitrate=192
):
target_path = os.path.join(target_directory, name)
ydl_opts = {
2018-06-09 15:36:16 +02:00
"quiet": True,
"outtmpl": target_path,
"postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "vorbis"}],
}
_downloader = youtube_dl.YoutubeDL(ydl_opts)
info = _downloader.extract_info(url)
2018-06-09 15:36:16 +02:00
info["audio_file_path"] = target_path % {"id": info["id"], "ext": "ogg"}
return info