]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sonyliv.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_HTTPError
16 class SonyLIVIE(InfoExtractor
):
20 https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+-
25 'url': 'https://www.sonyliv.com/shows/bachelors-delight-1700000113/achaari-cheese-toast-1000022678?watch=true',
27 'title': 'Achaari Cheese Toast',
30 'upload_date': '20200411',
31 'description': 'md5:3957fa31d9309bf336ceb3f37ad5b7cb',
32 'timestamp': 1586632091,
35 'series': 'Bachelors Delight',
40 'skip_download': True,
43 'url': 'https://www.sonyliv.com/movies/tahalka-1000050121?watch=true',
44 'only_matching': True,
46 'url': 'https://www.sonyliv.com/clip/jigarbaaz-1000098925',
47 'only_matching': True,
49 'url': 'https://www.sonyliv.com/trailer/sandwiched-forever-1000100286?watch=true',
50 'only_matching': True,
52 'url': 'https://www.sonyliv.com/sports/india-tour-of-australia-2020-21-1700000286/cricket-hls-day-3-1st-test-aus-vs-ind-19-dec-2020-1000100959?watch=true',
53 'only_matching': True,
55 'url': 'https://www.sonyliv.com/music-videos/yeh-un-dinon-ki-baat-hai-1000018779',
56 'only_matching': True,
58 _GEO_COUNTRIES
= ['IN']
61 def _call_api(self
, version
, path
, video_id
):
64 headers
['security_token'] = self
._TOKEN
66 return self
._download
_json
(
67 'https://apiv2.sonyliv.com/AGL/%s/A/ENG/WEB/%s' % (version
, path
),
68 video_id
, headers
=headers
)['resultObj']
69 except ExtractorError
as e
:
70 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
71 message
= self
._parse
_json
(
72 e
.cause
.read().decode(), video_id
)['message']
73 if message
== 'Geoblocked Country':
74 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
75 raise ExtractorError(message
)
78 def _real_initialize(self
):
79 self
._TOKEN
= self
._call
_api
('1.4', 'ALL/GETTOKEN', None)
81 def _real_extract(self
, url
):
82 video_id
= self
._match
_id
(url
)
83 content
= self
._call
_api
(
84 '1.5', 'IN/CONTENT/VIDEOURL/VOD/' + video_id
, video_id
)
85 if not self
.get_param('allow_unplayable_formats') and content
.get('isEncrypted'):
86 raise ExtractorError('This video is DRM protected.', expected
=True)
87 dash_url
= content
['videoURL']
89 'x-playback-session-id': '%s-%d' % (uuid
.uuid4().hex, time
.time() * 1000)
91 formats
= self
._extract
_mpd
_formats
(
92 dash_url
, video_id
, mpd_id
='dash', headers
=headers
, fatal
=False)
93 formats
.extend(self
._extract
_m
3u8_formats
(
94 dash_url
.replace('.mpd', '.m3u8').replace('/DASH/', '/HLS/'),
95 video_id
, 'mp4', m3u8_id
='hls', headers
=headers
, fatal
=False))
97 f
.setdefault('http_headers', {}).update(headers
)
98 self
._sort
_formats
(formats
)
100 metadata
= self
._call
_api
(
101 '1.6', 'IN/DETAIL/' + video_id
, video_id
)['containers'][0]['metadata']
102 title
= metadata
['episodeTitle']
104 for sub
in content
.get('subtitle', []):
105 sub_url
= sub
.get('subtitleUrl')
108 subtitles
.setdefault(sub
.get('subtitleLanguageName', 'ENG'), []).append({
115 'thumbnail': content
.get('posterURL'),
116 'description': metadata
.get('longDescription') or metadata
.get('shortDescription'),
117 'timestamp': int_or_none(metadata
.get('creationDate'), 1000),
118 'duration': int_or_none(metadata
.get('duration')),
119 'season_number': int_or_none(metadata
.get('season')),
120 'series': metadata
.get('title'),
121 'episode_number': int_or_none(metadata
.get('episodeNumber')),
122 'release_year': int_or_none(metadata
.get('year')),
123 'subtitles': subtitles
,
127 class SonyLIVSeriesIE(InfoExtractor
):
128 _VALID_URL
= r
'https?://(?:www\.)?sonyliv\.com/shows/[^/?#&]+-(?P<id>\d{10})$'
130 'url': 'https://www.sonyliv.com/shows/adaalat-1700000091',
131 'playlist_mincount': 456,
136 _API_SHOW_URL
= "https://apiv2.sonyliv.com/AGL/1.9/R/ENG/WEB/IN/DL/DETAIL/{}?kids_safe=false&from=0&to=49"
137 _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"
138 _API_SECURITY_URL
= 'https://apiv2.sonyliv.com/AGL/1.4/A/ENG/WEB/ALL/GETTOKEN'
140 def _entries(self
, show_id
):
142 'Accept': 'application/json, text/plain, */*',
143 'Referer': 'https://www.sonyliv.com',
145 headers
['security_token'] = self
._download
_json
(
146 self
._API
_SECURITY
_URL
, video_id
=show_id
, headers
=headers
,
147 note
='Downloading security token')['resultObj']
149 self
._download
_json
(self
._API
_SHOW
_URL
.format(show_id
), video_id
=show_id
, headers
=headers
),
150 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
151 for season
in seasons
or []:
152 season_id
= season
['id']
154 self
._download
_json
(self
._API
_EPISODES
_URL
.format(season_id
), video_id
=season_id
, headers
=headers
),
155 lambda x
: x
['resultObj']['containers'][0]['containers'], list)
156 for episode
in episodes
or []:
157 video_id
= episode
.get('id')
158 yield self
.url_result('sonyliv:%s' % video_id
, ie
=SonyLIVIE
.ie_key(), video_id
=video_id
)
160 def _real_extract(self
, url
):
161 show_id
= self
._match
_id
(url
)
162 return self
.playlist_result(self
._entries
(show_id
), playlist_id
=show_id
)