Skip to content

Commit dbfde28

Browse files
committed
fix(parser-youtube): support new search of ytInitialData
Updates the regex/JSON path filters to correctly extract search results from the altered "ytInitialData" object structure inside the page source.
1 parent 3eca1c9 commit dbfde28

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎video_parsers/youtube/api/common.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ def dict_merge(d1: dict[str, Any], d2: dict[str, Any]) -> None:
195195

196196

197197
def get_yt_initial_data(html: str) -> dict[str, Any] | None:
198-
patterns = [
199-
re.compile(r'window\["ytInitialData"\] = (\{.+?\});'),
198+
patterns: list[re.Pattern] = [
199+
re.compile(r'<script id="yt-initial-data" type="application/json".+?>(\{.+?\})</script'),
200200
re.compile(r"var ytInitialData = (\{.+?\});"),
201+
re.compile(r'window\["ytInitialData"\] = (\{.+?\});'),
201202
]
202203

203204
for pattern in patterns:
@@ -215,6 +216,7 @@ def load(url: str) -> tuple[requests.Response, dict[str, Any]]:
215216

216217
data = get_yt_initial_data(rs.text)
217218
if not data:
219+
print(f"Could not find ytInitialData!\nResponse:\n{rs.text}")
218220
raise Exception("Could not find ytInitialData!")
219221

220222
raise_if_error(data)

0 commit comments

Comments
 (0)