mps-youtube / pafy

Python library to download YouTube content and retrieve metadata
1.39k stars 313 forks source link

ValueError: unknown url type: '/yts/jsbin/player-fi_FI-vfl4yvaaM/base.js' #166

Open akifd opened 7 years ago

akifd commented 7 years ago

Most of the times when I try to fetch a video I get this error:

Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pafy
WARNING:root:pafy: youtube-dl not found; falling back to internal backend. This is not as well maintained as the youtube-dl backend. To hide this message, set the environmental variable PAFY_BACKEND to "internal".
>>> video = pafy.new("https://www.youtube.com/watch?v=e7gB2aLGdcE")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pafy/pafy.py", line 122, in new
    return Pafy(url, basic, gdata, size, callback, ydl_opts)
  File "/usr/local/lib/python3.5/dist-packages/pafy/backend_internal.py", line 42, in __init__
    super(InternPafy, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pafy/backend_shared.py", line 96, in __init__
    self._fetch_basic()
  File "/usr/local/lib/python3.5/dist-packages/pafy/backend_internal.py", line 92, in _fetch_basic
    smaps, js_url, mainfunc = get_js_sm(watchinfo, self.callback)
  File "/usr/local/lib/python3.5/dist-packages/pafy/backend_internal.py", line 430, in get_js_sm
    dbg_ref="javascript", file_prefix="js-")
  File "/usr/local/lib/python3.5/dist-packages/pafy/backend_internal.py", line 367, in fetch_cached
    data = fetch_decode(url, "utf8")  # unicode
  File "/usr/local/lib/python3.5/dist-packages/pafy/pafy.py", line 65, in fetch_decode
    req = g.opener.open(url)
  File "/usr/lib/python3.5/urllib/request.py", line 451, in open
    req = Request(fullurl, data)
  File "/usr/lib/python3.5/urllib/request.py", line 269, in __init__
    self.full_url = url
  File "/usr/lib/python3.5/urllib/request.py", line 295, in full_url
    self._parse()
  File "/usr/lib/python3.5/urllib/request.py", line 324, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '/yts/jsbin/player-fi_FI-vfl4yvaaM/base.js'

I tried setting my own API key, but that didn't help either. Occasionally it seems to work but most of the time it doesn't. I can't pin down why it's so random.

I also tried the following but these raised the same error:

pafy.new("http://www.youtube.com/watch?v=e7gB2aLGdcE")
pafy.new("e7gB2aLGdcE")
ids1024 commented 7 years ago

See the error message: WARNING:root:pafy: youtube-dl not found; falling back to internal backend. This is not as well maintained as the youtube-dl backend. To hide this message, set the environmental variable PAFY_BACKEND to "internal".

Install youtube-dl. Since pafy calls it as as a library, you also need a version of youtube-dl matching the Python version.

hipoglucido commented 7 years ago

For me what it worked was to uninstall both pafy and youtube-dl, and then reinstall them, first youtube-dl and after pafy

TwoLeaves commented 7 years ago

Installing youtube-dl is a good workaround for most situations, but the actual problem still lies in the internal youtube URL resolver in pafy. The issue and fix are described in this youtube-dl issue: (https://github.com/rg3/youtube-dl/issues/11894). It would be nice if the internal resolver was working, as I find it faster than youtube-dl for my needs (mopidy-youtube on a low-powered single board computer).

TwoLeaves commented 7 years ago

It is likely beyond me to port the youtube-dl fix to pafy but if this bug is still around in the not-too-distant future I will have a look.

ids1024 commented 7 years ago

the actual problem still lies in the internal youtube URL resolver in pafy

Indeed, but as you can see it breaks often and is not always easy to fix. PRs are welcome, of course. Help maintaining that code would be appreciated, since it is in fact helpful for low powered hardware, at least.