get-pytube / pytube3

A lightweight, dependency-free Python 3 library (and command-line utility) for downloading YouTube Videos.
https://pytube3.readthedocs.io
Other
180 stars 55 forks source link

Key Error: 'cipher' #81

Open boidushya opened 4 years ago

boidushya commented 4 years ago
Traceback (most recent call last):                        File "/usr/local/lib/python3.7/site-packages/pytube/extract.py", line 297, in apply_descrambler
    for format_item in formats                            File "/usr/local/lib/python3.7/site-packages/pytube/extract.py", line 297, in <listcomp>                          for format_item in formats
KeyError: 'url'                                         
During handling of the above exception, another exception occurred:

Traceback (most recent call last):                        File "main.py", line 59, in <module>
    task()                                                File "main.py", line 52, in task
    s,t = generate()                                      File "main.py", line 30, in generate
    prUtils.dl(url)                                       File "/home/mubashir/tom/prUtils.py", line 22, in dl      pytube.YouTube(q).streams.filter(file_extension='mp4').first().download(output_path="./assets",filename="song")
  File "/usr/local/lib/python3.7/site-packages/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/usr/local/lib/python3.7/site-packages/pytube/__main__.py", line 132, in descramble
    apply_descrambler(self.player_config_args, fmt)
  File "/usr/local/lib/python3.7/site-packages/pytube/extract.py", line 301, in apply_descrambler
    parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
  File "/usr/local/lib/python3.7/site-packages/pytube/extract.py", line 301, in <listcomp>
    parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
KeyError: 'cipher'

Video URL I was using last( I used a lot of links in context to this video to check and none worked ): https://youtu.be/7jaN9B5zLzQ Not sure but might be a YouTube change thing

crd commented 4 years ago

Easy to reproduce:

>>> from pytube import YouTube
>>> YouTube('https://www.youtube.com/watch?v=fKopy74weus').streams.get_highest_resolution().download()
Traceback (most recent call last):
  File "/pytube/extract.py", line 288, in apply_descrambler
    stream_data[key] = [
  File "/pytube/extract.py", line 290, in <listcomp>
    "url": format_item["url"],
KeyError: 'url'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/pytube/__main__.py", line 132, in descramble
    apply_descrambler(self.player_config_args, fmt)
  File "/pytube/extract.py", line 300, in apply_descrambler
    cipher_url = [
  File "/pytube/extract.py", line 301, in <listcomp>
    parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
KeyError: 'cipher'
boidushya commented 4 years ago

Update: Pull request #80 fixed it for me. Seemed like it was a YouTube change after all. @hbmartin please merge the PR🙏

boidushya commented 4 years ago

pip install git+https://github.com/apdug/pytube3.git@5ac96de69f025b09abf2a6a24a4103c78b7e4c81 for the time being