You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
6.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. ExtractorError,
  8. parse_iso8601,
  9. parse_duration,
  10. update_url_query,
  11. )
  12. class TVNowBaseIE(InfoExtractor):
  13. _VIDEO_FIELDS = (
  14. 'id', 'title', 'free', 'geoblocked', 'articleLong', 'articleShort',
  15. 'broadcastStartDate', 'isDrm', 'duration', 'manifest.dashclear',
  16. 'format.defaultImage169Format', 'format.defaultImage169Logo')
  17. def _call_api(self, path, video_id, query):
  18. return self._download_json(
  19. 'https://api.tvnow.de/v3/' + path,
  20. video_id, query=query)
  21. def _extract_video(self, info, display_id):
  22. video_id = compat_str(info['id'])
  23. title = info['title']
  24. mpd_url = info['manifest']['dashclear']
  25. if not mpd_url:
  26. if info.get('isDrm'):
  27. raise ExtractorError(
  28. 'Video %s is DRM protected' % video_id, expected=True)
  29. if info.get('geoblocked'):
  30. raise ExtractorError(
  31. 'Video %s is not available from your location due to geo restriction' % video_id,
  32. expected=True)
  33. if not info.get('free', True):
  34. raise ExtractorError(
  35. 'Video %s is not available for free' % video_id, expected=True)
  36. mpd_url = update_url_query(mpd_url, {'filter': ''})
  37. formats = self._extract_mpd_formats(mpd_url, video_id, mpd_id='dash', fatal=False)
  38. formats.extend(self._extract_ism_formats(
  39. mpd_url.replace('dash.', 'hss.').replace('/.mpd', '/Manifest'),
  40. video_id, ism_id='mss', fatal=False))
  41. formats.extend(self._extract_m3u8_formats(
  42. mpd_url.replace('dash.', 'hls.').replace('/.mpd', '/.m3u8'),
  43. video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  44. self._sort_formats(formats)
  45. description = info.get('articleLong') or info.get('articleShort')
  46. timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
  47. duration = parse_duration(info.get('duration'))
  48. f = info.get('format', {})
  49. thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
  50. return {
  51. 'id': video_id,
  52. 'display_id': display_id,
  53. 'title': title,
  54. 'description': description,
  55. 'thumbnail': thumbnail,
  56. 'timestamp': timestamp,
  57. 'duration': duration,
  58. 'formats': formats,
  59. }
  60. class TVNowIE(TVNowBaseIE):
  61. _VALID_URL = r'https?://(?:www\.)?tvnow\.(?:de|at|ch)/(?:rtl(?:2|plus)?|nitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/(?:(?:list/[^/]+|jahr/\d{4}/\d{1,2})/)?(?P<id>[^/]+)/(?:player|preview)'
  62. _TESTS = [{
  63. # rtl
  64. 'url': 'https://www.tvnow.de/rtl/alarm-fuer-cobra-11/freier-fall/player?return=/rtl',
  65. 'info_dict': {
  66. 'id': '385314',
  67. 'display_id': 'alarm-fuer-cobra-11/freier-fall',
  68. 'ext': 'mp4',
  69. 'title': 'Freier Fall',
  70. 'description': 'md5:8c2d8f727261adf7e0dc18366124ca02',
  71. 'thumbnail': r're:^https?://.*\.jpg$',
  72. 'timestamp': 1512677700,
  73. 'upload_date': '20171207',
  74. 'duration': 2862.0,
  75. },
  76. }, {
  77. # rtl2
  78. 'url': 'https://www.tvnow.de/rtl2/armes-deutschland/episode-0008/player',
  79. 'only_matching': 'True',
  80. }, {
  81. # rtlnitro
  82. 'url': 'https://www.tvnow.de/nitro/alarm-fuer-cobra-11-die-autobahnpolizei/auf-eigene-faust-pilot/player',
  83. 'only_matching': 'True',
  84. }, {
  85. # superrtl
  86. 'url': 'https://www.tvnow.de/superrtl/die-lustigsten-schlamassel-der-welt/u-a-ketchup-effekt/player',
  87. 'only_matching': 'True',
  88. }, {
  89. # ntv
  90. 'url': 'https://www.tvnow.de/ntv/startup-news/goetter-in-weiss/player',
  91. 'only_matching': 'True',
  92. }, {
  93. # vox
  94. 'url': 'https://www.tvnow.de/vox/auto-mobil/neues-vom-automobilmarkt-2017-11-19-17-00-00/player',
  95. 'only_matching': 'True',
  96. }, {
  97. # rtlplus
  98. 'url': 'https://www.tvnow.de/rtlplus/op-ruft-dr-bruckner/die-vernaehte-frau/player',
  99. 'only_matching': 'True',
  100. }]
  101. def _real_extract(self, url):
  102. display_id = '%s/%s' % re.match(self._VALID_URL, url).groups()
  103. info = self._call_api(
  104. 'movies/' + display_id, display_id, query={
  105. 'fields': ','.join(self._VIDEO_FIELDS),
  106. })
  107. return self._extract_video(info, display_id)
  108. class TVNowListIE(TVNowBaseIE):
  109. _VALID_URL = r'(?P<base_url>https?://(?:www\.)?tvnow\.(?:de|at|ch)/(?:rtl(?:2|plus)?|nitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/)list/(?P<id>[^?/#&]+)$'
  110. _SHOW_FIELDS = ('title', )
  111. _SEASON_FIELDS = ('id', 'headline', 'seoheadline', )
  112. _VIDEO_FIELDS = ('id', 'headline', 'seoUrl', )
  113. _TESTS = [{
  114. 'url': 'https://www.tvnow.de/rtl/30-minuten-deutschland/list/aktuell',
  115. 'info_dict': {
  116. 'id': '28296',
  117. 'title': '30 Minuten Deutschland - Aktuell',
  118. },
  119. 'playlist_mincount': 1,
  120. }]
  121. def _real_extract(self, url):
  122. base_url, show_id, season_id = re.match(self._VALID_URL, url).groups()
  123. fields = []
  124. fields.extend(self._SHOW_FIELDS)
  125. fields.extend('formatTabs.%s' % field for field in self._SEASON_FIELDS)
  126. fields.extend(
  127. 'formatTabs.formatTabPages.container.movies.%s' % field
  128. for field in self._VIDEO_FIELDS)
  129. list_info = self._call_api(
  130. 'formats/seo', season_id, query={
  131. 'fields': ','.join(fields),
  132. 'name': show_id + '.php'
  133. })
  134. season = next(
  135. season for season in list_info['formatTabs']['items']
  136. if season.get('seoheadline') == season_id)
  137. title = '%s - %s' % (list_info['title'], season['headline'])
  138. entries = []
  139. for container in season['formatTabPages']['items']:
  140. for info in ((container.get('container') or {}).get('movies') or {}).get('items') or []:
  141. seo_url = info.get('seoUrl')
  142. if not seo_url:
  143. continue
  144. entries.append(self.url_result(
  145. base_url + seo_url + '/player', 'TVNow', info.get('id')))
  146. return self.playlist_result(
  147. entries, compat_str(season.get('id') or season_id), title)