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