]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/genericembeds.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / genericembeds.py
1 import re
2 import urllib.parse
3
4 from .common import InfoExtractor
5 from ..utils import make_archive_id, unescapeHTML
6
7
8 class HTML5MediaEmbedIE(InfoExtractor):
9 _VALID_URL = False
10 IE_NAME = 'html5'
11 _WEBPAGE_TESTS = [
12 {
13 'url': 'https://html.com/media/',
14 'info_dict': {
15 'title': 'HTML5 Media',
16 'description': 'md5:933b2d02ceffe7a7a0f3c8326d91cc2a',
17 },
18 'playlist_count': 2
19 }
20 ]
21
22 def _extract_from_webpage(self, url, webpage):
23 video_id, title = self._generic_id(url), self._generic_title(url, webpage)
24 entries = self._parse_html5_media_entries(url, webpage, video_id, m3u8_id='hls') or []
25 for num, entry in enumerate(entries, start=1):
26 entry.update({
27 'id': f'{video_id}-{num}',
28 'title': f'{title} ({num})',
29 '_old_archive_ids': [
30 make_archive_id('generic', f'{video_id}-{num}' if len(entries) > 1 else video_id),
31 ],
32 })
33 yield entry
34
35
36 class QuotedHTMLIE(InfoExtractor):
37 """For common cases of quoted/escaped html parts in the webpage"""
38 _VALID_URL = False
39 IE_NAME = 'generic:quoted-html'
40 IE_DESC = False # Do not list
41 _WEBPAGE_TESTS = [{
42 # 2 YouTube embeds in data-html
43 'url': 'https://24tv.ua/bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
44 'info_dict': {
45 'id': 'bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
46 'title': 'Броньовик Wolfhound: гігант, який допомагає ЗСУ знищувати окупантів на фронті',
47 'thumbnail': r're:^https?://.*\.jpe?g',
48 'timestamp': float,
49 'upload_date': str,
50 'description': 'md5:6816e1e5a65304bd7898e4c7eb1b26f7',
51 'age_limit': 0,
52 },
53 'playlist_count': 2
54 }, {
55 # Generic iframe embed of TV24UAPlayerIE within data-html
56 'url': 'https://24tv.ua/harkivyani-zgaduyut-misto-do-viyni-shhemlive-video_n1887584',
57 'info_dict': {
58 'id': '1887584',
59 'ext': 'mp4',
60 'title': 'Харків\'яни згадують місто до війни: щемливе відео',
61 'thumbnail': r're:^https?://.*\.jpe?g',
62 },
63 'params': {'skip_download': True}
64 }, {
65 # YouTube embeds on Squarespace (data-html): https://github.com/ytdl-org/youtube-dl/issues/21294
66 'url': 'https://www.harvardballetcompany.org/past-productions',
67 'info_dict': {
68 'id': 'past-productions',
69 'title': 'Productions — Harvard Ballet Company',
70 'age_limit': 0,
71 'description': 'Past Productions',
72 },
73 'playlist_mincount': 26
74 }, {
75 # Squarespace video embed, 2019-08-28, data-html
76 'url': 'http://ootboxford.com',
77 'info_dict': {
78 'id': 'Tc7b_JGdZfw',
79 'title': 'Out of the Blue, at Childish Things 10',
80 'ext': 'mp4',
81 'description': 'md5:a83d0026666cf5ee970f8bd1cfd69c7f',
82 'uploader_id': 'helendouglashouse',
83 'uploader': 'Helen & Douglas House',
84 'upload_date': '20140328',
85 'availability': 'public',
86 'view_count': int,
87 'channel': 'Helen & Douglas House',
88 'comment_count': int,
89 'uploader_url': 'http://www.youtube.com/user/helendouglashouse',
90 'duration': 253,
91 'channel_url': 'https://www.youtube.com/channel/UCTChGezrZVmlYlpMlkmulPA',
92 'playable_in_embed': True,
93 'age_limit': 0,
94 'channel_follower_count': int,
95 'channel_id': 'UCTChGezrZVmlYlpMlkmulPA',
96 'tags': 'count:6',
97 'categories': ['Nonprofits & Activism'],
98 'like_count': int,
99 'thumbnail': 'https://i.ytimg.com/vi/Tc7b_JGdZfw/hqdefault.jpg',
100 },
101 'params': {
102 'skip_download': True,
103 },
104 }]
105
106 def _extract_from_webpage(self, url, webpage):
107 combined = ''
108 for _, html in re.findall(r'(?s)\bdata-html=(["\'])((?:(?!\1).)+)\1', webpage):
109 # unescapeHTML can handle " etc., unquote can handle percent encoding
110 unquoted_html = unescapeHTML(urllib.parse.unquote(html))
111 if unquoted_html != html:
112 combined += unquoted_html
113 if combined:
114 yield from self._extract_generic_embeds(url, combined)