diff options
author | garret <garret@airmail.cc> | 2023-05-29 22:12:05 +0100 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-05-29 22:12:05 +0100 |
commit | fd0fbe008e7255b3ff28fd4b8700737ad1497ed3 (patch) | |
tree | 5f115f19f24ccaf8ccb4a8de8e2c1ef2eb0dea9b | |
parent | c2eac05e4e512c8d4d139e17a122c1fa10827885 (diff) | |
download | yt-dlp-rajiko-fd0fbe008e7255b3ff28fd4b8700737ad1497ed3.tar.gz yt-dlp-rajiko-fd0fbe008e7255b3ff28fd4b8700737ad1497ed3.tar.bz2 yt-dlp-rajiko-fd0fbe008e7255b3ff28fd4b8700737ad1497ed3.zip |
somewhat quick and dirty search extractor
-rwxr-xr-x | yt_dlp_plugins/extractor/radiko.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/yt_dlp_plugins/extractor/radiko.py b/yt_dlp_plugins/extractor/radiko.py index 21f2b2f..9373867 100755 --- a/yt_dlp_plugins/extractor/radiko.py +++ b/yt_dlp_plugins/extractor/radiko.py @@ -8,6 +8,7 @@ from yt_dlp.extractor.common import InfoExtractor from yt_dlp.utils import ( clean_html, join_nonempty, + parse_qs, traverse_obj, unified_timestamp, url_or_none, @@ -803,3 +804,34 @@ class RadikoTimeFreeIE(_RadikoBaseIE): 'live_status': live_status, 'container': 'm4a_dash', # force fixup, AAC-only HLS } + +class RadikoSearchIE(_RadikoBaseIE): + _VALID_URL = r'https?://(?:www\.)?radiko\.jp/#!/search/(?:timeshift|live)\?' + + def _strip_date(self, date): + return date.replace(" ", "").replace("-", "").replace(":", "") + + 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 + queries = parse_qs(url) + + search_url = update_url_query("https://radiko.jp/v3/api/program/search", { + **queries, + 'uid': secrets.token_hex(16), + 'app_id': 'pc', + }) + data = self._download_json(search_url, None) + + results = traverse_obj(data, ('data',..., { + "station": "station_id", + "time": ("start_time", {self._strip_date}) + })) + + return { + "_type": "playlist", + "title": traverse_obj(queries, ("key", 0)), + "entries": [self.url_result(f"https://radiko.jp/#!/ts/{station}/{time}", RadikoTimeFreeIE) + for station, time in [ep.values() for ep in results]] + # TODO: have traverse_obj return a tuple, not a dict + } |