aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/voot.py
blob: db5bda66005b04fec01489e83e43a0f752efe0b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor


class VootIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?voot\.com/shows/(?:.+?[/-]?)/1/(?:.+?[0-9]?)/(?:.+?[/-]?)/(?P<id>[0-9]+)'
    _TEST = {
        'url': 'https://www.voot.com/shows/ishq-ka-rang-safed/1/360558/is-this-the-end-of-kamini-/441353',
        'info_dict': {
            'id': '441353',
            'ext': 'mp4',
            'title': 'Ishq Ka Rang Safed - Season 01 - Episode 340',
            'thumbnail': r're:^https?://.*\.jpg$',
        }
    }

    _GET_CONTENT_TEMPLATE = 'https://wapi.voot.com/ws/ott/getMediaInfo.json?platform=Web&pId=3&mediaId=%s'

    def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata', fatal=True):
        json_data = super(VootIE, self)._download_json(url_or_request, video_id, note, fatal=fatal)
        if json_data['status']['code'] != 0:
            if fatal:
                raise ExtractorError(json_data['status']['message'])
            return None
        return json_data['assets']

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_data = self._download_json(
            self._GET_CONTENT_TEMPLATE % video_id,
            video_id)

        thumbnail = ''
        formats = []

        if video_data:
            format_url = video_data.get('URL')
            formats.extend(self._extract_m3u8_formats(format_url, video_id, 'mp4', m3u8_id='hls', fatal=False))

        if video_data['Pictures']:
            for picture in video_data['Pictures']:
                #Get only first available thumbnail
                thumbnail = picture.get('URL')
                break

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': video_data.get('MediaName'),
            'thumbnail': thumbnail,
            'formats':formats,
        }