phoenix.py 4.8 KB

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