pytube / pytube

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
https://pytube.io
The Unlicense
12.1k stars 2.5k forks source link

ValueError: too many values to unpack (expected 2) #695

Closed 7a35090f closed 4 years ago

7a35090f commented 4 years ago

Ran into this error in my main file i was using.

So i made the most basic version i could and still got that error. Running in python 3.8 64 bit

from pytube import YouTube yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw')

Error thrown: Traceback (most recent call last): File "c:\Users\user\Documents\My scripting projects\yt download testr\test.py", line 4, in <module> yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw') File "C:\Python38\lib\site-packages\pytube\__main__.py", line 92, in __init__ self.descramble() File "C:\Python38\lib\site-packages\pytube\__main__.py", line 140, in descramble apply_signature(self.player_config_args, fmt, self.js) File "C:\Python38\lib\site-packages\pytube\extract.py", line 225, in apply_signature cipher = Cipher(js=js) File "C:\Python38\lib\site-packages\pytube\cipher.py", line 31, in __init__ var, _ = self.transform_plan[0].split(".") ValueError: too many values to unpack (expected 2)

Is it just me or are you guys getting this error also?

Mattia249 commented 4 years ago

no, i'm getting the same error

7a35090f commented 4 years ago

Did you use "pip install pytube" or "pip install pytube3" ? if it's the first then uninstall it then install the latter

pytube 3.

pytube alone gave me other errors which can be seen in #672

drwjf commented 4 years ago

Videos that require to extract js player broken

Traceback (most recent call last): File "pytube/main.py", line 92, in init self.descramble() File "pytube/main.py", line 136, in descramble apply_signature(self.player_config_args, fmt, self.js) File "pytube/extract.py", line 225, in applysignature cipher = Cipher(js=js) File "pytube/cipher.py", line 32, in init var, = self.transform_plan[0].split(".") ValueError: too many values to unpack (expected 2)

check the value of js in Cipher/init_ class Cipher: def init(self, js: str):

It is changed to:

['var b=[-1215677809,null,-1744521562,833462946,694270393,function(c,d){d=(d%c', 'length+c', 'length)%c', 'length']

no more:

['DE.AJ(a,15)', 'DE.VR(a,3)', 'DE.AJ(a,51)', 'DE.VR(a,3)', 'DE.kT(a,51)', 'DE.kT(a,8)', 'DE.VR(a,3)', 'DE.kT(a,21)']

7a35090f commented 4 years ago

Videos that require to extract js player broken

Traceback (most recent call last): File "pytube/main.py", line 92, in init self.descramble() File "pytube/main.py", line 136, in descramble apply_signature(self.player_config_args, fmt, self.js) File "pytube/extract.py", line 225, in applysignature cipher = Cipher(js=js) File "pytube/cipher.py", line 32, in init var, = self.transform_plan[0].split(".") ValueError: too many values to unpack (expected 2)

check the value of js in Cipher/init_ class Cipher: def init(self, js: str):

It is changed to:

['var b=[-1215677809,null,-1744521562,833462946,694270393,function(c,d){d=(d%c', 'length+c', 'length)%c', 'length']

no more:

['DE.AJ(a,15)', 'DE.VR(a,3)', 'DE.AJ(a,51)', 'DE.VR(a,3)', 'DE.kT(a,51)', 'DE.kT(a,8)', 'DE.VR(a,3)', 'DE.kT(a,21)']

Can you elaborate further?

BANANAPEEL202 commented 4 years ago

i've been getting the same problem. It's weird cause I didn't have this problem earlier today...

7a35090f commented 4 years ago

i've been getting the same problem. It's weird cause I didn't have this problem earlier today...

Yea exactly the same for me. Youtube changed something, now we need the fix for the code.

redplant0 commented 4 years ago

I'm also getting the same problem.

murdak commented 4 years ago

i have the same problem as well. pytube3==9.6.4 python3.7.6

zuntah commented 4 years ago

Same problem here

RONNCC commented 4 years ago

@ZippyDoodah123 would appreciate a PR (and I can merge ๐Ÿ˜‰ ) to fix this issue

zuntah commented 4 years ago

Youtube probably changed something. I tried to change this line (cipher.py line 31): var, _ = self.transform_plan[0].split(".")

To this: var = self.transform_plan[0].split(".")[0]

