]>
Commit | Line | Data |
---|---|---|
9d46608e | 1 | import re |
2 | from .common import InfoExtractor | |
3 | from ..compat import compat_urlparse | |
4 | from ..utils import ( | |
5 | get_element_by_attribute, | |
6 | qualities, | |
7 | unescapeHTML, | |
8 | ) | |
9 | ||
10 | ||
11 | class OraTVIE(InfoExtractor): | |
ca950f49 S |
12 | _VALID_URL = r'https?://(?:www\.)?(?:ora\.tv|unsafespeech\.com)/([^/]+/)*(?P<id>[^/\?#]+)' |
13 | _TESTS = [{ | |
9d46608e | 14 | 'url': 'https://www.ora.tv/larrykingnow/2015/12/16/vine-youtube-stars-zach-king-king-bach-on-their-viral-videos-0_36jupg6090pq', |
15 | 'md5': 'fa33717591c631ec93b04b0e330df786', | |
16 | 'info_dict': { | |
17 | 'id': '50178', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'Vine & YouTube Stars Zach King & King Bach On Their Viral Videos!', | |
20 | 'description': 'md5:ebbc5b1424dd5dba7be7538148287ac1', | |
9d46608e | 21 | } |
ca950f49 S |
22 | }, { |
23 | 'url': 'http://www.unsafespeech.com/video/2016/5/10/student-self-censorship-and-the-thought-police-on-university-campuses-0_6622bnkppw4d', | |
24 | 'only_matching': True, | |
25 | }] | |
9d46608e | 26 | |
27 | def _real_extract(self, url): | |
28 | display_id = self._match_id(url) | |
29 | webpage = self._download_webpage(url, display_id) | |
30 | ||
ca950f49 S |
31 | video_data = self._search_regex( |
32 | r'"(?:video|current)"\s*:\s*({[^}]+?})', webpage, 'current video') | |
33 | m3u8_url = self._search_regex( | |
34 | r'hls_stream"?\s*:\s*"([^"]+)', video_data, 'm3u8 url', None) | |
9d46608e | 35 | if m3u8_url: |
36 | formats = self._extract_m3u8_formats( | |
37 | m3u8_url, display_id, 'mp4', 'm3u8_native', | |
38 | m3u8_id='hls', fatal=False) | |
dfb1b146 | 39 | # similar to GameSpotIE |
9d46608e | 40 | m3u8_path = compat_urlparse.urlparse(m3u8_url).path |
41 | QUALITIES_RE = r'((,[a-z]+\d+)+,?)' | |
42 | available_qualities = self._search_regex( | |
43 | QUALITIES_RE, m3u8_path, 'qualities').strip(',').split(',') | |
44 | http_path = m3u8_path[1:].split('/', 1)[1] | |
45 | http_template = re.sub(QUALITIES_RE, r'%s', http_path) | |
46 | http_template = http_template.replace('.csmil/master.m3u8', '') | |
47 | http_template = compat_urlparse.urljoin( | |
48 | 'http://videocdn-pmd.ora.tv/', http_template) | |
49 | preference = qualities( | |
50 | ['mobile400', 'basic400', 'basic600', 'sd900', 'sd1200', 'sd1500', 'hd720', 'hd1080']) | |
51 | for q in available_qualities: | |
52 | formats.append({ | |
53 | 'url': http_template % q, | |
54 | 'format_id': q, | |
f983b875 | 55 | 'quality': preference(q), |
9d46608e | 56 | }) |
9d46608e | 57 | else: |
58 | return self.url_result(self._search_regex( | |
59 | r'"youtube_id"\s*:\s*"([^"]+)', webpage, 'youtube id'), 'Youtube') | |
60 | ||
61 | return { | |
ca950f49 S |
62 | 'id': self._search_regex( |
63 | r'"id"\s*:\s*(\d+)', video_data, 'video id', default=display_id), | |
9d46608e | 64 | 'display_id': display_id, |
65 | 'title': unescapeHTML(self._og_search_title(webpage)), | |
66 | 'description': get_element_by_attribute( | |
67 | 'class', 'video_txt_decription', webpage), | |
ca950f49 S |
68 | 'thumbnail': self._proto_relative_url(self._search_regex( |
69 | r'"thumb"\s*:\s*"([^"]+)', video_data, 'thumbnail', None)), | |
9d46608e | 70 | 'formats': formats, |
71 | } |