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:`
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.
Yeah. It worked. Thanks :+1:
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
That is not a double quote in the beginning of the line
js_url = '' js_partial_url
​ ^​
On 2 February 2017 at 22:49, Sonu Jangra notifications@github.com wrote:
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—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nficano/pytube/issues/117#issuecomment-277021732, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AHnTHiVHG2Nt3zhKs5WiT5FUBCaiIS9kks5rYhAWgaJpZM4LyP9u
.
--
regards,
Palash Goel
Can you show me the exact code how does it look .
js_url = '' js_partial_url = .....
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
Urgh. Indentation is shot to hell. Someone should just submit a pull request.
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
Ok. @rotemvilsa I submitted a pull request https://github.com/nficano/pytube/pull/120
@rotemvilsa hack works. ps: watch out for the code formatting
Thanks for your help folks! Accepted PR and released to Pypi.
thank you @nficano and @rotemvilsa. pytube does a great job conserving electrons.
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.
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.
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))
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
Ok, I was able to repro, looking into it now
All fixed! Updated release to 6.2.2.
That came through just fine, thanks very much.
Thanks for reporting!
Most helpful comment
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_urlWorked for me, hope it'll be helpful.