tv24ua.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import determine_ext, js_to_json, mimetype2ext, traverse_obj
  4. class TV24UAVideoIE(InfoExtractor):
  5. _VALID_URL = r'https?://24tv\.ua/news/showPlayer\.do.*?(?:\?|&)objectId=(?P<id>\d+)'
  6. _EMBED_REGEX = [rf'<iframe[^>]+?src=["\']?(?P<url>{_VALID_URL})["\']?']
  7. IE_NAME = '24tv.ua'
  8. _TESTS = [{
  9. 'url': 'https://24tv.ua/news/showPlayer.do?objectId=2074790&videoUrl=2022/07/2074790&w=640&h=360',
  10. 'info_dict': {
  11. 'id': '2074790',
  12. 'ext': 'mp4',
  13. 'title': 'У Харкові ворожа ракета прилетіла в будинок, де слухали пісні про "офіцерів-росіян"',
  14. 'thumbnail': r're:^https?://.*\.jpe?g',
  15. },
  16. }, {
  17. 'url': 'https://24tv.ua/news/showPlayer.do?videoUrl=2022/07/2074790&objectId=2074790&w=640&h=360',
  18. 'only_matching': True,
  19. }]
  20. _WEBPAGE_TESTS = [
  21. {
  22. # iframe embed created from share menu.
  23. 'url': 'data:text/html,%3Ciframe%20src=%22https://24tv.ua/news/showPlayer.do?objectId=1886193&videoUrl'
  24. '=2022/03/1886193&w=640&h=360%22%20width=%22640%22%20height=%22360%22%20frameborder=%220%22'
  25. '%20scrolling=%22no%22%3E%3C/iframe%3E',
  26. 'info_dict': {
  27. 'id': '1886193',
  28. 'ext': 'mp4',
  29. 'title': 'Росіяни руйнують Бородянку на Київщині та стріляють з літаків по мешканцях: шокуючі фото',
  30. 'thumbnail': r're:^https?://.*\.jpe?g',
  31. },
  32. },
  33. {
  34. 'url': 'https://24tv.ua/vipalyuyut-nashi-mista-sela-dsns-pokazali-motoroshni-naslidki_n1883966',
  35. 'info_dict': {
  36. 'id': '1883966',
  37. 'ext': 'mp4',
  38. 'title': 'Випалюють наші міста та села, – моторошні наслідки обстрілів на Чернігівщині',
  39. 'thumbnail': r're:^https?://.*\.jpe?g',
  40. },
  41. 'params': {'allowed_extractors': ['Generic', '24tv.ua']},
  42. },
  43. ]
  44. def _real_extract(self, url):
  45. video_id = self._match_id(url)
  46. webpage = self._download_webpage(url, video_id)
  47. formats = []
  48. subtitles = {}
  49. for j in re.findall(r'vPlayConfig\.sources\s*=\s*(?P<json>\[{\s*(?s:.+?)\s*}])', webpage):
  50. sources = self._parse_json(j, video_id, fatal=False, ignore_extra=True, transform_source=js_to_json, errnote='') or []
  51. for source in sources:
  52. if mimetype2ext(traverse_obj(source, 'type')) == 'm3u8':
  53. f, s = self._extract_m3u8_formats_and_subtitles(source['src'], video_id)
  54. formats.extend(f)
  55. self._merge_subtitles(subtitles, s)
  56. else:
  57. formats.append({
  58. 'url': source['src'],
  59. 'ext': determine_ext(source['src']),
  60. })
  61. thumbnail = traverse_obj(
  62. self._search_json(
  63. r'var\s*vPlayConfig\s*=\s*', webpage, 'thumbnail',
  64. video_id, default=None, transform_source=js_to_json), 'poster')
  65. return {
  66. 'id': video_id,
  67. 'formats': formats,
  68. 'subtitles': subtitles,
  69. 'thumbnail': thumbnail or self._og_search_thumbnail(webpage),
  70. 'title': self._generic_title('', webpage),
  71. 'description': self._og_search_description(webpage, default=None),
  72. }