From a6a5befebafced40da8dd0582a6c486b56184b22 Mon Sep 17 00:00:00 2001 From: garret Date: Sat, 15 Jul 2023 16:28:31 +0100 Subject: handle multi-paged search results fixes #13 --- yt_dlp_plugins/extractor/radiko.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'yt_dlp_plugins/extractor') diff --git a/yt_dlp_plugins/extractor/radiko.py b/yt_dlp_plugins/extractor/radiko.py index 6929f8e..ebe3265 100755 --- a/yt_dlp_plugins/extractor/radiko.py +++ b/yt_dlp_plugins/extractor/radiko.py @@ -6,6 +6,7 @@ import urllib.parse from yt_dlp.extractor.common import InfoExtractor from yt_dlp.utils import ( + OnDemandPagedList, clean_html, join_nonempty, parse_qs, @@ -853,6 +854,14 @@ class RadikoSearchIE(_RadikoBaseIE): def _strip_date(self, date): return date.replace(" ", "").replace("-", "").replace(":", "") + def _pagefunc(self, url, idx): + url = update_url_query(url, {"page_idx": idx}) + data = self._download_json(url, None, note=f"Downloading page {idx+1}") + + return [self.url_result("https://radiko.jp/#!/ts/{station}/{time}".format( + station = i.get("station_id"), time = self._strip_date(i.get("start_time")))) + for i in data.get("data")] + def _real_extract(self, url): url = url.replace("/#!/", "/!/", 1) # urllib.parse interprets the path as just one giant fragment because of the #, so we hack it away @@ -862,9 +871,10 @@ class RadikoSearchIE(_RadikoBaseIE): **queries, "uid": secrets.token_hex(16), "app_id": "pc", + "row_limit": 50, # higher row_limit = more results = less requests = more good }) - data = self._download_json(search_url, None) - results = [(i.get("station_id"), self._strip_date(i.get("start_time"))) for i in data.get("data")] + + results = OnDemandPagedList(lambda idx: self._pagefunc(search_url, idx), 50) key = traverse_obj(queries, ("key", 0)) day = traverse_obj(queries, ('start_day', 0)) or "all" @@ -877,8 +887,7 @@ class RadikoSearchIE(_RadikoBaseIE): "_type": "playlist", "title": traverse_obj(queries, ("key", 0)), "id": playlist_id, - "entries": [self.url_result(f"https://radiko.jp/#!/ts/{station}/{time}", RadikoTimeFreeIE) - for station, time in results] + "entries": results, } class RadikoShareIE(_RadikoBaseIE): -- cgit v1.2.3-70-g09d2