But now getting this error:

  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 140, in descramble
    apply_signature(self.player_config_args, fmt, self.js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/extract.py", line 225, in apply_signature
    cipher = Cipher(js=js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 33, in __init__
    self.transform_map = get_transform_map(js, var)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 198, in get_transform_map
    transform_object = get_transform_object(js, var)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 180, in get_transform_object
    raise RegexMatchError(caller="get_transform_object", pattern=pattern)
pytube.exceptions.RegexMatchError: get_transform_object: could not find match for var var\ b=\[\-1215677809,null,\-1744521562,833462946,694270393,function\(c,d\)\{d=\(d%c={(.*?)};
light42 commented 4 years ago

Welp, doesn't need to take a full week to have another cipher problem. :(

RONNCC commented 4 years ago

@light42 sorry about the frustration - is there something I can do to help

light42 commented 4 years ago

@RONNCC I'm cool, just give me good alternatives to scrap youtube videos while this issue is being resolved.

zuntah commented 4 years ago

you can use youtube-dl maenwhile ๐Ÿคจ

zuntah commented 4 years ago

I use this workaround until bug is fixed:


import os

def download_video(self, video_id):
        url = "https://www.youtube.com/watch?v={}".format(video_id)
        os.system('youtube-dl "{}" --no-check-certificate'.format(url))

You need to install Youtube-DL for that

light42 commented 4 years ago

@zuntah thank you.

Vino2530 commented 4 years ago

Facing the same error from today morning.(28.07.2020) "ValueError: too many values to unpack (expected 2)"

jimmyxp01 commented 4 years ago

Ran into this error in my main file i was using.

So i made the most basic version i could and still got that error. Running in python 3.8 64 bit

from pytube import YouTube yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw')

Error thrown: Traceback (most recent call last): File "c:\Users\user\Documents\My scripting projects\yt download testr\test.py", line 4, in <module> yt = YouTube('https://www.youtube.com/watch?v=jNQXAC9IVRw') File "C:\Python38\lib\site-packages\pytube\__main__.py", line 92, in __init__ self.descramble() File "C:\Python38\lib\site-packages\pytube\__main__.py", line 140, in descramble apply_signature(self.player_config_args, fmt, self.js) File "C:\Python38\lib\site-packages\pytube\extract.py", line 225, in apply_signature cipher = Cipher(js=js) File "C:\Python38\lib\site-packages\pytube\cipher.py", line 31, in __init__ var, _ = self.transform_plan[0].split(".") ValueError: too many values to unpack (expected 2)

Is it just me or are you guys getting this error also?

Yes I'm facing same problem today. My program run 20 hour's ago perfectly but now its showing me this problem

belthaZornv commented 4 years ago

The problem is most probably youtube changed the js file and the regular expressions are no longer working:

pytube.cipher.get_initial_function_name

I don't have time to fix this, hopefully someone can pick it up.

belthaZornv commented 4 years ago

PR Open: https://github.com/nficano/pytube/pull/701

7a35090f commented 4 years ago

701 Works for me, does it work for everyone else?

Great fix @belthaZornv !

raphi59 commented 4 years ago

the fix doesnt work for me :/

7a35090f commented 4 years ago

the fix doesnt work for me :/

Are you using pytube or pytube3?

raphi59 commented 4 years ago

pytube3 python 3.7 ubuntu 18.04

ruchou commented 4 years ago

I have the same issue starting today on my telegram chatbot

7a35090f commented 4 years ago

Weird since #701 fixed it for me.

Hmm. I suggest using youtube-dl anyway it can do everything pytube can and more. Try it til theres a fix that works for you!

partriv commented 4 years ago

having the same error in pytube3. Tried manually applying this fix into pytube3, and didn't work, got a cipher error. Maybe I was doing it wrong?

raphi59 commented 4 years ago

Will give it a try, thanks

Karachristou commented 4 years ago

@partriv I had trouble getting it to work too, what worked at the end was uninstalling, pytube3, installing pytubeX and replacing ALL the function patterns (not just the one changed) in cipher.py with the ones in #701 and obviously changing from extract.py in the line 301 the key from "cipher" to "signatureCipher"

Hope this helps ๐Ÿ‘

wuhen365 commented 4 years ago

PR Open: #701

thank you very much, i can down the youtube video now

light42 commented 4 years ago

@partriv

You can try to directly install the pull request version.

pip install git+https://github.com/nficano/pytube.git@refs/pull/701/head

512DuncanL commented 4 years ago

ran pip install git+https://github.com/nficano/pytube.git@refs/pull/701/head, still getting error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    video = YouTube("https://www.youtube.com/watch?v=3FSmZQ3LwG0")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 140, in descramble
    apply_signature(self.player_config_args, fmt, self.js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/extract.py", line 225, in apply_signature
    cipher = Cipher(js=js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 31, in __init__
    var, _ = self.transform_plan[0].split(".")
ValueError: too many values to unpack (expected 2)
BANANAPEEL202 commented 4 years ago

ran pip install git+https://github.com/nficano/pytube.git@refs/pull/701/head, still getting error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    video = YouTube("https://www.youtube.com/watch?v=3FSmZQ3LwG0")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 140, in descramble
    apply_signature(self.player_config_args, fmt, self.js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/extract.py", line 225, in apply_signature
    cipher = Cipher(js=js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 31, in __init__
    var, _ = self.transform_plan[0].split(".")
ValueError: too many values to unpack (expected 2)

for me, I had to uninstall pytube3 and then only ran: pip install git+https://github.com/nficano/pytube.git@refs/pull/701/h

light42 commented 4 years ago

ran pip install git+https://github.com/nficano/pytube.git@refs/pull/701/head, still getting error:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    video = YouTube("https://www.youtube.com/watch?v=3FSmZQ3LwG0")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
    self.descramble()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 140, in descramble
    apply_signature(self.player_config_args, fmt, self.js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/extract.py", line 225, in apply_signature
    cipher = Cipher(js=js)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/cipher.py", line 31, in __init__
    var, _ = self.transform_plan[0].split(".")
ValueError: too many values to unpack (expected 2)

for me, I had to uninstall pytube3 and then only ran: pip install git+https://github.com/nficano/pytube.git@refs/pull/701/h

Yeah, but this fix probably won't worked anymore now. I got this new error when trying to download video. image

belthaZornv commented 4 years ago

@light42 change key 'cipher' to 'signatureCipher' in extract.py

light42 commented 4 years ago

@light42 change key 'cipher' to 'signatureCipher' in extract.py

got it, but I think it would be better if the change is made directly on the pull request.

kbuilds commented 4 years ago

I patched and hosted this again. Looks like there was a merge conflict between this PR and #643

You can install directly from my repo like this:

pip install git+https://gitlab.com/obuilds/public/pytube@ob-v2

or add the following to your requirements.txt

git+https://gitlab.com/obuilds/public/pytube@ob-v2
RONNCC commented 4 years ago

@kbuilds if you could contribute a PR to fix this in main - I can help to get it merged ๐Ÿ˜„

RONNCC commented 4 years ago

Just merged #701 which should fix this -- please reopen if issue still persists!