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.

169 lines
5.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. # superrtl
  53. 'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
  54. 'info_dict': {
  55. 'id': '99205',
  56. 'display_id': 'medicopter-117/angst',
  57. 'ext': 'mp4',
  58. 'title': 'Angst!',
  59. 'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
  60. 'thumbnail': 're:^https?://.*\.jpg$',
  61. 'timestamp': 1222632900,
  62. 'upload_date': '20080928',
  63. 'duration': 3025,
  64. },
  65. 'params': {
  66. # m3u8 download
  67. 'skip_download': True,
  68. },
  69. }, {
  70. # ntv
  71. 'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
  72. 'info_dict': {
  73. 'id': '203521',
  74. 'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
  75. 'ext': 'mp4',
  76. 'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
  77. 'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
  78. 'thumbnail': 're:^https?://.*\.jpg$',
  79. 'timestamp': 1432751700,
  80. 'upload_date': '20150527',
  81. 'duration': 1083,
  82. },
  83. 'params': {
  84. # m3u8 download
  85. 'skip_download': True,
  86. },
  87. }, {
  88. # vox
  89. 'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
  90. 'info_dict': {
  91. 'id': '128953',
  92. 'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
  93. 'ext': 'mp4',
  94. 'title': "Büro-Fall / Chihuahua 'Joel'",
  95. 'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
  96. 'thumbnail': 're:^https?://.*\.jpg$',
  97. 'timestamp': 1432408200,
  98. 'upload_date': '20150523',
  99. 'duration': 3092,
  100. },
  101. 'params': {
  102. # m3u8 download
  103. 'skip_download': True,
  104. },
  105. }]
  106. def _real_extract(self, url):
  107. mobj = re.match(self._VALID_URL, url)
  108. display_id = mobj.group('id')
  109. station = mobj.group('station')
  110. info = self._download_json(
  111. 'https://api.nowtv.de/v3/movies/%s?fields=*,format,files,breakpoints,paymentPaytypes,trailers,pictures' % display_id,
  112. display_id)
  113. video_id = compat_str(info['id'])
  114. if info.get('geoblocked'):
  115. raise ExtractorError(
  116. 'Video %s is not available from your location due to geo restriction' % video_id,
  117. expected=True)
  118. f = info.get('format', {})
  119. station = f.get('station') or station
  120. STATIONS = {
  121. 'rtl': 'rtlnow',
  122. 'rtl2': 'rtl2now',
  123. 'vox': 'voxnow',
  124. 'nitro': 'rtlnitronow',
  125. 'ntv': 'n-tvnow',
  126. 'superrtl': 'superrtlnow'
  127. }
  128. formats = []
  129. for item in info['files']['items']:
  130. item_path = remove_start(item['path'], '/')
  131. tbr = int_or_none(item['bitrate'])
  132. m3u8_url = 'http://hls.fra.%s.de/hls-vod-enc/%s.m3u8' % (STATIONS[station], item_path)
  133. m3u8_url = m3u8_url.replace('now/', 'now/videos/')
  134. formats.append({
  135. 'url': m3u8_url,
  136. 'format_id': '%s-%sk' % (item['id'], tbr),
  137. 'ext': 'mp4',
  138. 'tbr': tbr,
  139. })
  140. self._sort_formats(formats)
  141. title = info['title']
  142. description = info.get('articleLong') or info.get('articleShort')
  143. timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
  144. duration = parse_duration(info.get('duration'))
  145. thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
  146. return {
  147. 'id': video_id,
  148. 'display_id': display_id,
  149. 'title': title,
  150. 'description': description,
  151. 'thumbnail': thumbnail,
  152. 'timestamp': timestamp,
  153. 'duration': duration,
  154. 'formats': formats,
  155. }