aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/streamango.py
blob: a4ef06b6668a63cf03f39c90949f72eddf8fe917 (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
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor


class StreamangoIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>.+?)/(?:.+)'
    _TESTS = [{
        'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
        'md5': 'e992787515a182f55e38fc97588d802a',
        'info_dict': {
            'id': 'clapasobsptpkdfe',
            'ext': 'mp4',
            'title': '20170315_150006.mp4',
            'url': r're:https://streamango\.com/v/d/clapasobsptpkdfe~[0-9]{10}~(?:[0-9]+\.){3}[0-9]+~.{8}/720',
        }
    }, {
        'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        def extract_url(urltype):
            return self._search_regex(
                r'type\s*:\s*["\']{}["\']\s*,\s*src\s*:\s*["\'](?P<url>.+?)["\'].*'.format(urltype),
                webpage, 'video URL', group='url')

        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        title = self._og_search_title(webpage)
        url = 'https:' + extract_url('video/mp4')
        dashurl = extract_url(r'application/dash\+xml')

        formats = [{
            'url': url,
            'ext': 'mp4',
            'width': 1280,
            'height': 720,
            'format_id': 'mp4',
        }]

        formats.extend(self._extract_mpd_formats(
            dashurl, video_id, mpd_id='dash', fatal=False))

        self._sort_formats(formats)

        return {
            'id': video_id,
            'url': url,
            'title': title,
            'formats': formats,
        }