]> jfr.im git - yt-dlp.git/commitdiff
[Hotstar] Add HotStarSeriesIE (#366)
authorAshish <redacted>
Tue, 1 Jun 2021 14:44:03 +0000 (20:14 +0530)
committerGitHub <redacted>
Tue, 1 Jun 2021 14:44:03 +0000 (20:14 +0530)
Authored by: Ashish0804

yt_dlp/extractor/extractors.py
yt_dlp/extractor/hotstar.py

index 8a99b2a3da2f1a965baf45e39a1b9a38861fbc6e..ada6fa619d37d124ba52e1b5e2125940e444e1e1 100644 (file)
 from .hotstar import (
     HotStarIE,
     HotStarPlaylistIE,
+    HotStarSeriesIE,
 )
 from .howcast import HowcastIE
 from .howstuffworks import HowStuffWorksIE
index d497b50c1bc65afc3657b53883f7aec62251bf79..430b4e236d02f6857b35271ffef5c3973d2c6722 100644 (file)
@@ -87,7 +87,14 @@ def _call_api_v2(self, path, video_id):
 
 class HotStarIE(HotStarBaseIE):
     IE_NAME = 'hotstar'
-    _VALID_URL = r'https?://(?:www\.)?hotstar\.com/.*(?P<id>\d{10})'
+    _VALID_URL = r'''(?x)
+                           https?://(?:www\.)?hotstar\.com(?:/in)?/(?!in/)
+                           (?:
+                               tv/(?:[^/?#]+/){3}|
+                               (?!tv/)[^?#]+/
+                           )?
+                           (?P<id>\d{10})
+                   '''
     _TESTS = [{
         # contentData
         'url': 'https://www.hotstar.com/can-you-not-spread-rumours/1000076273',
@@ -235,3 +242,41 @@ def _real_extract(self, url):
             if video.get('contentId')]
 
         return self.playlist_result(entries, playlist_id)
+
+
+class HotStarSeriesIE(HotStarBaseIE):
+    IE_NAME = 'hotstar:series'
+    _VALID_URL = r'(?:https?://)(?:www\.)?hotstar\.com(?:/in)?/tv/[^/]+/(?P<id>\d{10})$'
+    _TESTS = [{
+        'url': 'https://www.hotstar.com/in/tv/radhakrishn/1260000646',
+        'info_dict': {
+            'id': '1260000646',
+        },
+        'playlist_mincount': 690,
+    }, {
+        'url': 'https://www.hotstar.com/tv/dancee-/1260050431',
+        'info_dict': {
+            'id': '1260050431',
+        },
+        'playlist_mincount': 43,
+    }]
+
+    def _real_extract(self, url):
+        series_id = self._match_id(url)
+        headers = {
+            'x-country-code': 'IN',
+            'x-platform-code': 'PCTV',
+        }
+        detail_json = self._download_json('https://api.hotstar.com/o/v1/show/detail?contentId=' + series_id,
+                                          video_id=series_id, headers=headers)
+        id = compat_str(try_get(detail_json, lambda x: x['body']['results']['item']['id'], int))
+        item_json = self._download_json('https://api.hotstar.com/o/v1/tray/g/1/items?etid=0&tao=0&tas=10000&eid=' + id,
+                                        video_id=series_id, headers=headers)
+        entries = [
+            self.url_result(
+                'https://www.hotstar.com/%d' % video['contentId'],
+                ie=HotStarIE.ie_key(), video_id=video['contentId'])
+            for video in item_json['body']['results']['items']
+            if video.get('contentId')]
+
+        return self.playlist_result(entries, series_id)