Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't cipher the signature #117

Closed
harindu95 opened this issue Jan 31, 2017 · 20 comments
Closed

Couldn't cipher the signature #117

harindu95 opened this issue Jan 31, 2017 · 20 comments

Comments

@harindu95
Copy link
Contributor

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 "", line 1, in
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: `

@rotemvilsa
Copy link

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.

@harindu95
Copy link
Contributor Author

Yeah. It worked. Thanks 👍

@imsonujangra
Copy link

After changing api.py file it gives me :
Traceback (most recent call last):
File "/usr/local/bin/pytube", line 7, in
from pytube.main import main
File "/usr/local/lib/python3.5/dist-packages/pytube/init.py", line 10, in
from .api import YouTube
File "/usr/local/lib/python3.5/dist-packages/pytube/api.py", line 190
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
^
SyntaxError: invalid syntax

@palashgoel7
Copy link
Contributor

palashgoel7 commented Feb 3, 2017 via email

@imsonujangra
Copy link

Can you show me the exact code how does it look .
js_url = '' js_partial_url = .....

@harindu95
Copy link
Contributor Author

It is
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

@harindu95
Copy link
Contributor Author

Urgh. Indentation is shot to hell. Someone should just submit a pull request.

@imsonujangra
Copy link

Yes agree with @harindu95 . please submit a pull request .

Traceback (most recent call last):
File "/usr/local/bin/pytube", line 7, in
from pytube.main import main
File "/usr/local/lib/python3.5/dist-packages/pytube/init.py", line 10, in
from .api import YouTube
File "/usr/local/lib/python3.5/dist-packages/pytube/api.py", line 190
js_url = ' '
^
TabError: inconsistent use of tabs and spaces in indentation

harindu95 added a commit to harindu95/pytube that referenced this issue Feb 4, 2017
@harindu95
Copy link
Contributor Author

Ok. @rotemvilsa I submitted a pull request #120

@peterrenshaw
Copy link

@rotemvilsa hack works. ps: watch out for the code formatting

nficano added a commit that referenced this issue Feb 6, 2017
@nficano
Copy link
Collaborator

nficano commented Feb 7, 2017

Thanks for your help folks! Accepted PR and released to Pypi.

@nficano nficano closed this as completed Feb 7, 2017
@peterrenshaw
Copy link

thank you @nficano and @rotemvilsa. pytube does a great job conserving electrons.

@jasonab
Copy link

jasonab commented Feb 8, 2017

My pip is not picking up the new version in Pypi, and the documentation on the site does not appear correct: https://pypi.python.org/pypi/pytube/6.2.1

Note that the markup isn't parsed, and the platform and classifier data at the bottom is in the text, not parsed properly. So, I'm not sure what exactly is wrong, but I don't think it was installed properly.

On further glance, it appears it's only installed for py2, and not py3, which is likely why I can't see it.

@nficano
Copy link
Collaborator

nficano commented Feb 8, 2017

I cannot reproduce this, seems to be working for me:

nficano at dinkins ~/ pip3 search pytube
pytube (6.2.1)  - A Python library for downloading YouTube videos.
nficano at dinkins ~/ pip search pytube
pytube (6.2.1)  - A Python library for downloading YouTube videos.

@jasonab
Copy link

jasonab commented Feb 8, 2017

I have the same result with your commands, but here is what I get when I try to install:
Collecting pytube==6.2.1 (from -r requirements.txt (line 11))
Could not find a version that satisfies the requirement pytube==6.2.1 (from -r requirements.txt (line 11)) (from versions: 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.3.3, 0.4.1, 0.4.2, 5.1.0, 6.0.0, 6.0.1, 6.0.2, 6.1.0, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.8, 6.1.10, 6.1.11)
No matching distribution found for pytube==6.2.1 (from -r requirements.txt (line 11))

@jasonab
Copy link

jasonab commented Feb 8, 2017

Here's some more context:
pip search pytube
pytube (6.2.1) - A Python library for downloading YouTube videos.
INSTALLED: 6.1.11
LATEST: 6.2.1

pip3 search pytube
pytube (6.2.1) - A Python library for downloading YouTube videos.
INSTALLED: 6.1.11
LATEST: 6.2.1

pip install --upgrade pytube
Requirement already up-to-date: pytube in ./venv/lib/python3.5/site-packages

@nficano
Copy link
Collaborator

nficano commented Feb 8, 2017

Ok, I was able to repro, looking into it now

@nficano
Copy link
Collaborator

nficano commented Feb 8, 2017

All fixed! Updated release to 6.2.2.

@jasonab
Copy link

jasonab commented Feb 8, 2017

That came through just fine, thanks very much.

@nficano
Copy link
Collaborator

nficano commented Feb 8, 2017

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants