1import os
2
3def download_audio(request):
4 SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
5
6 ydl_opts = {
7 'format': 'bestaudio/best',
8 'postprocessors': [{
9 'key': 'FFmpegExtractAudio',
10 'preferredcodec': 'mp3',
11 'preferredquality': '192',
12 }],
13 'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
14 }
15
16 link = request.GET.get('video_url')
17
18 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
19 ydl.download(["https://www.youtube.com/watch?v="+link])
20