Merge pull request #12909 from remitamine/raw-sub
[youtube-dl] / youtube_dl / extractor / voot.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .kaltura import KalturaIE
6 from ..utils import (
7     ExtractorError,
8     int_or_none,
9     try_get,
10     unified_timestamp,
11 )
12
13
14 class VootIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?voot\.com/(?:[^/]+/)+(?P<id>\d+)'
16     _GEO_COUNTRIES = ['IN']
17     _TESTS = [{
18         'url': 'https://www.voot.com/shows/ishq-ka-rang-safed/1/360558/is-this-the-end-of-kamini-/441353',
19         'info_dict': {
20             'id': '0_8ledb18o',
21             'ext': 'mp4',
22             'title': 'Ishq Ka Rang Safed - Season 01 - Episode 340',
23             'description': 'md5:06291fbbbc4dcbe21235c40c262507c1',
24             'uploader_id': 'batchUser',
25             'timestamp': 1472162937,
26             'upload_date': '20160825',
27             'duration': 1146,
28             'series': 'Ishq Ka Rang Safed',
29             'season_number': 1,
30             'episode': 'Is this the end of Kamini?',
31             'episode_number': 340,
32             'view_count': int,
33             'like_count': int,
34         },
35         'params': {
36             'skip_download': True,
37         },
38         'expected_warnings': ['Failed to download m3u8 information'],
39     }, {
40         'url': 'https://www.voot.com/kids/characters/mighty-cat-masked-niyander-e-/400478/school-bag-disappears/440925',
41         'only_matching': True,
42     }, {
43         'url': 'https://www.voot.com/movies/pandavas-5/424627',
44         'only_matching': True,
45     }]
46
47     def _real_extract(self, url):
48         video_id = self._match_id(url)
49
50         media_info = self._download_json(
51             'https://wapi.voot.com/ws/ott/getMediaInfo.json', video_id,
52             query={
53                 'platform': 'Web',
54                 'pId': 2,
55                 'mediaId': video_id,
56             })
57
58         status_code = try_get(media_info, lambda x: x['status']['code'], int)
59         if status_code != 0:
60             raise ExtractorError(media_info['status']['message'], expected=True)
61
62         media = media_info['assets']
63
64         entry_id = media['EntryId']
65         title = media['MediaName']
66
67         description, series, season_number, episode, episode_number = [None] * 5
68
69         for meta in try_get(media, lambda x: x['Metas'], list) or []:
70             key, value = meta.get('Key'), meta.get('Value')
71             if not key or not value:
72                 continue
73             if key == 'ContentSynopsis':
74                 description = value
75             elif key == 'RefSeriesTitle':
76                 series = value
77             elif key == 'RefSeriesSeason':
78                 season_number = int_or_none(value)
79             elif key == 'EpisodeMainTitle':
80                 episode = value
81             elif key == 'EpisodeNo':
82                 episode_number = int_or_none(value)
83
84         return {
85             '_type': 'url_transparent',
86             'url': 'kaltura:1982551:%s' % entry_id,
87             'ie_key': KalturaIE.ie_key(),
88             'title': title,
89             'description': description,
90             'series': series,
91             'season_number': season_number,
92             'episode': episode,
93             'episode_number': episode_number,
94             'timestamp': unified_timestamp(media.get('CreationDate')),
95             'duration': int_or_none(media.get('Duration')),
96             'view_count': int_or_none(media.get('ViewCounter')),
97             'like_count': int_or_none(media.get('like_counter')),
98         }