From 135e6b93f40e63edb6814765d3d7fa6ab625b4ee Mon Sep 17 00:00:00 2001 From: Ashish <39122144+Ashish0804@users.noreply.github.com> Date: Sat, 22 May 2021 17:53:06 +0530 Subject: [PATCH] [SonyLIV] Add SonyLIVSeriesIE (#331) Authored by: Ashish0804 --- yt_dlp/extractor/extractors.py | 5 +++- yt_dlp/extractor/sonyliv.py | 47 +++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py index 70cbe7ba5..829394ac6 100644 --- a/yt_dlp/extractor/extractors.py +++ b/yt_dlp/extractor/extractors.py @@ -1184,7 +1184,10 @@ from .slideslive import SlidesLiveIE from .slutload import SlutloadIE from .snotr import SnotrIE from .sohu import SohuIE -from .sonyliv import SonyLIVIE +from .sonyliv import ( + SonyLIVIE, + SonyLIVSeriesIE, +) from .soundcloud import ( SoundcloudEmbedIE, SoundcloudIE, diff --git a/yt_dlp/extractor/sonyliv.py b/yt_dlp/extractor/sonyliv.py index 5cfd109bb..ec7b4f37f 100644 --- a/yt_dlp/extractor/sonyliv.py +++ b/yt_dlp/extractor/sonyliv.py @@ -9,11 +9,18 @@ from ..compat import compat_HTTPError from ..utils import ( ExtractorError, int_or_none, + try_get, ) class SonyLIVIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+-(?P\d+)' + _VALID_URL = r'''(?x) + (?: + sonyliv:| + https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+- + ) + (?P\d+) + ''' _TESTS = [{ 'url': 'https://www.sonyliv.com/shows/bachelors-delight-1700000113/achaari-cheese-toast-1000022678?watch=true', 'info_dict': { @@ -107,3 +114,41 @@ class SonyLIVIE(InfoExtractor): 'episode_number': int_or_none(metadata.get('episodeNumber')), 'release_year': int_or_none(metadata.get('year')), } + + +class SonyLIVSeriesIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?sonyliv\.com/shows/[^/?#&]+-(?P\d{10})$' + _TESTS = [{ + 'url': 'https://www.sonyliv.com/shows/adaalat-1700000091', + 'playlist_mincount': 456, + 'info_dict': { + 'id': '1700000091', + }, + }] + _API_SHOW_URL = "https://apiv2.sonyliv.com/AGL/1.9/R/ENG/WEB/IN/DL/DETAIL/{}?kids_safe=false&from=0&to=49" + _API_EPISODES_URL = "https://apiv2.sonyliv.com/AGL/1.4/R/ENG/WEB/IN/CONTENT/DETAIL/BUNDLE/{}?from=0&to=1000&orderBy=episodeNumber&sortOrder=asc" + _API_SECURITY_URL = 'https://apiv2.sonyliv.com/AGL/1.4/A/ENG/WEB/ALL/GETTOKEN' + + def _entries(self, show_id): + headers = { + 'Accept': 'application/json, text/plain, */*', + 'Referer': 'https://www.sonyliv.com', + } + headers['security_token'] = self._download_json( + self._API_SECURITY_URL, video_id=show_id, headers=headers, + note='Downloading security token')['resultObj'] + seasons = try_get( + self._download_json(self._API_SHOW_URL.format(show_id), video_id=show_id, headers=headers), + lambda x: x['resultObj']['containers'][0]['containers'], list) + for season in seasons or []: + season_id = season['id'] + episodes = try_get( + self._download_json(self._API_EPISODES_URL.format(season_id), video_id=season_id, headers=headers), + lambda x: x['resultObj']['containers'][0]['containers'], list) + for episode in episodes or []: + video_id = episode.get('id') + yield self.url_result('sonyliv:%s' % video_id, ie=SonyLIVIE.ie_key(), video_id=video_id) + + def _real_extract(self, url): + show_id = self._match_id(url) + return self.playlist_result(self._entries(show_id), playlist_id=show_id)