Skip to content

Commit

Permalink
Merge pull request #94 from felipeucelli/innertube-update
Browse files Browse the repository at this point in the history
Fixed "get_throttling_function_name: could not find match for multiple" and other improvements
  • Loading branch information
JuanBindez authored Jul 10, 2024
2 parents 22fc56d + 1c20e86 commit 73aadb0
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 249 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ coverage.xml
.hypothesis/
.pytest_cache/
*.mp4
*.mp3
*.webm

# Performance profiling
prof/
Expand Down
25 changes: 13 additions & 12 deletions pytubefix/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,6 @@ def streaming_data(self):
video_id = self.vid_info['videoDetails']['videoId']

if video_id in invalid_id_list:
logger.warning(
f'The {self.client} client did not get a valid response, trying to use the WEB client.'
)
logger.warning(
f'Video ID: {video_id}'
)
logger.warning(
'Please open an issue at '
'https://github.com/JuanBindez/pytubefix/issues '
'and provide this log output.'
)

self.try_another_client()
else:
self.try_another_client()
Expand Down Expand Up @@ -338,6 +326,19 @@ def try_another_client(self):
but it is no longer effective.
"""

logger.warning(
f'The {self.client} client did not get a valid response, trying to use the WEB client.'
)
logger.warning(
f'Video ID: {self.video_id}'
)
logger.warning(
'Please open an issue at '
'https://github.com/JuanBindez/pytubefix/issues '
'and provide this log output.'
)

innertube = InnerTube(
client='WEB',
use_oauth=self.use_oauth,
Expand Down
11 changes: 9 additions & 2 deletions pytubefix/cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ def get_throttling_function_name(js: str) -> str:
# a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
# Bpa.length || iha("")) }};
# In the above case, `iha` is the relevant function name
r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
# r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
# r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',

# New pattern added on July 9, 2024
# https://github.com/yt-dlp/yt-dlp/pull/10390/files
# In this example we can find the name of the function at index "0" of "IRa"
# a.D && (b = String.fromCharCode(110), c = a.get(b)) && (c = IRa[0](c), a.set(b,c), IRa.length || Ima(""))
r'(?:\.get\(\"n\"\)\)&&\(b=|b=String\.fromCharCode\(\d+\),c=a\.get\(b\)\)&&\(c=)([a-zA-Z0-9$]+)(?:\[('
r'\d+)\])?\([a-zA-Z0-9]\)'
]
logger.debug('Finding throttling function name')
for pattern in function_patterns:
Expand Down
12 changes: 7 additions & 5 deletions pytubefix/contrib/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,12 @@ def _build_continuation_url(self, continuation: str) -> Tuple[str, dict, dict]:
return (
(
# was changed to this format (and post requests)
# between 2022.11.06 and 2022.11.20
"https://www.youtube.com/youtubei/v1/browse?key="
f"{self.yt_api_key}"
# around the day 2024.04.16
"https://www.youtube.com/youtubei/v1/browse?prettyPrint=false"
),
{
"X-YouTube-Client-Name": "1",
"X-YouTube-Client-Version": "2.20200720.00.02",
"X-YouTube-Client-Version": "2.20240530.02.00",
},
# extra data required for post request
{
Expand All @@ -201,7 +200,10 @@ def _build_continuation_url(self, continuation: str) -> Tuple[str, dict, dict]:
"client": {
"clientName": "WEB",
"visitorData": self._visitor_data,
"clientVersion": "2.20200720.00.02"
"osName": "Windows",
"osVersion": "10.0",
"clientVersion": "2.20240530.02.00",
"platform": "DESKTOP"
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions pytubefix/contrib/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,23 @@ def _build_continuation_url(self, continuation: str) -> Tuple[str, dict, dict]:
return (
(
# was changed to this format (and post requests)
# between 2021.03.02 and 2021.03.03
"https://www.youtube.com/youtubei/v1/browse?key="
f"{self.yt_api_key}"
# around the day 2024.04.16
"https://www.youtube.com/youtubei/v1/browse?prettyPrint=false"
),
{
"X-YouTube-Client-Name": "1",
"X-YouTube-Client-Version": "2.20200720.00.02",
"X-YouTube-Client-Version": "2.20240530.02.00",
},
# extra data required for post request
{
"continuation": continuation,
"context": {
"client": {
"clientName": "WEB",
"clientVersion": "2.20200720.00.02"
"osName": "Windows",
"osVersion": "10.0",
"clientVersion": "2.20240530.02.00",
"platform": "DESKTOP"
}
}
}
Expand Down
Loading

0 comments on commit 73aadb0

Please sign in to comment.