logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

phoenix.py (5018B)


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