From 2009cb27e17014787bf63eaa2ada51293d54f22a Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:16:22 +0000 Subject: [PATCH] [ie/SonyLIVSeries] Add `sort_order` extractor-arg (#11569) Authored by: bashonly --- README.md | 3 +++ yt_dlp/extractor/sonyliv.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 09096218e8..c9fe47a9a9 100644 --- a/README.md +++ b/README.md @@ -1869,6 +1869,9 @@ #### bilibili #### digitalconcerthall * `prefer_combined_hls`: Prefer extracting combined/pre-merged video and audio HLS formats. This will exclude 4K/HEVC video and lossless/FLAC audio formats, which are only available as split video/audio HLS formats +#### sonylivseries +* `sort_order`: Episode sort order for series extraction - one of `asc` (ascending, oldest first) or `desc` (descending, newest first). Default is `asc` + **Note**: These options may be changed/removed in the future without concern for backward compatibility diff --git a/yt_dlp/extractor/sonyliv.py b/yt_dlp/extractor/sonyliv.py index a0a051e972..0cd914cbba 100644 --- a/yt_dlp/extractor/sonyliv.py +++ b/yt_dlp/extractor/sonyliv.py @@ -199,8 +199,9 @@ class SonyLIVSeriesIE(InfoExtractor): }, }] _API_BASE = 'https://apiv2.sonyliv.com/AGL' + _SORT_ORDERS = ('asc', 'desc') - def _entries(self, show_id): + def _entries(self, show_id, sort_order): headers = { 'Accept': 'application/json, text/plain, */*', 'Referer': 'https://www.sonyliv.com', @@ -215,6 +216,9 @@ def _entries(self, show_id): 'from': '0', 'to': '49', }), ('resultObj', 'containers', 0, 'containers', lambda _, v: int_or_none(v['id']))) + + if sort_order == 'desc': + seasons = reversed(seasons) for season in seasons: season_id = str(season['id']) note = traverse_obj(season, ('metadata', 'title', {str})) or 'season' @@ -226,7 +230,7 @@ def _entries(self, show_id): 'from': str(cursor), 'to': str(cursor + 99), 'orderBy': 'episodeNumber', - 'sortOrder': 'asc', + 'sortOrder': sort_order, }), ('resultObj', 'containers', 0, 'containers', lambda _, v: int_or_none(v['id']))) if not episodes: break @@ -237,4 +241,10 @@ def _entries(self, show_id): def _real_extract(self, url): show_id = self._match_id(url) - return self.playlist_result(self._entries(show_id), playlist_id=show_id) + + sort_order = self._configuration_arg('sort_order', [self._SORT_ORDERS[0]])[0] + if sort_order not in self._SORT_ORDERS: + raise ValueError( + f'Invalid sort order "{sort_order}". Allowed values are: {", ".join(self._SORT_ORDERS)}') + + return self.playlist_result(self._entries(show_id, sort_order), playlist_id=show_id)