a4ef06b6668a63cf03f39c90949f72eddf8fe917
[youtube-dl] / youtube_dl / extractor / streamango.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class StreamangoIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>.+?)/(?:.+)'
9     _TESTS = [{
10         'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
11         'md5': 'e992787515a182f55e38fc97588d802a',
12         'info_dict': {
13             'id': 'clapasobsptpkdfe',
14             'ext': 'mp4',
15             'title': '20170315_150006.mp4',
16             'url': r're:https://streamango\.com/v/d/clapasobsptpkdfe~[0-9]{10}~(?:[0-9]+\.){3}[0-9]+~.{8}/720',
17         }
18     }, {
19         'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
20         'only_matching': True,
21     }]
22
23     def _real_extract(self, url):
24         def extract_url(urltype):
25             return self._search_regex(
26                 r'type\s*:\s*["\']{}["\']\s*,\s*src\s*:\s*["\'](?P<url>.+?)["\'].*'.format(urltype),
27                 webpage, 'video URL', group='url')
28
29         video_id = self._match_id(url)
30         webpage = self._download_webpage(url, video_id)
31
32         title = self._og_search_title(webpage)
33         url = 'https:' + extract_url('video/mp4')
34         dashurl = extract_url(r'application/dash\+xml')
35
36         formats = [{
37             'url': url,
38             'ext': 'mp4',
39             'width': 1280,
40             'height': 720,
41             'format_id': 'mp4',
42         }]
43
44         formats.extend(self._extract_mpd_formats(
45             dashurl, video_id, mpd_id='dash', fatal=False))
46
47         self._sort_formats(formats)
48
49         return {
50             'id': video_id,
51             'url': url,
52             'title': title,
53             'formats': formats,
54         }