]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/hotstar.py
[YoutubeDL] Ensure dir existence for each requested format (closes #14116)
[yt-dlp.git] / youtube_dl / extractor / hotstar.py
CommitLineData
fb8e402a 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..utils import (
6 ExtractorError,
7 determine_ext,
8 int_or_none,
9)
10
11
12class HotStarIE(InfoExtractor):
89d23f37
S
13 _VALID_URL = r'https?://(?:www\.)?hotstar\.com/(?:.+?[/-])?(?P<id>\d{10})'
14 _TESTS = [{
fb8e402a 15 'url': 'http://www.hotstar.com/on-air-with-aib--english-1000076273',
16 'info_dict': {
17 'id': '1000076273',
18 'ext': 'mp4',
19 'title': 'On Air With AIB - English',
20 'description': 'md5:c957d8868e9bc793ccb813691cc4c434',
21 'timestamp': 1447227000,
22 'upload_date': '20151111',
23 'duration': 381,
24 },
25 'params': {
26 # m3u8 download
27 'skip_download': True,
28 }
89d23f37
S
29 }, {
30 'url': 'http://www.hotstar.com/sports/cricket/rajitha-sizzles-on-debut-with-329/2001477583',
31 'only_matching': True,
32 }, {
33 'url': 'http://www.hotstar.com/1000000515',
34 'only_matching': True,
35 }]
fb8e402a 36
0dac7cbb
RA
37 def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True, query=None):
38 json_data = super(HotStarIE, self)._download_json(
39 url_or_request, video_id, note, fatal=fatal, query=query)
fb8e402a 40 if json_data['resultCode'] != 'OK':
41 if fatal:
42 raise ExtractorError(json_data['errorDescription'])
43 return None
44 return json_data['resultObj']
45
46 def _real_extract(self, url):
47 video_id = self._match_id(url)
48 video_data = self._download_json(
0dac7cbb
RA
49 'http://account.hotstar.com/AVS/besc', video_id, query={
50 'action': 'GetAggregatedContentDetails',
51 'channel': 'PCTV',
52 'contentId': video_id,
53 })['contentInfo'][0]
54 title = video_data['episodeTitle']
55
56 if video_data.get('encrypted') == 'Y':
57 raise ExtractorError('This video is DRM protected.', expected=True)
fb8e402a 58
59 formats = []
0dac7cbb 60 for f in ('JIO',):
fb8e402a 61 format_data = self._download_json(
0dac7cbb
RA
62 'http://getcdn.hotstar.com/AVS/besc',
63 video_id, 'Downloading %s JSON metadata' % f,
64 fatal=False, query={
65 'action': 'GetCDN',
66 'asJson': 'Y',
67 'channel': f,
68 'id': video_id,
69 'type': 'VOD',
70 })
fb8e402a 71 if format_data:
0dac7cbb
RA
72 format_url = format_data.get('src')
73 if not format_url:
74 continue
fb8e402a 75 ext = determine_ext(format_url)
76 if ext == 'm3u8':
0dac7cbb
RA
77 formats.extend(self._extract_m3u8_formats(
78 format_url, video_id, 'mp4',
79 m3u8_id='hls', fatal=False))
fb8e402a 80 elif ext == 'f4m':
81 # produce broken files
82 continue
83 else:
84 formats.append({
85 'url': format_url,
86 'width': int_or_none(format_data.get('width')),
87 'height': int_or_none(format_data.get('height')),
88 })
89 self._sort_formats(formats)
90
91 return {
92 'id': video_id,
0dac7cbb 93 'title': title,
fb8e402a 94 'description': video_data.get('description'),
95 'duration': int_or_none(video_data.get('duration')),
96 'timestamp': int_or_none(video_data.get('broadcastDate')),
97 'formats': formats,
0dac7cbb
RA
98 'episode': title,
99 'episode_number': int_or_none(video_data.get('episodeNumber')),
100 'series': video_data.get('contentTitle'),
fb8e402a 101 }