youtube-dl pip code example

Example 1: youtube-dl python download to specific folder

ydl_opts = {
    'format': 'bestaudio/best',
  	'outtmpl': 'e:/python/downloadedsongs/%(title)s.%(ext)s', # <--- pay attention here
    'download_archive': 'downloaded_songs.txt',
    'outtmpl': '%(title)s.%(ext)s',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
        }],
    'logger': MyLogger(),
    'progress_hooks': [my_hook],

}

Example 2: youtube-dl download audio

youtube-dl -F http://www.youtube.com/watch?v={video ID}  to get available audio
then
youtube-dl -f {number of available audio} http://www.youtube.com/watch?v={video ID}

Tags: