funkwhale/api/funkwhale_api/downloader/downloader.py

20 wiersze
566 B
Python
Czysty Zwykły widok Historia

import os
2018-06-10 08:55:16 +00:00
import youtube_dl
from django.conf import settings
def download(
2018-06-09 13:36:16 +00: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 13:36:16 +00: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 13:36:16 +00:00
info["audio_file_path"] = target_path % {"id": info["id"], "ext": "ogg"}
return info