Skip to content

Commit

Permalink
[youtube] Fix function signature parser (refs ytdl-org/ytdl-org#30363)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanegramling committed Dec 15, 2021
1 parent a803582 commit 1a09168
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,10 +1323,10 @@ def _parse_sig_js(self, jscode):
funcname = self._search_regex(
(r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\(',
r'\bm=(?P<sig>[a-zA-Z0-9$]{2})\(decodeURIComponent\(h\.s\)\)',
r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2})\(decodeURIComponent\(c\)\)',
r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\);[a-zA-Z0-9$]{2}\.[a-zA-Z0-9$]{2}\(a,\d+\)',
r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
r'\bm=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(h\.s\)\)',
r'\bc&&\(c=(?P<sig>[a-zA-Z0-9$]{2,})\(decodeURIComponent\(c\)\)',
r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\);[a-zA-Z0-9$]{2}\.[a-zA-Z0-9$]{2}\(a,\d+\)',
r'(?:\b|[^a-zA-Z0-9$])(?P<sig>[a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
r'(?P<sig>[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',
# Obsolete patterns
r'(["\'])signature\1\s*,\s*(?P<sig>[a-zA-Z0-9$]+)\(',
Expand Down

4 comments on commit 1a09168

@romonwafa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Great job!

@acantekingibz
Copy link

@acantekingibz acantekingibz commented on 1a09168 Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the youtube-dl module in python. How can I update it with this branch? When I try to update it with pip3 install --upgrade youtube-dl it just tells me that there's nothing to update as its most-likely using the master branch as the source.
Or am I missing out on something?

@robertocarroll
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lanegramling Thanks so much for this fix. I'm leaving a comment just in case anyone comes here and puzzles over how to implement it:

  • My youtube-dl is installed via homebrew on Mac OS, so I went searching for the youtube-dl files in /usr/local/Cellar/ which is where homebrew installs them, but the basic principle is the same however the package is installed.
  • Inside youtube-dl I found the extractor folder: /usr/local/Cellar/youtube-dl/2021.6.6_1/libexec/lib/python3.10/site-packages/youtube_dl/extractor
  • Inside that folder is youtube.py
  • Go to line 1326 and replace the four regex patterns with your updates.
  • Save the file.
  • It works!

Thanks again.

@000011111111
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using yt-dlp worked for me. Workflow here!

https://youtu.be/dAc5VIDIs5k

Please sign in to comment.