mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 23:18:26 +02:00
Initial commit that merge both the front end and the API in the same repository
This commit is contained in:
commit
76f98b74dd
285 changed files with 51318 additions and 0 deletions
27
api/funkwhale_api/downloader/downloader.py
Normal file
27
api/funkwhale_api/downloader/downloader.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
import requests
|
||||
import json
|
||||
from urllib.parse import quote_plus
|
||||
import youtube_dl
|
||||
from django.conf import settings
|
||||
import glob
|
||||
|
||||
|
||||
def download(
|
||||
url,
|
||||
target_directory=settings.MEDIA_ROOT,
|
||||
name="%(id)s.%(ext)s",
|
||||
bitrate=192):
|
||||
target_path = os.path.join(target_directory, name)
|
||||
ydl_opts = {
|
||||
'quiet': True,
|
||||
'outtmpl': target_path,
|
||||
'postprocessors': [{
|
||||
'key': 'FFmpegExtractAudio',
|
||||
'preferredcodec': 'vorbis',
|
||||
}],
|
||||
}
|
||||
_downloader = youtube_dl.YoutubeDL(ydl_opts)
|
||||
info = _downloader.extract_info(url)
|
||||
info['audio_file_path'] = target_path % {'id': info['id'], 'ext': 'ogg'}
|
||||
return info
|
Loading…
Add table
Add a link
Reference in a new issue