Search code examples
pythonyoutubepafy

Pafy Youtube URL Error


I am trying Pafy library but seem to have encountered a problem. This is my code:

a = pafy.new("http://www.youtube.com/watch?v=W2AF8jH84o0")

And this is the error I am getting:

https://i.sstatic.net/NRKZg.png


Solution

  • Youtube-DL must be downloaded as well since Pafy uses it as a dependancy.

    You can use Pip: sudo -H pip install --upgrade youtube-dl

    On a Mac, you can download it using homebrew instead: brew install youtube-dl

    On Unix like machines (Mac, Linux), you can use curl:

    sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
    
    sudo chmod a+rx /usr/local/bin/youtube-dl
    

    If Youtube-DL isn't found on your machine, Pafy usually falls back to it's internal mechanisms, which are "not as well mantained." If you really can't download Youtube-DL, you can try to use Pafy's own internal backend (not recommended) by adding the line:

    pafy.BACK_END = "internal"

    The recommended method is Youtube-DL