mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-12-08 17:25:21 +00:00
[extractor/generic:quoted-html] Add extractor (#5213)
Extracts embeds from escaped HTML within `data-html` attribute. Related: https://github.com/ytdl-org/youtube-dl/issues/21294, https://github.com/yt-dlp/yt-dlp/pull/5121 Authored by: coletdjnz Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
import base64
|
||||
import re
|
||||
import urllib.parse
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
determine_ext,
|
||||
extract_attributes,
|
||||
get_elements_html_by_class,
|
||||
js_to_json,
|
||||
mimetype2ext,
|
||||
smuggle_url,
|
||||
traverse_obj,
|
||||
)
|
||||
|
||||
@@ -87,60 +82,3 @@ class TV24UAVideoIE(InfoExtractor):
|
||||
'title': self._html_extract_title(webpage) or self._og_search_title(webpage),
|
||||
'description': self._og_search_description(webpage, default=None),
|
||||
}
|
||||
|
||||
|
||||
class TV24UAGenericPassthroughIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:[a-zA-Z0-9]+?\.)?24tv\.ua/(?P<id>[^/]+?_n\d+)'
|
||||
|
||||
_TESTS = [{
|
||||
# Generic iframe, not within media_embed
|
||||
'url': 'https://24tv.ua/vipalyuyut-nashi-mista-sela-dsns-pokazali-motoroshni-naslidki_n1883966',
|
||||
'info_dict': {
|
||||
'id': '1883966',
|
||||
'ext': 'mp4',
|
||||
'title': 'Випалюють наші міста та села, – моторошні наслідки обстрілів на Чернігівщині',
|
||||
'thumbnail': r're:^https?://.*\.jpe?g',
|
||||
}
|
||||
}, {
|
||||
# Generic iframe embed of TV24UAPlayerIE, within media_embed
|
||||
'url': 'https://24tv.ua/harkivyani-zgaduyut-misto-do-viyni-shhemlive-video_n1887584',
|
||||
'info_dict': {
|
||||
'id': 'harkivyani-zgaduyut-misto-do-viyni-shhemlive-video_n1887584',
|
||||
'title': 'Харків\'яни згадують місто до війни: щемливе відео'
|
||||
},
|
||||
'playlist': [{
|
||||
'info_dict': {
|
||||
'id': '1887584',
|
||||
'ext': 'mp4',
|
||||
'title': 'Харків\'яни згадують місто до війни: щемливе відео',
|
||||
'thumbnail': r're:^https?://.*\.jpe?g',
|
||||
},
|
||||
}]
|
||||
}, {
|
||||
# 2 media_embeds with YouTube iframes
|
||||
'url': 'https://24tv.ua/bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
|
||||
'info_dict': {
|
||||
'id': 'bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
|
||||
'title': 'Броньовик Wolfhound: гігант, який допомагає ЗСУ знищувати окупантів на фронті',
|
||||
},
|
||||
'playlist_count': 2
|
||||
}, {
|
||||
'url': 'https://men.24tv.ua/fitnes-bloger-sprobuvav-vikonati-trenuvannya-naysilnishoyi-lyudini_n2164538',
|
||||
'only_matching': True,
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
display_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, display_id)
|
||||
data_urls = []
|
||||
# The site contains escaped iframe embeds within an attribute.
|
||||
# Once escaped, generic can handle them, so we use a data url to pass the escaped html back.
|
||||
for html in get_elements_html_by_class('media_embed', webpage):
|
||||
data = urllib.parse.unquote(extract_attributes(html).get('data-html'))
|
||||
data_urls.append(f'data:text/html;base64,{base64.b64encode(data.encode("utf-8")).decode("utf-8")}')
|
||||
|
||||
if not data_urls:
|
||||
return self.url_result(url, 'Generic')
|
||||
return self.playlist_from_matches(
|
||||
[smuggle_url(url, {'to_generic': True}) for url in data_urls], display_id, ie='Generic',
|
||||
playlist_title=self._og_search_title(webpage) or self._html_extract_title(webpage))
|
||||
|
||||
Reference in New Issue
Block a user