diff options
author | garret <garret@airmail.cc> | 2023-07-04 01:46:18 +0100 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-07-04 02:06:23 +0100 |
commit | c2aeb311b00feabc8cbd4836a1b0bad6d1e4107b (patch) | |
tree | d9ac09de82ff20902b3c7eb90d284e461d66bbd4 | |
parent | 3000651068f7ef3f8d54d407c0804782ad145295 (diff) | |
download | yt-dlp-rajiko-c2aeb311b00feabc8cbd4836a1b0bad6d1e4107b.tar.gz yt-dlp-rajiko-c2aeb311b00feabc8cbd4836a1b0bad6d1e4107b.tar.bz2 yt-dlp-rajiko-c2aeb311b00feabc8cbd4836a1b0bad6d1e4107b.zip |
add tracklist chapters extraction
closes #6
-rwxr-xr-x | yt_dlp_plugins/extractor/radiko.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/yt_dlp_plugins/extractor/radiko.py b/yt_dlp_plugins/extractor/radiko.py index 5fc13e0..8a7ec6d 100755 --- a/yt_dlp_plugins/extractor/radiko.py +++ b/yt_dlp_plugins/extractor/radiko.py @@ -761,6 +761,18 @@ class RadikoTimeFreeIE(_RadikoBaseIE): } )}, (prog.get("ft"), prog.get("to")) + def _extract_chapters(self, station, start, end, video_id=None): + start_str = urllib.parse.quote(start.isoformat()) + end_str = urllib.parse.quote(end.isoformat()) + data = self._download_json(f"https://api.radiko.jp/music/api/v1/noas/{station}?start_time_gte={start_str}&end_time_lt={end_str}", + video_id, note="Downloading tracklist").get("data") + + return self._extract_chapters_helper(data, + title_function=lambda track: join_nonempty("artist_name", "title", delim=" - ", from_dict=track), + start_function=lambda track: (datetime.datetime.fromisoformat(track.get("displayed_start_time")) - start).total_seconds(), + duration=(end - start).total_seconds() + ) + def _real_extract(self, url): station, start_time = self._match_valid_url(url).group("station", "id") meta, times = self._get_programme_meta(station, start_time) @@ -790,6 +802,7 @@ class RadikoTimeFreeIE(_RadikoBaseIE): region = self._get_station_region(station) station_meta = self._get_station_meta(region, station) + chapters = self._extract_chapters(station, start_datetime, end_datetime, video_id=meta["id"]) auth_data = self._auth(region) formats = self._get_station_formats(station, True, auth_data, start_at=times[0], end_at=times[1]) @@ -801,6 +814,7 @@ class RadikoTimeFreeIE(_RadikoBaseIE): **station_meta, "alt_title": None, **meta, + "chapters": chapters, "formats": formats, "live_status": live_status, "container": "m4a_dash", # force fixup, AAC-only HLS |