Installation (Python 3.6.9, pytube3-9.6.4):
pip3 uninstall -y pytube3
pip3 install git+https://github.com/nficano/pytube
python3
Test:
from pytube import YouTube
YouTube('https://www.youtube.com/watch?v=5YceQ8YqYMc')
Output including the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".local/lib/python3.6/site-packages/pytube/__main__.py", line 91, in __init__
self.prefetch()
File ".local/lib/python3.6/site-packages/pytube/__main__.py", line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File ".local/lib/python3.6/site-packages/pytube/extract.py", line 143, in js_url
base_js = get_ytplayer_config(html)["assets"]["js"]
File ".local/lib/python3.6/site-packages/pytube/extract.py", line 202, in get_ytplayer_config
raise RegexMatchError(caller="get_ytplayer_config", pattern="config_patterns")
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns```
Is this maybe the case, because there is nothing to watch on this url? If I visit the url it states: This live stream recording is not available.. There should be another exception tho.
Yes, right. This fault appears to be related to missing live video feed
You can get that error if the video is private.
Is there any solution to this question?
I have the same issue. I guess that a new regular expression should be include in the list config_patterns of the method get_ytplayer_config, in extract.py module (line 185).
def get_ytplayer_config(html: str) -> Any:
"""Get the YouTube player configuration data from the watch html.
Extract the ``ytplayer_config``, which is json data embedded within the
watch html and serves as the primary source of obtaining the stream
manifest data.
:param str html:
The html contents of the watch page.
:rtype: str
:returns:
Substring of the html containing the encoded manifest data.
"""
config_patterns = [
r";ytplayer\.config\s*=\s*({.*?});",
r";ytplayer\.config\s*=\s*({.+?});ytplayer",
r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})}\);",
r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})(,'EXPERIMENT_FLAGS'|;)", # noqa: E501
]
.....
I get this error when I tried to download videos which should be verified.
For example, a portion of the input parameter html looks like:
_yt.setConfig({'EVENT_ID': "lEBNX6PiGJPuwAT1zJSwCQ",'VIDEO_ID': "wuDcndAWRR0",'POST_MESSAGE_ORIGIN': "*",'XSRF_TOKEN': 'QUFFLUhqblRFMG5zSXRVREtSY1lCaUoyWmdZZWMtSW9fd3xBQ3Jtc0trUnJFaG5VN2x6SHlNVmg0QjZycU56XzVkQlRWNm85S0ZVdkhJRFQxQ2IyamY4VkRpanRvc2Mza0U1QmV1MVNqNFpFT1lVN3V2Ynp5MV91MjgyRHN1UlpMbExMMFN6SWRHT0ZzMm8wZ19mQWhXWEU5cXdMSS1DdHhZdEFwb3JONFRVYXZjaEpFelFHbGN2eWpiTVNxQ3B4NEZjQWc=','XSRF_FIELD_NAME': 'session_token','INNERTUBE_CONTEXT': {"client":{"hl":"es-419","gl":"AR","visitorData":"CgtLM05kXzQ4NWdCbyiUgbX6BQ%3D%3D","userAgent":"Mozilla/5.0,gzip(gfe)","clientName":"WEB_EMBEDDED_PLAYER","clientVersion":"20200827"},"request":{"sessionId":"6867216011288531711"}},'PLAYER_CONFIG': {"attrs":{"width":"100%","height":"100%","id":"video-player"},"assets":{"js":"/s/player/54d6fa95/player_ias.vflset/es_MX/base.js","css":"/s/player/54d6fa95/www-player.css","player_canary_state":"none"}_
I have the same issue. I guess that a new regular expression should be include in the list config_patterns of the method get_ytplayer_config, in extract.py module (line 185).
def get_ytplayer_config(html: str) -> Any: """Get the YouTube player configuration data from the watch html. Extract the ``ytplayer_config``, which is json data embedded within the watch html and serves as the primary source of obtaining the stream manifest data. :param str html: The html contents of the watch page. :rtype: str :returns: Substring of the html containing the encoded manifest data. """ config_patterns = [ r";ytplayer\.config\s*=\s*({.*?});", r";ytplayer\.config\s*=\s*({.+?});ytplayer", r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})}\);", r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})(,'EXPERIMENT_FLAGS'|;)", # noqa: E501 ] .....I get this error when I tried to download videos which should be verified.
For example, a portion of the input parameter html looks like:
_yt.setConfig({'EVENT_ID': "lEBNX6PiGJPuwAT1zJSwCQ",'VIDEO_ID': "wuDcndAWRR0",'POST_MESSAGE_ORIGIN': "*",'XSRF_TOKEN': 'QUFFLUhqblRFMG5zSXRVREtSY1lCaUoyWmdZZWMtSW9fd3xBQ3Jtc0trUnJFaG5VN2x6SHlNVmg0QjZycU56XzVkQlRWNm85S0ZVdkhJRFQxQ2IyamY4VkRpanRvc2Mza0U1QmV1MVNqNFpFT1lVN3V2Ynp5MV91MjgyRHN1UlpMbExMMFN6SWRHT0ZzMm8wZ19mQWhXWEU5cXdMSS1DdHhZdEFwb3JONFRVYXZjaEpFelFHbGN2eWpiTVNxQ3B4NEZjQWc=','XSRF_FIELD_NAME': 'session_token','INNERTUBE_CONTEXT': {"client":{"hl":"es-419","gl":"AR","visitorData":"CgtLM05kXzQ4NWdCbyiUgbX6BQ%3D%3D","userAgent":"Mozilla/5.0,gzip(gfe)","clientName":"WEB_EMBEDDED_PLAYER","clientVersion":"20200827"},"request":{"sessionId":"6867216011288531711"}},'PLAYER_CONFIG': {"attrs":{"width":"100%","height":"100%","id":"video-player"},"assets":{"js":"/s/player/54d6fa95/player_ias.vflset/es_MX/base.js","css":"/s/player/54d6fa95/www-player.css","player_canary_state":"none"}_
ytplayer_config which works:
@jihuun YouTube videos can be marked as "private", which means they cannot be watched unless the person who posted the video directly shares the video with specific users. These are commonly used by companies for things like training videos that they want only their employees to be able to see.
pytube now raises specific exceptions for unavailable videos, so I believe that resolves this issue
I'm afraid the issue in this test is not solved yet.
@Ircama pytube is correctly raising a RecordingUnavailable exception when I run that test, did you make sure to reinstall pytube with python3 -m pip install git+https://github.com/nficano/pytube.git?
@tfdahlin yes, I double checked the issue with different Python versions and I also used a clean Ubuntu 20.04 LTS with Python3.8. Result is similar to the above mentioned test, but not the same:
>>> from pytube import YouTube
>>> YouTube('https://www.youtube.com/watch?v=5YceQ8YqYMc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../.local/lib/python3.8/site-packages/pytube/__main__.py", line 103, in __init__
self.prefetch()
File ".../.local/lib/python3.8/site-packages/pytube/__main__.py", line 192, in prefetch
self.js_url = extract.js_url(self.watch_html)
File ".../.local/lib/python3.8/site-packages/pytube/extract.py", line 178, in js_url
base_js = get_ytplayer_config(html)['assets']['js']
File ".../.local/lib/python3.8/site-packages/pytube/extract.py", line 277, in get_ytplayer_config
raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns, setconfig_patterns
@Ircama actually, I just had a thought about why that might be happening. I think this may be related to something that is being added in https://github.com/nficano/pytube/pull/683.
Your github profile says that you're located in Italy, and I suspect that the page is being loaded in Italian, which means that the regex matches for checking if a video is unavailable aren't finding the correct string.
Can you edit your copy of request.py and edit this line to be base_headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"} instead of base_headers = {"User-Agent": "Mozilla/5.0"} and see if that fixes the problem?
If you need help finding the filepath, you should be able to run the following to find the correct directory:
import os, pytube; print(os.path.dirname(pytube.__file__))
@tfdahlin thanks a lot, your consideration is correct and your suggestion fixes the problem!
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytube import YouTube
>>> YouTube('https://www.youtube.com/watch?v=5YceQ8YqYMc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../.local/lib/python3.6/site-packages/pytube/__main__.py", line 103, in __init__
self.prefetch()
File ".../.local/lib/python3.6/site-packages/pytube/__main__.py", line 177, in prefetch
raise RecordingUnavailable(video_id=self.video_id)
pytube.exceptions.RecordingUnavailable: 5YceQ8YqYMc does not have a live stream recording available
>>>
Cool! That fix will hopefully be added to the actual pytube repository pretty soon, sorry that took so long to figure out!
Quick update on this: the PR that fixes the language issue is ready to go, just waiting on approval before merging it
Last update: PR with the accept-language header change got merged into the main repo
Hey, I got the same problem while using the new version
I have tried downloading a blocked video from my channel.
Hey, I got the same problem while using the new version
I have tried downloading a blocked video from my channel.
Providing the YouTube url you used would be helpful triaging the issue.
updated the request.py file, problem still remains.
the pytube version 10.1.0 solves the problem.
It still does not work for me although I updated pytube to 10.1.0. The error
get_ytplayer_config: could not find match for config_patterns, setconfig_patterns
still appears on the line
youtube = pytube.YouTube(video_url)
@P51KjMustang what's the video url you're trying to download?
I also get still get the error, even with updated headers (Am from Germany). I print them to the console see Output below:
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=Z5oS8TNI8fI')
Output
{'User-Agent': 'Mozilla/5.0', 'accept-language': 'en-US,en'}
{'User-Agent': 'Mozilla/5.0', 'accept-language': 'en-US,en'}
---------------------------------------------------------------------------
RegexMatchError Traceback (most recent call last)
<ipython-input-2-c2cbc02076c0> in <module>
----> 1 yt = YouTube('https://www.youtube.com/watch?v=Z5oS8TNI8fI')
~\Anaconda3\lib\site-packages\pytube\__main__.py in __init__(self, url, defer_prefetch_init, on_progress_callback, on_complete_callback, proxies)
89
90 if not defer_prefetch_init:
---> 91 self.prefetch()
92 self.descramble()
93
~\Anaconda3\lib\site-packages\pytube\__main__.py in prefetch(self)
181 self.vid_info_raw = request.get(self.vid_info_url)
182 if not self.age_restricted:
--> 183 self.js_url = extract.js_url(self.watch_html)
184 self.js = request.get(self.js_url)
185
~\Anaconda3\lib\site-packages\pytube\extract.py in js_url(html)
141 The html contents of the watch page.
142 """
--> 143 base_js = get_ytplayer_config(html)["assets"]["js"]
144 return "https://youtube.com" + base_js
145
~\Anaconda3\lib\site-packages\pytube\extract.py in get_ytplayer_config(html)
200 return json.loads(yt_player_config)
201
--> 202 raise RegexMatchError(caller="get_ytplayer_config", pattern="config_patterns")
203
204
RegexMatchError: get_ytplayer_config: could not find match for config_patterns
my request.py
...
def _execute_request(
url: str, method: Optional[str] = None, headers: Optional[Dict[str, str]] = None
) -> HTTPResponse:
base_headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"}
print(base_headers)
if headers:
base_headers.update(headers)
print(base_headers)
if url.lower().startswith("http"):
request = Request(url, headers=base_headers, method=method)
else:
raise ValueError("Invalid URL")
return urlopen(request) # nosec
...
Here is the HTML script (I receive) of the video request https://controlc.com/7db22704 .
The regex patterns in extract.py indeed don't exist if you search for them
config_patterns = [
r";ytplayer\.config\s*=\s*({.*?});",
r";ytplayer\.config\s*=\s*({.+?});ytplayer",
r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})}\);",
r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})(,'EXPERIMENT_FLAGS'|;)", # noqa: E501
]
I am generally unable to find anything about the actual video in the script.
hi @Ferdodonna it looks like you're using a very old version of pytube based on the traceback you're getting. Please run the following to uninstall pytube, and then reinstall from the source code:
python -m pip uninstall pytube pytube3 pytubex
python -m pip install git+https://github.com/nficano/pytube
Oh I assumed "pip install" would have the latest version available. Thank you now it works fine!
@Ferdodonna pip install --upgrade <package> may also help in the future 馃槂
It works for me.
pip install pytube==10.4.1
I deleted "pytuebe" and "pytube3" folders in this location:
C:\Users\xxx\AppData\Local\Programs\Python\Python39\Lib\site-packages
and I installed it again with pip and somehow it works!
Most helpful comment
@Ircama actually, I just had a thought about why that might be happening. I think this may be related to something that is being added in https://github.com/nficano/pytube/pull/683.
Your github profile says that you're located in Italy, and I suspect that the page is being loaded in Italian, which means that the regex matches for checking if a video is unavailable aren't finding the correct string.
Can you edit your copy of
request.pyand edit this line to bebase_headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"}instead ofbase_headers = {"User-Agent": "Mozilla/5.0"}and see if that fixes the problem?If you need help finding the filepath, you should be able to run the following to find the correct directory:
import os, pytube; print(os.path.dirname(pytube.__file__))