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.

261 lines
9.3 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. determine_ext,
  9. int_or_none,
  10. parse_iso8601,
  11. parse_duration,
  12. remove_start,
  13. )
  14. class NowTVBaseIE(InfoExtractor):
  15. _VIDEO_FIELDS = (
  16. 'id', 'title', 'free', 'geoblocked', 'articleLong', 'articleShort',
  17. 'broadcastStartDate', 'seoUrl', 'duration', 'files',
  18. 'format.defaultImage169Format', 'format.defaultImage169Logo')
  19. def _extract_video(self, info, display_id=None):
  20. video_id = compat_str(info['id'])
  21. files = info['files']
  22. if not files:
  23. if info.get('geoblocked', False):
  24. raise ExtractorError(
  25. 'Video %s is not available from your location due to geo restriction' % video_id,
  26. expected=True)
  27. if not info.get('free', True):
  28. raise ExtractorError(
  29. 'Video %s is not available for free' % video_id, expected=True)
  30. formats = []
  31. for item in files['items']:
  32. if determine_ext(item['path']) != 'f4v':
  33. continue
  34. app, play_path = remove_start(item['path'], '/').split('/', 1)
  35. formats.append({
  36. 'url': 'rtmpe://fms.rtl.de',
  37. 'app': app,
  38. 'play_path': 'mp4:%s' % play_path,
  39. 'ext': 'flv',
  40. 'page_url': 'http://rtlnow.rtl.de',
  41. 'player_url': 'http://cdn.static-fra.de/now/vodplayer.swf',
  42. 'tbr': int_or_none(item.get('bitrate')),
  43. })
  44. self._sort_formats(formats)
  45. title = info['title']
  46. description = info.get('articleLong') or info.get('articleShort')
  47. timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
  48. duration = parse_duration(info.get('duration'))
  49. f = info.get('format', {})
  50. thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
  51. return {
  52. 'id': video_id,
  53. 'display_id': display_id or info.get('seoUrl'),
  54. 'title': title,
  55. 'description': description,
  56. 'thumbnail': thumbnail,
  57. 'timestamp': timestamp,
  58. 'duration': duration,
  59. 'formats': formats,
  60. }
  61. class NowTVIE(NowTVBaseIE):
  62. _WORKING = False
  63. _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/(?:(?:list/[^/]+|jahr/\d{4}/\d{1,2})/)?(?P<id>[^/]+)/(?:player|preview)'
  64. _TESTS = [{
  65. # rtl
  66. 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
  67. 'info_dict': {
  68. 'id': '203519',
  69. 'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
  70. 'ext': 'flv',
  71. 'title': 'Inka Bause stellt die neuen Bauern vor',
  72. 'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
  73. 'thumbnail': r're:^https?://.*\.jpg$',
  74. 'timestamp': 1432580700,
  75. 'upload_date': '20150525',
  76. 'duration': 2786,
  77. },
  78. 'params': {
  79. # rtmp download
  80. 'skip_download': True,
  81. },
  82. }, {
  83. # rtl2
  84. 'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player',
  85. 'info_dict': {
  86. 'id': '203481',
  87. 'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934',
  88. 'ext': 'flv',
  89. 'title': 'Berlin - Tag & Nacht (Folge 934)',
  90. 'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
  91. 'thumbnail': r're:^https?://.*\.jpg$',
  92. 'timestamp': 1432666800,
  93. 'upload_date': '20150526',
  94. 'duration': 2641,
  95. },
  96. 'params': {
  97. # rtmp download
  98. 'skip_download': True,
  99. },
  100. }, {
  101. # rtlnitro
  102. 'url': 'http://www.nowtv.de/rtlnitro/alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00/player',
  103. 'info_dict': {
  104. 'id': '165780',
  105. 'display_id': 'alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00',
  106. 'ext': 'flv',
  107. 'title': 'Hals- und Beinbruch',
  108. 'description': 'md5:b50d248efffe244e6f56737f0911ca57',
  109. 'thumbnail': r're:^https?://.*\.jpg$',
  110. 'timestamp': 1432415400,
  111. 'upload_date': '20150523',
  112. 'duration': 2742,
  113. },
  114. 'params': {
  115. # rtmp download
  116. 'skip_download': True,
  117. },
  118. }, {
  119. # superrtl
  120. 'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
  121. 'info_dict': {
  122. 'id': '99205',
  123. 'display_id': 'medicopter-117/angst',
  124. 'ext': 'flv',
  125. 'title': 'Angst!',
  126. 'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
  127. 'thumbnail': r're:^https?://.*\.jpg$',
  128. 'timestamp': 1222632900,
  129. 'upload_date': '20080928',
  130. 'duration': 3025,
  131. },
  132. 'params': {
  133. # rtmp download
  134. 'skip_download': True,
  135. },
  136. }, {
  137. # ntv
  138. 'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
  139. 'info_dict': {
  140. 'id': '203521',
  141. 'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
  142. 'ext': 'flv',
  143. 'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
  144. 'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
  145. 'thumbnail': r're:^https?://.*\.jpg$',
  146. 'timestamp': 1432751700,
  147. 'upload_date': '20150527',
  148. 'duration': 1083,
  149. },
  150. 'params': {
  151. # rtmp download
  152. 'skip_download': True,
  153. },
  154. }, {
  155. # vox
  156. 'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
  157. 'info_dict': {
  158. 'id': '128953',
  159. 'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
  160. 'ext': 'flv',
  161. 'title': "Büro-Fall / Chihuahua 'Joel'",
  162. 'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
  163. 'thumbnail': r're:^https?://.*\.jpg$',
  164. 'timestamp': 1432408200,
  165. 'upload_date': '20150523',
  166. 'duration': 3092,
  167. },
  168. 'params': {
  169. # rtmp download
  170. 'skip_download': True,
  171. },
  172. }, {
  173. 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview',
  174. 'only_matching': True,
  175. }, {
  176. 'url': 'http://www.nowtv.at/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview?return=/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
  177. 'only_matching': True,
  178. }, {
  179. 'url': 'http://www.nowtv.de/rtl2/echtzeit/list/aktuell/schnelles-geld-am-ende-der-welt/player',
  180. 'only_matching': True,
  181. }, {
  182. 'url': 'http://www.nowtv.de/rtl2/zuhause-im-glueck/jahr/2015/11/eine-erschuetternde-diagnose/player',
  183. 'only_matching': True,
  184. }]
  185. def _real_extract(self, url):
  186. mobj = re.match(self._VALID_URL, url)
  187. display_id = '%s/%s' % (mobj.group('show_id'), mobj.group('id'))
  188. info = self._download_json(
  189. 'https://api.nowtv.de/v3/movies/%s?fields=%s'
  190. % (display_id, ','.join(self._VIDEO_FIELDS)), display_id)
  191. return self._extract_video(info, display_id)
  192. class NowTVListIE(NowTVBaseIE):
  193. _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/list/(?P<id>[^?/#&]+)$'
  194. _SHOW_FIELDS = ('title', )
  195. _SEASON_FIELDS = ('id', 'headline', 'seoheadline', )
  196. _TESTS = [{
  197. 'url': 'http://www.nowtv.at/rtl/stern-tv/list/aktuell',
  198. 'info_dict': {
  199. 'id': '17006',
  200. 'title': 'stern TV - Aktuell',
  201. },
  202. 'playlist_count': 1,
  203. }, {
  204. 'url': 'http://www.nowtv.at/rtl/das-supertalent/list/free-staffel-8',
  205. 'info_dict': {
  206. 'id': '20716',
  207. 'title': 'Das Supertalent - FREE Staffel 8',
  208. },
  209. 'playlist_count': 14,
  210. }]
  211. def _real_extract(self, url):
  212. mobj = re.match(self._VALID_URL, url)
  213. show_id = mobj.group('show_id')
  214. season_id = mobj.group('id')
  215. fields = []
  216. fields.extend(self._SHOW_FIELDS)
  217. fields.extend('formatTabs.%s' % field for field in self._SEASON_FIELDS)
  218. fields.extend(
  219. 'formatTabs.formatTabPages.container.movies.%s' % field
  220. for field in self._VIDEO_FIELDS)
  221. list_info = self._download_json(
  222. 'https://api.nowtv.de/v3/formats/seo?fields=%s&name=%s.php'
  223. % (','.join(fields), show_id),
  224. season_id)
  225. season = next(
  226. season for season in list_info['formatTabs']['items']
  227. if season.get('seoheadline') == season_id)
  228. title = '%s - %s' % (list_info['title'], season['headline'])
  229. entries = []
  230. for container in season['formatTabPages']['items']:
  231. for info in ((container.get('container') or {}).get('movies') or {}).get('items') or []:
  232. entries.append(self._extract_video(info))
  233. return self.playlist_result(
  234. entries, compat_str(season.get('id') or season_id), title)