home
clear breadcrumbs
search
login
 
youtube_dl module
https://github.com/ytdl-org/youtube-dl/blob/3e4cedf9e8cd3157df2457df7274d0c842421945/youtube_dl/YoutubeDL.py#L137-L312 import subprocess import youtube_dl import os os.system('clear') def run(video_url): # video to download # video_url = video_url # Download and convert to mp3 and store in downloads folder video_info = youtube_dl.YoutubeDL().extract_info( url=video_url, download=False) video_title = video_info['title'] filename = f"{video_title}.mp3" # save file in current working directory cwd where_to_save = os.getcwd() filename = f"{video_info['title']}.mp3" output_path = os.path.join(where_to_save, filename) options = { # reduces the several line of output to barest minimal and therefore, time 'quiet': True, 'noplaylist': True, 'format': 'bestaudio/best', 'keepvideo': False, 'outtmpl': output_path, 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }] } with youtube_dl.YoutubeDL(options) as ydl: ydl.download([video_info['webpage_url']]) run('https://youtu.be/c1eoBnlqeGg')