antenna.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from ..networking import HEADRequest
  4. from ..utils import (
  5. ExtractorError,
  6. determine_ext,
  7. make_archive_id,
  8. scale_thumbnails_to_max_format_width,
  9. )
  10. class AntennaBaseIE(InfoExtractor):
  11. def _download_and_extract_api_data(self, video_id, netloc, cid=None):
  12. info = self._download_json(f'{self.http_scheme()}//{netloc}{self._API_PATH}',
  13. video_id, query={'cid': cid or video_id})
  14. if not info.get('url'):
  15. raise ExtractorError(f'No source found for {video_id}')
  16. ext = determine_ext(info['url'])
  17. if ext == 'm3u8':
  18. formats, subs = self._extract_m3u8_formats_and_subtitles(info['url'], video_id, 'mp4')
  19. else:
  20. formats, subs = [{'url': info['url'], 'format_id': ext}], {}
  21. thumbnails = scale_thumbnails_to_max_format_width(
  22. formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+') if info.get('thumb') else []
  23. return {
  24. 'id': video_id,
  25. 'title': info.get('title'),
  26. 'thumbnails': thumbnails,
  27. 'formats': formats,
  28. 'subtitles': subs,
  29. }
  30. class AntennaGrWatchIE(AntennaBaseIE):
  31. IE_NAME = 'antenna:watch'
  32. IE_DESC = 'antenna.gr and ant1news.gr videos'
  33. _VALID_URL = r'https?://(?P<netloc>(?:www\.)?(?:antenna|ant1news)\.gr)/watch/(?P<id>\d+)/'
  34. _API_PATH = '/templates/data/player'
  35. _TESTS = [{
  36. 'url': 'https://www.ant1news.gr/watch/1506168/ant1-news-09112021-stis-18-45',
  37. 'md5': 'c472d9dd7cd233c63aff2ea42201cda6',
  38. 'info_dict': {
  39. 'id': '1506168',
  40. 'ext': 'mp4',
  41. 'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a',
  42. 'description': 'md5:18665af715a6dcfeac1d6153a44f16b0',
  43. 'thumbnail': r're:https://ant1media\.azureedge\.net/imgHandler/\d+/26d46bf6-8158-4f02-b197-7096c714b2de\.jpg',
  44. },
  45. }, {
  46. 'url': 'https://www.antenna.gr/watch/1643812/oi-prodotes-epeisodio-01',
  47. 'md5': '8f6f7dd3b1dba4d835ba990e25f31243',
  48. 'info_dict': {
  49. 'id': '1643812',
  50. 'ext': 'mp4',
  51. 'format_id': 'mp4',
  52. 'title': 'ΟΙ ΠΡΟΔΟΤΕΣ – ΕΠΕΙΣΟΔΙΟ 01',
  53. 'thumbnail': r're:https://ant1media\.azureedge\.net/imgHandler/\d+/b3d63096-e72d-43c4-87a0-00d4363d242f\.jpg',
  54. },
  55. }]
  56. def _real_extract(self, url):
  57. video_id, netloc = self._match_valid_url(url).group('id', 'netloc')
  58. webpage = self._download_webpage(url, video_id)
  59. info = self._download_and_extract_api_data(video_id, netloc)
  60. info['description'] = self._og_search_description(webpage, default=None)
  61. info['_old_archive_ids'] = [make_archive_id('Ant1NewsGrWatch', video_id)]
  62. return info
  63. class Ant1NewsGrArticleIE(AntennaBaseIE):
  64. IE_NAME = 'ant1newsgr:article'
  65. IE_DESC = 'ant1news.gr articles'
  66. _VALID_URL = r'https?://(?:www\.)?ant1news\.gr/[^/]+/article/(?P<id>\d+)/'
  67. _TESTS = [{
  68. 'url': 'https://www.ant1news.gr/afieromata/article/549468/o-tzeims-mpont-sta-meteora-oi-apeiles-kai-o-xesikomos-ton-kalogeron',
  69. 'md5': '57eb8d12181f0fa2b14b0b138e1de9b6',
  70. 'info_dict': {
  71. 'id': '_xvg/m_cmbatw=',
  72. 'ext': 'mp4',
  73. 'title': 'md5:a93e8ecf2e4073bfdffcb38f59945411',
  74. 'timestamp': 1666166520,
  75. 'upload_date': '20221019',
  76. 'thumbnail': 'https://ant1media.azureedge.net/imgHandler/1920/756206d2-d640-40e2-b201-3555abdfc0db.jpg',
  77. },
  78. }, {
  79. 'url': 'https://ant1news.gr/Society/article/620286/symmoria-anilikon-dikigoros-thymaton-ithelan-na-toys-apoteleiosoyn',
  80. 'info_dict': {
  81. 'id': '620286',
  82. 'title': 'md5:91fe569e952e4d146485740ae927662b',
  83. },
  84. 'playlist_mincount': 2,
  85. 'params': {
  86. 'skip_download': True,
  87. },
  88. }]
  89. def _real_extract(self, url):
  90. video_id = self._match_id(url)
  91. webpage = self._download_webpage(url, video_id)
  92. info = self._search_json_ld(webpage, video_id, expected_type='NewsArticle')
  93. embed_urls = list(Ant1NewsGrEmbedIE._extract_embed_urls(url, webpage))
  94. if not embed_urls:
  95. raise ExtractorError(f'no videos found for {video_id}', expected=True)
  96. return self.playlist_from_matches(
  97. embed_urls, video_id, info.get('title'), ie=Ant1NewsGrEmbedIE.ie_key(),
  98. video_kwargs={'url_transparent': True, 'timestamp': info.get('timestamp')})
  99. class Ant1NewsGrEmbedIE(AntennaBaseIE):
  100. IE_NAME = 'ant1newsgr:embed'
  101. IE_DESC = 'ant1news.gr embedded videos'
  102. _BASE_PLAYER_URL_RE = r'(?:https?:)?//(?:[a-zA-Z0-9\-]+\.)?(?:antenna|ant1news)\.gr/templates/pages/player'
  103. _VALID_URL = rf'{_BASE_PLAYER_URL_RE}\?([^#]+&)?cid=(?P<id>[^#&]+)'
  104. _EMBED_REGEX = [rf'<iframe[^>]+?src=(?P<_q1>["\'])(?P<url>{_BASE_PLAYER_URL_RE}\?(?:(?!(?P=_q1)).)+)(?P=_q1)']
  105. _API_PATH = '/templates/data/jsonPlayer'
  106. _TESTS = [{
  107. 'url': 'https://www.antenna.gr/templates/pages/player?cid=3f_li_c_az_jw_y_u=&w=670&h=377',
  108. 'md5': 'dfc58c3a11a5a9aad2ba316ed447def3',
  109. 'info_dict': {
  110. 'id': '3f_li_c_az_jw_y_u=',
  111. 'ext': 'mp4',
  112. 'title': 'md5:a30c93332455f53e1e84ae0724f0adf7',
  113. 'thumbnail': 'https://ant1media.azureedge.net/imgHandler/640/bbe31201-3f09-4a4e-87f5-8ad2159fffe2.jpg',
  114. },
  115. }]
  116. def _real_extract(self, url):
  117. video_id = self._match_id(url)
  118. canonical_url = self._request_webpage(
  119. HEADRequest(url), video_id,
  120. note='Resolve canonical player URL',
  121. errnote='Could not resolve canonical player URL').url
  122. _, netloc, _, _, query, _ = urllib.parse.urlparse(canonical_url)
  123. cid = urllib.parse.parse_qs(query)['cid'][0]
  124. return self._download_and_extract_api_data(video_id, netloc, cid=cid)