steve-shambles-2109

Download audio of a video

Oct 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. """
  2. Python code snippets vol 35:
  3. 171-Download audio of a youtube video
  4. stevepython.wordpress.com
  5.  
  6. pip3 install youtube-dl
  7.  
  8. Also required, install ffmpeg from https://www.ffmpeg.org/
  9. On linux mint: sudo apt-get install ffmpeg
  10.  
  11. source:
  12. https://stackoverflow.com/questions/49246598/
  13. youtube-dl-get-audio-link-with-python
  14. """
  15.  
  16. import youtube_dl
  17.  
  18. # Change options if wish mp3 to wav, 192 to 320 for example.
  19. ydl_opts = {
  20.     'format': 'bestaudio/best',
  21.     'postprocessors': [{
  22.         'key': 'FFmpegExtractAudio',
  23.         'preferredcodec': 'mp3',
  24.         'preferredquality': '192',
  25.     }],
  26. }
  27. # Will download the audio file into current dir with same name as video.
  28. with youtube_dl.YoutubeDL(ydl_opts) as ydl:
  29.     ydl.download(['https://www.youtube.com/watch?v=kWZdv5pO5kg'])
  30.     # Replace youtube video address above to the one you want.
Add Comment
Please, Sign In to add comment