]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/discoveryplusindia.py
[test/download] Fallback test to `bv`
[yt-dlp.git] / yt_dlp / extractor / discoveryplusindia.py
CommitLineData
de675812
A
1# coding: utf-8
2from __future__ import unicode_literals
3
4import json
de675812
A
5
6from ..compat import compat_str
7from ..utils import try_get
8from .common import InfoExtractor
9from .dplay import DPlayIE
10
11
12class DiscoveryPlusIndiaIE(DPlayIE):
13 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/videos?' + DPlayIE._PATH_REGEX
14 _TESTS = [{
15 'url': 'https://www.discoveryplus.in/videos/how-do-they-do-it/fugu-and-more?seasonId=8&type=EPISODE',
16 'info_dict': {
17 'id': '27104',
18 'ext': 'mp4',
19 'display_id': 'how-do-they-do-it/fugu-and-more',
20 'title': 'Fugu and More',
21 'description': 'The Japanese catch, prepare and eat the deadliest fish on the planet.',
22 'duration': 1319,
23 'timestamp': 1582309800,
24 'upload_date': '20200221',
25 'series': 'How Do They Do It?',
26 'season_number': 8,
27 'episode_number': 2,
28 'creator': 'Discovery Channel',
29 },
30 'params': {
de675812
A
31 'skip_download': True,
32 },
33 'skip': 'Cookies (not necessarily logged in) are needed'
34 }]
35
36 def _update_disco_api_headers(self, headers, disco_base, display_id, realm):
37 headers['x-disco-params'] = 'realm=%s' % realm
38 headers['x-disco-client'] = 'WEB:UNKNOWN:dplus-india:17.0.0'
39
40 def _download_video_playback_info(self, disco_base, video_id, headers):
41 return self._download_json(
42 disco_base + 'playback/v3/videoPlaybackInfo',
43 video_id, headers=headers, data=json.dumps({
44 'deviceInfo': {
45 'adBlocker': False,
46 },
47 'videoId': video_id,
48 }).encode('utf-8'))['data']['attributes']['streaming']
49
50 def _real_extract(self, url):
51 display_id = self._match_id(url)
52 return self._get_disco_api_info(
53 url, display_id, 'ap2-prod-direct.discoveryplus.in', 'dplusindia', 'in')
54
55
56class DiscoveryPlusIndiaShowIE(InfoExtractor):
57 _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/show/(?P<show_name>[^/]+)/?(?:[?#]|$)'
58 _TESTS = [{
59 'url': 'https://www.discoveryplus.in/show/how-do-they-do-it',
60 'playlist_mincount': 140,
61 'info_dict': {
62 'id': 'how-do-they-do-it',
63 },
45d1f157 64 }]
de675812
A
65
66 def _entries(self, show_name):
67 headers = {
68 'x-disco-client': 'WEB:UNKNOWN:dplus-india:prod',
69 'x-disco-params': 'realm=dplusindia',
70 'referer': 'https://www.discoveryplus.in/',
71 }
72 show_url = 'https://ap2-prod-direct.discoveryplus.in/cms/routes/show/{}?include=default'.format(show_name)
73 show_json = self._download_json(show_url,
74 video_id=show_name,
75 headers=headers)['included'][4]['attributes']['component']
76 show_id = show_json['mandatoryParams'].split('=')[-1]
77 season_url = 'https://ap2-prod-direct.discoveryplus.in/content/videos?sort=episodeNumber&filter[seasonNumber]={}&filter[show.id]={}&page[size]=100&page[number]={}'
78 for season in show_json['filters'][0]['options']:
79 season_id = season['id']
80 total_pages, page_num = 1, 0
81 while page_num < total_pages:
82 season_json = self._download_json(season_url.format(season_id, show_id, compat_str(page_num + 1)),
83 video_id=show_id, headers=headers,
84 note='Downloading JSON metadata%s' % (' page %d' % page_num if page_num else ''))
85 if page_num == 0:
86 total_pages = try_get(season_json, lambda x: x['meta']['totalPages'], int) or 1
87 episodes_json = season_json['data']
88 for episode in episodes_json:
89 video_id = episode['attributes']['path']
90 yield self.url_result(
91 'https://discoveryplus.in/videos/%s' % video_id,
92 ie=DiscoveryPlusIndiaIE.ie_key(), video_id=video_id)
93 page_num += 1
94
95 def _real_extract(self, url):
5ad28e7f 96 show_name = self._match_valid_url(url).group('show_name')
de675812 97 return self.playlist_result(self._entries(show_name), playlist_id=show_name)