tvopengr.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. get_elements_text_and_html_by_attribute,
  5. scale_thumbnails_to_max_format_width,
  6. )
  7. class TVOpenGrBaseIE(InfoExtractor):
  8. def _return_canonical_url(self, url, video_id):
  9. webpage = self._download_webpage(url, video_id)
  10. canonical_url = self._og_search_url(webpage)
  11. title = self._og_search_title(webpage)
  12. return self.url_result(canonical_url, ie=TVOpenGrWatchIE.ie_key(), video_id=video_id, video_title=title)
  13. class TVOpenGrWatchIE(TVOpenGrBaseIE):
  14. IE_NAME = 'tvopengr:watch'
  15. IE_DESC = 'tvopen.gr (and ethnos.gr) videos'
  16. _VALID_URL = r'https?://(?P<netloc>(?:www\.)?(?:tvopen|ethnos)\.gr)/watch/(?P<id>\d+)/(?P<slug>[^/]+)'
  17. _API_ENDPOINT = 'https://www.tvopen.gr/templates/data/player'
  18. _TESTS = [{
  19. 'url': 'https://www.ethnos.gr/watch/101009/nikoskaprabelosdenexoymekanenanasthenhsemethmethmetallaxhomikron',
  20. 'md5': '8728570e3a72e0f8d9475ba94859fdc1',
  21. 'info_dict': {
  22. 'id': '101009',
  23. 'title': 'md5:51f68773dcb6c70498cd326f45fefdf0',
  24. 'display_id': 'nikoskaprabelosdenexoymekanenanasthenhsemethmethmetallaxhomikron',
  25. 'description': 'md5:78fff49f18fb3effe41b070e5c7685d6',
  26. 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/d573ba71-ec5f-43c6-b4cb-d181f327d3a8.jpg',
  27. 'ext': 'mp4',
  28. 'upload_date': '20220109',
  29. 'timestamp': 1641686400,
  30. },
  31. }, {
  32. 'url': 'https://www.tvopen.gr/watch/100979/se28099agapaomenalla7cepeisodio267cmhthrargiapashskakias',
  33. 'md5': '38f98a1be0c577db4ea2d1b1c0770c48',
  34. 'info_dict': {
  35. 'id': '100979',
  36. 'title': 'md5:e021f3001e16088ee40fa79b20df305b',
  37. 'display_id': 'se28099agapaomenalla7cepeisodio267cmhthrargiapashskakias',
  38. 'description': 'md5:ba17db53954134eb8d625d199e2919fb',
  39. 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/9bb71cf1-21da-43a9-9d65-367950fde4e3.jpg',
  40. 'ext': 'mp4',
  41. 'upload_date': '20220108',
  42. 'timestamp': 1641600000,
  43. },
  44. }]
  45. def _extract_formats_and_subs(self, response, video_id):
  46. formats, subs = [], {}
  47. for format_id, format_url in response.items():
  48. if format_id not in ('stream', 'httpstream', 'mpegdash'):
  49. continue
  50. ext = determine_ext(format_url)
  51. if ext == 'm3u8':
  52. formats_, subs_ = self._extract_m3u8_formats_and_subtitles(
  53. format_url, video_id, 'mp4', m3u8_id=format_id,
  54. fatal=False)
  55. elif ext == 'mpd':
  56. formats_, subs_ = self._extract_mpd_formats_and_subtitles(
  57. format_url, video_id, 'mp4', fatal=False)
  58. else:
  59. formats.append({
  60. 'url': format_url,
  61. 'format_id': format_id,
  62. })
  63. continue
  64. formats.extend(formats_)
  65. self._merge_subtitles(subs_, target=subs)
  66. return formats, subs
  67. def _real_extract(self, url):
  68. netloc, video_id, display_id = self._match_valid_url(url).group('netloc', 'id', 'slug')
  69. if netloc.find('tvopen.gr') == -1:
  70. return self._return_canonical_url(url, video_id)
  71. webpage = self._download_webpage(url, video_id)
  72. info = self._search_json_ld(webpage, video_id, expected_type='VideoObject')
  73. info['formats'], info['subtitles'] = self._extract_formats_and_subs(
  74. self._download_json(self._API_ENDPOINT, video_id, query={'cid': video_id}),
  75. video_id)
  76. info['thumbnails'] = scale_thumbnails_to_max_format_width(
  77. info['formats'], info['thumbnails'], r'(?<=/imgHandler/)\d+')
  78. description, _html = next(get_elements_text_and_html_by_attribute('class', 'description', webpage))
  79. if description and _html.startswith('<span '):
  80. info['description'] = description
  81. info['id'] = video_id
  82. info['display_id'] = display_id
  83. return info
  84. class TVOpenGrEmbedIE(TVOpenGrBaseIE):
  85. IE_NAME = 'tvopengr:embed'
  86. IE_DESC = 'tvopen.gr embedded videos'
  87. _VALID_URL = r'(?:https?:)?//(?:www\.|cdn\.|)(?:tvopen|ethnos).gr/embed/(?P<id>\d+)'
  88. _EMBED_REGEX = [rf'''<iframe[^>]+?src=(?P<_q1>["'])(?P<url>{_VALID_URL})(?P=_q1)''']
  89. _TESTS = [{
  90. 'url': 'https://cdn.ethnos.gr/embed/100963',
  91. 'md5': '2da147881f45571d81662d94d086628b',
  92. 'info_dict': {
  93. 'id': '100963',
  94. 'display_id': 'koronoiosapotoysdieythyntestonsxoleionselftestgiaosoysdenbrhkan',
  95. 'title': 'md5:2c71876fadf0cda6043da0da5fca2936',
  96. 'description': 'md5:17482b4432e5ed30eccd93b05d6ea509',
  97. 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/5804e07f-799a-4247-a696-33842c94ca37.jpg',
  98. 'ext': 'mp4',
  99. 'upload_date': '20220108',
  100. 'timestamp': 1641600000,
  101. },
  102. }]
  103. def _real_extract(self, url):
  104. video_id = self._match_id(url)
  105. return self._return_canonical_url(url, video_id)