aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbashonly <88596187+bashonly@users.noreply.github.com>2024-11-17 21:16:22 +0000
committerGitHub <noreply@github.com>2024-11-17 21:16:22 +0000
commit2009cb27e17014787bf63eaa2ada51293d54f22a (patch)
tree6b8525bb09dcc9036432013d4e5254283107e14e
parentf351440f1dc5b3dfbfc5737b037a869d946056fe (diff)
[ie/SonyLIVSeries] Add `sort_order` extractor-arg (#11569)
Authored by: bashonly
-rw-r--r--README.md3
-rw-r--r--yt_dlp/extractor/sonyliv.py16
2 files changed, 16 insertions, 3 deletions
diff --git a/README.md b/README.md
index 09096218e..c9fe47a9a 100644
--- a/README.md
+++ b/README.md
@@ -1869,6 +1869,9 @@ The following extractors use this feature:
#### 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
<!-- MANPAGE: MOVE "INSTALLATION" SECTION HERE -->
diff --git a/yt_dlp/extractor/sonyliv.py b/yt_dlp/extractor/sonyliv.py
index a0a051e97..0cd914cbb 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 @@ class SonyLIVSeriesIE(InfoExtractor):
'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 @@ class SonyLIVSeriesIE(InfoExtractor):
'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 @@ class SonyLIVSeriesIE(InfoExtractor):
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)