pytube: Couldn't cipher the signature
Just today it seems Youtube changed it’s cypher coz it worked in the morning.
from pytube import YouTube yt = YouTube(“https://www.youtube.com/watch?v=7F37r50VUTQ&list=PL9NY5axt700FjL6HlEhqlMFT1gjMGVBgy&index=3”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/usr/local/lib/python2.7/dist-packages/pytube/api.py”, line 66, in init self.from_url(url) File “/usr/local/lib/python2.7/dist-packages/pytube/api.py”, line 189, in from_url signature = self._get_cipher(stream_map[“s”][i], js_url) File “/usr/local/lib/python2.7/dist-packages/pytube/api.py”, line 363, in get_cipher response = urlopen(url) File “/usr/lib/python2.7/urllib2.py”, line 154, in urlopen return opener.open(url, data, timeout) File “/usr/lib/python2.7/urllib2.py”, line 427, in open req = meth(req) File “/usr/lib/python2.7/urllib2.py”, line 1126, in do_request raise URLError(‘no host given’) urllib2.URLError: <urlopen error no host given>`
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (5 by maintainers)
Commits related to this issue
- Fixed issue #117 — committed to harindu95/pytube by harindu95 7 years ago
- Merge pull request #120 from harindu95/master Fixed issue #117 — committed to pytube/pytube by nficano 7 years ago
There’s an easy fix for that. I took it from https://github.com/rg3/youtube-dl/pull/11892/files (youtube-dl project had this problem too).
Fix in pytube will be like that (I’ll try to upload a pull request by today): In api.py file you should change 2 code lines. First, under the function _get_cipher you should change the line:
reg_exp = re.compile(r'\.sig\|\|([a-zA-Z0-9$]+)\(')
to:reg_exp = re.compile(r'"signature",\s?([a-zA-Z0-9$]+)\(')
Second, under the function from_url you should change this line:js_url = "http:" + video_data.get("assets", {}).get("js")
to this code:js_url = '' js_partial_url = video_data.get("assets", {}).get("js") if js_partial_url.startswith('//'): js_url = 'http:' + js_partial_url elif js_partial_url.startswith('/'): js_url = 'https://youtube.com' + js_partial_url
Worked for me, hope it’ll be helpful.
thank you @nficano and @rotemvilsa. pytube does a great job conserving electrons.