]>
Commit | Line | Data |
---|---|---|
f25e1c8d S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | determine_ext, | |
34921b43 | 9 | join_nonempty, |
f25e1c8d S |
10 | xpath_text, |
11 | ) | |
12 | ||
13 | ||
14 | class WebcasterIE(InfoExtractor): | |
15 | _VALID_URL = r'https?://bl\.webcaster\.pro/(?:quote|media)/start/free_(?P<id>[^/]+)' | |
16 | _TESTS = [{ | |
17 | # http://video.khl.ru/quotes/393859 | |
18 | 'url': 'http://bl.webcaster.pro/quote/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104?sr%3D105%26fa%3D1%26type_id%3D18', | |
19 | 'md5': '0c162f67443f30916ff1c89425dcd4cd', | |
20 | 'info_dict': { | |
21 | 'id': 'c8cefd240aa593681c8d068cff59f407_hd', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Сибирь - Нефтехимик. Лучшие моменты первого периода', | |
ec85ded8 | 24 | 'thumbnail': r're:^https?://.*\.jpg$', |
f25e1c8d S |
25 | }, |
26 | }, { | |
27 | 'url': 'http://bl.webcaster.pro/media/start/free_6246c7a4453ac4c42b4398f840d13100_hd/2_2991109016/e8d0d82587ef435480118f9f9c41db41/4635726126', | |
28 | 'only_matching': True, | |
29 | }] | |
30 | ||
31 | def _real_extract(self, url): | |
32 | video_id = self._match_id(url) | |
33 | ||
34 | video = self._download_xml(url, video_id) | |
35 | ||
36 | title = xpath_text(video, './/event_name', 'event name', fatal=True) | |
37 | ||
f25e1c8d S |
38 | formats = [] |
39 | for format_id in (None, 'noise'): | |
34921b43 | 40 | track_tag = join_nonempty('track', format_id, delim='_') |
f25e1c8d S |
41 | for track in video.findall('.//iphone/%s' % track_tag): |
42 | track_url = track.text | |
43 | if not track_url: | |
44 | continue | |
45 | if determine_ext(track_url) == 'm3u8': | |
46 | m3u8_formats = self._extract_m3u8_formats( | |
47 | track_url, video_id, 'mp4', | |
48 | entry_protocol='m3u8_native', | |
34921b43 | 49 | m3u8_id=join_nonempty('hls', format_id, delim='-'), fatal=False) |
f25e1c8d S |
50 | for f in m3u8_formats: |
51 | f.update({ | |
52 | 'source_preference': 0 if format_id == 'noise' else 1, | |
53 | 'format_note': track.get('title'), | |
54 | }) | |
55 | formats.extend(m3u8_formats) | |
56 | self._sort_formats(formats) | |
57 | ||
58 | thumbnail = xpath_text(video, './/image', 'thumbnail') | |
59 | ||
60 | return { | |
61 | 'id': video_id, | |
62 | 'title': title, | |
63 | 'thumbnail': thumbnail, | |
64 | 'formats': formats, | |
65 | } | |
66 | ||
67 | ||
68 | class WebcasterFeedIE(InfoExtractor): | |
69 | _VALID_URL = r'https?://bl\.webcaster\.pro/feed/start/free_(?P<id>[^/]+)' | |
70 | _TEST = { | |
71 | 'url': 'http://bl.webcaster.pro/feed/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104', | |
72 | 'only_matching': True, | |
73 | } | |
74 | ||
83f1481b S |
75 | @staticmethod |
76 | def _extract_url(ie, webpage): | |
77 | mobj = re.search( | |
78 | r'<(?:object|a[^>]+class=["\']webcaster-player["\'])[^>]+data(?:-config)?=(["\']).*?config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_.*?)(?:[?&]|\1)', | |
79 | webpage) | |
80 | if mobj: | |
81 | return mobj.group('url') | |
82 | for secure in (True, False): | |
83 | video_url = ie._og_search_video_url( | |
84 | webpage, secure=secure, default=None) | |
85 | if video_url: | |
86 | mobj = re.search( | |
87 | r'config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_[^?&=]+)', | |
88 | video_url) | |
89 | if mobj: | |
90 | return mobj.group('url') | |
91 | ||
f25e1c8d S |
92 | def _real_extract(self, url): |
93 | video_id = self._match_id(url) | |
94 | ||
95 | feed = self._download_xml(url, video_id) | |
96 | ||
97 | video_url = xpath_text( | |
98 | feed, ('video_hd', 'video'), 'video url', fatal=True) | |
99 | ||
100 | return self.url_result(video_url, WebcasterIE.ie_key()) |