3

Here's the code:

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

I pretty much copied this from download only audio from youtube video using youtube-dl in python script. The error that is coming up is:

AttributeError: module 'youtube_dl' has no attribute 'YoutubeDL'

I did lots of research but is seems youtube_dl is a pretty uncommon module. Essentially, it can get a ton of data off of youtube. The code I had was supposed to successfully grab audio from a youtube link of my desire. However, that same error always comes up. I ran it on python 2.7.13 and 3.6.3 - the same outcome on both. It seemed to have worked for otthers, and there was another thread about this here Can someone tell me what is causing the error so I can move onward with this project?

  • How did you install `youtube_dl`? What is the output of `print(youtube_dl.__file__)`? – alecxe Dec 16 '17 at 03:13
  • 1
    did you save your code in file `youtube_dl.py` ? if yes then `import ` loads your file instead expected module. Change name of your file and delete `youtube_dl.pyc` (see extension `.pyc`) and/or subfolder `__pycache__` if you have it in your folder. – furas Dec 16 '17 at 04:08
  • BTW: always put full error message (Traceback) in question (as text, not screenshot). There are other useful informations. ie. it shows your file name. – furas Dec 16 '17 at 04:12
  • 1
    Oh my... I did name my file youtube_dl.py. Thanks! – Free Crawler Dec 16 '17 at 17:04

1 Answers1

4

If you have named your file as youtube_dl.py, It will mix the programs mind. I am not seeing any problem in your code btw.

Emir Sürmen
  • 884
  • 3
  • 14
  • 33