phoenix.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import re
  2. from .youtube import YoutubeIE
  3. from .zdf import ZDFBaseIE
  4. from ..utils import (
  5. int_or_none,
  6. merge_dicts,
  7. try_get,
  8. unified_timestamp,
  9. urljoin,
  10. )
  11. class PhoenixIE(ZDFBaseIE):
  12. IE_NAME = 'phoenix.de'
  13. _VALID_URL = r'https?://(?:www\.)?phoenix\.de/(?:[^/]+/)*[^/?#&]*-a-(?P<id>\d+)\.html'
  14. _TESTS = [{
  15. # Same as https://www.zdf.de/politik/phoenix-sendungen/wohin-fuehrt-der-protest-in-der-pandemie-100.html
  16. 'url': 'https://www.phoenix.de/sendungen/ereignisse/corona-nachgehakt/wohin-fuehrt-der-protest-in-der-pandemie-a-2050630.html',
  17. 'md5': '34ec321e7eb34231fd88616c65c92db0',
  18. 'info_dict': {
  19. 'id': '210222_phx_nachgehakt_corona_protest',
  20. 'ext': 'mp4',
  21. 'title': 'Wohin führt der Protest in der Pandemie?',
  22. 'description': 'md5:7d643fe7f565e53a24aac036b2122fbd',
  23. 'duration': 1691,
  24. 'timestamp': 1613902500,
  25. 'upload_date': '20210221',
  26. 'uploader': 'Phoenix',
  27. 'series': 'corona nachgehakt',
  28. 'episode': 'Wohin führt der Protest in der Pandemie?',
  29. },
  30. }, {
  31. # Youtube embed
  32. 'url': 'https://www.phoenix.de/sendungen/gespraeche/phoenix-streitgut-brennglas-corona-a-1965505.html',
  33. 'info_dict': {
  34. 'id': 'hMQtqFYjomk',
  35. 'ext': 'mp4',
  36. 'title': 'phoenix streitgut: Brennglas Corona - Wie gerecht ist unsere Gesellschaft?',
  37. 'description': 'md5:ac7a02e2eb3cb17600bc372e4ab28fdd',
  38. 'duration': 3509,
  39. 'upload_date': '20201219',
  40. 'uploader': 'phoenix',
  41. 'uploader_id': 'phoenix',
  42. },
  43. 'params': {
  44. 'skip_download': True,
  45. },
  46. }, {
  47. 'url': 'https://www.phoenix.de/entwicklungen-in-russland-a-2044720.html',
  48. 'only_matching': True,
  49. }, {
  50. # no media
  51. 'url': 'https://www.phoenix.de/sendungen/dokumentationen/mit-dem-jumbo-durch-die-nacht-a-89625.html',
  52. 'only_matching': True,
  53. }, {
  54. # Same as https://www.zdf.de/politik/phoenix-sendungen/die-gesten-der-maechtigen-100.html
  55. 'url': 'https://www.phoenix.de/sendungen/dokumentationen/gesten-der-maechtigen-i-a-89468.html?ref=suche',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. article_id = self._match_id(url)
  60. article = self._download_json(
  61. f'https://www.phoenix.de/response/id/{article_id}', article_id,
  62. 'Downloading article JSON')
  63. video = article['absaetze'][0]
  64. title = video.get('titel') or article.get('subtitel')
  65. if video.get('typ') == 'video-youtube':
  66. video_id = video['id']
  67. return self.url_result(
  68. video_id, ie=YoutubeIE.ie_key(), video_id=video_id,
  69. video_title=title)
  70. video_id = str(video.get('basename') or video.get('content'))
  71. details = self._download_json(
  72. 'https://www.phoenix.de/php/mediaplayer/data/beitrags_details.php',
  73. video_id, 'Downloading details JSON', query={
  74. 'ak': 'web',
  75. 'ptmd': 'true',
  76. 'id': video_id,
  77. 'profile': 'player2',
  78. })
  79. title = title or details['title']
  80. content_id = details['tracking']['nielsen']['content']['assetid']
  81. info = self._extract_ptmd(
  82. f'https://tmd.phoenix.de/tmd/2/ngplayer_2_3/vod/ptmd/phoenix/{content_id}',
  83. content_id, None, url)
  84. duration = int_or_none(try_get(
  85. details, lambda x: x['tracking']['nielsen']['content']['length']))
  86. timestamp = unified_timestamp(details.get('editorialDate'))
  87. series = try_get(
  88. details, lambda x: x['tracking']['nielsen']['content']['program'],
  89. str)
  90. episode = title if details.get('contentType') == 'episode' else None
  91. thumbnails = []
  92. teaser_images = try_get(details, lambda x: x['teaserImageRef']['layouts'], dict) or {}
  93. for thumbnail_key, thumbnail_url in teaser_images.items():
  94. thumbnail_url = urljoin(url, thumbnail_url)
  95. if not thumbnail_url:
  96. continue
  97. thumbnail = {
  98. 'url': thumbnail_url,
  99. }
  100. m = re.match('^([0-9]+)x([0-9]+)$', thumbnail_key)
  101. if m:
  102. thumbnail['width'] = int(m.group(1))
  103. thumbnail['height'] = int(m.group(2))
  104. thumbnails.append(thumbnail)
  105. return merge_dicts(info, {
  106. 'id': content_id,
  107. 'title': title,
  108. 'description': details.get('leadParagraph'),
  109. 'duration': duration,
  110. 'thumbnails': thumbnails,
  111. 'timestamp': timestamp,
  112. 'uploader': details.get('tvService'),
  113. 'series': series,
  114. 'episode': episode,
  115. })