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.

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