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.

192 lines
6.6 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. remove_start,
  12. )
  13. class NowTVIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?nowtv\.de/(?P<station>rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/player'
  15. _TESTS = [{
  16. # rtl
  17. 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
  18. 'info_dict': {
  19. 'id': '203519',
  20. 'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
  21. 'ext': 'mp4',
  22. 'title': 'Die neuen Bauern und eine Hochzeit',
  23. 'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
  24. 'thumbnail': 're:^https?://.*\.jpg$',
  25. 'timestamp': 1432580700,
  26. 'upload_date': '20150525',
  27. 'duration': 2786,
  28. },
  29. 'params': {
  30. # m3u8 download
  31. 'skip_download': True,
  32. },
  33. }, {
  34. # rtl2
  35. 'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player',
  36. 'info_dict': {
  37. 'id': '203481',
  38. 'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934',
  39. 'ext': 'mp4',
  40. 'title': 'Berlin - Tag & Nacht (Folge 934)',
  41. 'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
  42. 'thumbnail': 're:^https?://.*\.jpg$',
  43. 'timestamp': 1432666800,
  44. 'upload_date': '20150526',
  45. 'duration': 2641,
  46. },
  47. 'params': {
  48. # m3u8 download
  49. 'skip_download': True,
  50. },
  51. }, {
  52. # rtlnitro
  53. 'url': 'http://www.nowtv.de/rtlnitro/alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00/player',
  54. 'info_dict': {
  55. 'id': '165780',
  56. 'display_id': 'alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00',
  57. 'ext': 'mp4',
  58. 'title': 'Hals- und Beinbruch',
  59. 'description': 'md5:b50d248efffe244e6f56737f0911ca57',
  60. 'thumbnail': 're:^https?://.*\.jpg$',
  61. 'timestamp': 1432415400,
  62. 'upload_date': '20150523',
  63. 'duration': 2742,
  64. },
  65. 'params': {
  66. # m3u8 download
  67. 'skip_download': True,
  68. },
  69. }, {
  70. # superrtl
  71. 'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
  72. 'info_dict': {
  73. 'id': '99205',
  74. 'display_id': 'medicopter-117/angst',
  75. 'ext': 'mp4',
  76. 'title': 'Angst!',
  77. 'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
  78. 'thumbnail': 're:^https?://.*\.jpg$',
  79. 'timestamp': 1222632900,
  80. 'upload_date': '20080928',
  81. 'duration': 3025,
  82. },
  83. 'params': {
  84. # m3u8 download
  85. 'skip_download': True,
  86. },
  87. }, {
  88. # ntv
  89. 'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
  90. 'info_dict': {
  91. 'id': '203521',
  92. 'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
  93. 'ext': 'mp4',
  94. 'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
  95. 'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
  96. 'thumbnail': 're:^https?://.*\.jpg$',
  97. 'timestamp': 1432751700,
  98. 'upload_date': '20150527',
  99. 'duration': 1083,
  100. },
  101. 'params': {
  102. # m3u8 download
  103. 'skip_download': True,
  104. },
  105. }, {
  106. # vox
  107. 'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
  108. 'info_dict': {
  109. 'id': '128953',
  110. 'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
  111. 'ext': 'mp4',
  112. 'title': "Büro-Fall / Chihuahua 'Joel'",
  113. 'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
  114. 'thumbnail': 're:^https?://.*\.jpg$',
  115. 'timestamp': 1432408200,
  116. 'upload_date': '20150523',
  117. 'duration': 3092,
  118. },
  119. 'params': {
  120. # m3u8 download
  121. 'skip_download': True,
  122. },
  123. }]
  124. def _real_extract(self, url):
  125. mobj = re.match(self._VALID_URL, url)
  126. display_id = mobj.group('id')
  127. station = mobj.group('station')
  128. info = self._download_json(
  129. 'https://api.nowtv.de/v3/movies/%s?fields=id,title,free,geoblocked,articleLong,articleShort,broadcastStartDate,seoUrl,duration,format,files' % display_id,
  130. display_id)
  131. video_id = compat_str(info['id'])
  132. files = info['files']
  133. if not files:
  134. if info.get('geoblocked', False):
  135. raise ExtractorError(
  136. 'Video %s is not available from your location due to geo restriction' % video_id,
  137. expected=True)
  138. if not info.get('free', True):
  139. raise ExtractorError(
  140. 'Video %s is not available for free' % video_id, expected=True)
  141. f = info.get('format', {})
  142. station = f.get('station') or station
  143. STATIONS = {
  144. 'rtl': 'rtlnow',
  145. 'rtl2': 'rtl2now',
  146. 'vox': 'voxnow',
  147. 'nitro': 'rtlnitronow',
  148. 'ntv': 'n-tvnow',
  149. 'superrtl': 'superrtlnow'
  150. }
  151. formats = []
  152. for item in files['items']:
  153. item_path = remove_start(item['path'], '/')
  154. tbr = int_or_none(item['bitrate'])
  155. m3u8_url = 'http://hls.fra.%s.de/hls-vod-enc/%s.m3u8' % (STATIONS[station], item_path)
  156. m3u8_url = m3u8_url.replace('now/', 'now/videos/')
  157. formats.append({
  158. 'url': m3u8_url,
  159. 'format_id': '%s-%sk' % (item['id'], tbr),
  160. 'ext': 'mp4',
  161. 'tbr': tbr,
  162. })
  163. self._sort_formats(formats)
  164. title = info['title']
  165. description = info.get('articleLong') or info.get('articleShort')
  166. timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
  167. duration = parse_duration(info.get('duration'))
  168. thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
  169. return {
  170. 'id': video_id,
  171. 'display_id': display_id,
  172. 'title': title,
  173. 'description': description,
  174. 'thumbnail': thumbnail,
  175. 'timestamp': timestamp,
  176. 'duration': duration,
  177. 'formats': formats,
  178. }