genericembeds.py 4.5 KB

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