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

Could not find match for config_patterns for certain urls #742

Closed
lukas4haus opened this issue Sep 18, 2020 · 11 comments · Fixed by #800 or #804
Closed

Could not find match for config_patterns for certain urls #742

lukas4haus opened this issue Sep 18, 2020 · 11 comments · Fixed by #800 or #804

Comments

@lukas4haus
Copy link

Hi,
I started using pyTube just recently and I am very happy with the functionality.
I am using it to download music tracks from YouTube Music.

In most of my tests, it worked great, but with some urls I catch an exception:

pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns

For example it occurs with this track: https://www.youtube.com/watch?v=hbFQARBbZww

I am neither good at regex, nor do I really understand what to search for in the analyzed html.
Do you maybe have a solution for this issue, or can you give me some hints about how to fix the issue myself?

Best regards,
Lukas

@github-actions
Copy link

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@sirodus
Copy link

sirodus commented Sep 23, 2020

Hi, I spent an hour on it but found a solution, specially set up an account here to share it.
In the pytube/extract.py file, add to the config_patterns list
r"'PLAYER_CONFIG':\s*({.*})});"
it's supposed to look like this
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 r"'PLAYER_CONFIG':\s*({.*})}\);", ]

@lukas4haus
Copy link
Author

Hi sirodus,
I tried both versions mentioned in your comment, but both were unsuccessful.

r"'PLAYER_CONFIG':\s*({.*})});"
r"'PLAYER_CONFIG':\s*({.*})}\);"

Could you please check if there is a typo or something in your comment if you were successful using the regex?

@TheLuctus
Copy link

Html source code:

from video that works:

<script >if (window.ytcsi) {window.ytcsi.tick("cfg", null, '');}</script> <script >var ytplayer = ytplayer || {};ytplayer.config = {"assets":{"css":"/s/player/134332d3/www-player-2x-webp.css","js":"/s/player/134332d3/player_ias.vflset/de_DE/base.js","player_canary_state":"none"},"attrs":{"id":"movie_player"},"args":{"innertube_api_version":"v1","gapi_hintparams":"m;//scs/abc-static/_/js/k=gapi.gapi.en.lqqPe8Y-aUs.O/d=1/ct=zgms/rs=AHpOoo_7ZBgzLryveB2qtYoSqeBQ4P-TYA/m=features","hl":"de_DE","show_miniplayer_button":"1","cos":"Windows","innertube_context_client_version":"2.20200910.05.00","user_display_image":"https://lh3.googleusercontent.com/a-/AOh14Gj6WnHLc1Z8PBIfU-

video that does not work:

<script >if (window.ytcsi) {window.ytcsi.tick("cfg", null, '');}</script> <script >var ytplayer = ytplayer || {};ytplayer.config = {"args":{"user_display_name":"PLURRED","watermark":",https://s.ytimg.com/yts/img/watermark/youtube_watermark-vflHX6b6E.png,https://s.ytimg.com/yts/img/watermark/youtube_hd_watermark-vflAzLcD6.png","loaderUrl":"https://www.youtube.com/watch?

One of the links has a Watermark in it's source code.

@sirodus
Copy link

sirodus commented Sep 26, 2020

Hi sirodus,
I tried both versions mentioned in your comment, but both were unsuccessful.

r"'PLAYER_CONFIG':\s*({.*})});"
r"'PLAYER_CONFIG':\s*({.*})}\);"

Could you please check if there is a typo or something in your comment if you were successful using the regex?

This is definitely correct. In your case, you may need to add other expression to the config_patterns list. Send me the link of the video you still have problems with after adding my fix.

@TheLuctus
Copy link

works for me

@lukas4haus
Copy link
Author

I am sorry, but it is still the URL from my first message which is causing me issues.

Now I realized that all the urls that are working for me are not YouTube Premium only, but available for everyone
e.g https://www.youtube.com/watch?v=UGN00k2bHgs

The one in the start post is indeed premium only (in Germany). I can also not access it from a private tab in my browser. As I can not find a way to provide my credentials to pytube, this might be a dead end for me.

Thank you for your support!

@ruizr
Copy link

ruizr commented Oct 17, 2020

Hi sirodus,
I tried both versions mentioned in your comment, but both were unsuccessful.

r"'PLAYER_CONFIG':\s*({.*})});"
r"'PLAYER_CONFIG':\s*({.*})}\);"

Could you please check if there is a typo or something in your comment if you were successful using the regex?

I modified the file "extract.py" in line 187 with the following (keep attention to open-close variables):

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
r"'{PLAYER_CONFIG':\s*({.*})});" ]

and works like a charm!!!.

@randomnessyt92
Copy link

Hi, I spent an hour on it but found a solution, specially set up an account here to share it.
In the pytube/extract.py file, add to the config_patterns list
r"'PLAYER_CONFIG':\s*({.*})});"
it's supposed to look like this
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 r"'PLAYER_CONFIG':\s*({.*})}\);", ]

Thanks! it works.

@davidrodord56
Copy link

Hi sirodus,
I tried both versions mentioned in your comment, but both were unsuccessful.
r"'PLAYER_CONFIG':\s*({.*})});"
r"'PLAYER_CONFIG':\s*({.*})}\);"
Could you please check if there is a typo or something in your comment if you were successful using the regex?

I modified the file "extract.py" in line 187 with the following (keep attention to open-close variables):

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
r"'{PLAYER_CONFIG':\s*({.*})});" ]

and works like a charm!!!.

It worked for me, I was having trouble I don't know why, videos were online without restrictions or problems. It hade problems randomly but now is solved. Thank you so much

@tfdahlin
Copy link
Collaborator

tfdahlin commented Nov 8, 2020

I am sorry, but it is still the URL from my first message which is causing me issues.

Now I realized that all the urls that are working for me are not YouTube Premium only, but available for everyone
e.g https://www.youtube.com/watch?v=UGN00k2bHgs

The one in the start post is indeed premium only (in Germany). I can also not access it from a private tab in my browser. As I can not find a way to provide my credentials to pytube, this might be a dead end for me.

Thank you for your support!

Hi @lukas4haus I believe the most recent update to the repository should fix the issue with these videos (though it can't fix premium-only videos). If you want to test it out, you can install from the source with python -m pip install git+https://github.com/nficano/pytube. Let me know if this works!

This was linked to pull requests Nov 9, 2020
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

Successfully merging a pull request may close this issue.

7 participants