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.

170 lines
6.9 KiB

9 years ago
9 years ago
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. )
  8. class RtlNlIE(InfoExtractor):
  9. IE_NAME = 'rtl.nl'
  10. IE_DESC = 'rtl.nl and rtlxl.nl'
  11. _VALID_URL = r'''(?x)
  12. https?://(?:www\.)?
  13. (?:
  14. rtlxl\.nl/[^\#]*\#!/[^/]+/|
  15. rtl\.nl/(?:system/videoplayer/(?:[^/]+/)+(?:video_)?embed\.html\b.+?\buuid=|video/)
  16. )
  17. (?P<id>[0-9a-f-]+)'''
  18. _TESTS = [{
  19. 'url': 'http://www.rtlxl.nl/#!/rtl-nieuws-132237/82b1aad1-4a14-3d7b-b554-b0aed1b2c416',
  20. 'md5': '473d1946c1fdd050b2c0161a4b13c373',
  21. 'info_dict': {
  22. 'id': '82b1aad1-4a14-3d7b-b554-b0aed1b2c416',
  23. 'ext': 'mp4',
  24. 'title': 'RTL Nieuws',
  25. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  26. 'timestamp': 1461951000,
  27. 'upload_date': '20160429',
  28. 'duration': 1167.96,
  29. },
  30. }, {
  31. # best format avaialble a3t
  32. 'url': 'http://www.rtl.nl/system/videoplayer/derden/rtlnieuws/video_embed.html#uuid=84ae5571-ac25-4225-ae0c-ef8d9efb2aed/autoplay=false',
  33. 'md5': 'dea7474214af1271d91ef332fb8be7ea',
  34. 'info_dict': {
  35. 'id': '84ae5571-ac25-4225-ae0c-ef8d9efb2aed',
  36. 'ext': 'mp4',
  37. 'timestamp': 1424039400,
  38. 'title': 'RTL Nieuws - Nieuwe beelden Kopenhagen: chaos direct na aanslag',
  39. 'thumbnail': r're:^https?://screenshots\.rtl\.nl/(?:[^/]+/)*sz=[0-9]+x[0-9]+/uuid=84ae5571-ac25-4225-ae0c-ef8d9efb2aed$',
  40. 'upload_date': '20150215',
  41. 'description': 'Er zijn nieuwe beelden vrijgegeven die vlak na de aanslag in Kopenhagen zijn gemaakt. Op de video is goed te zien hoe omstanders zich bekommeren om één van de slachtoffers, terwijl de eerste agenten ter plaatse komen.',
  42. }
  43. }, {
  44. # empty synopsis and missing episodes (see https://github.com/rg3/youtube-dl/issues/6275)
  45. # best format available nettv
  46. 'url': 'http://www.rtl.nl/system/videoplayer/derden/rtlnieuws/video_embed.html#uuid=f536aac0-1dc3-4314-920e-3bd1c5b3811a/autoplay=false',
  47. 'info_dict': {
  48. 'id': 'f536aac0-1dc3-4314-920e-3bd1c5b3811a',
  49. 'ext': 'mp4',
  50. 'title': 'RTL Nieuws - Meer beelden van overval juwelier',
  51. 'thumbnail': r're:^https?://screenshots\.rtl\.nl/(?:[^/]+/)*sz=[0-9]+x[0-9]+/uuid=f536aac0-1dc3-4314-920e-3bd1c5b3811a$',
  52. 'timestamp': 1437233400,
  53. 'upload_date': '20150718',
  54. 'duration': 30.474,
  55. },
  56. 'params': {
  57. 'skip_download': True,
  58. },
  59. }, {
  60. # encrypted m3u8 streams, georestricted
  61. 'url': 'http://www.rtlxl.nl/#!/afl-2-257632/52a74543-c504-4cde-8aa8-ec66fe8d68a7',
  62. 'only_matching': True,
  63. }, {
  64. 'url': 'http://www.rtl.nl/system/videoplayer/derden/embed.html#!/uuid=bb0353b0-d6a4-1dad-90e9-18fe75b8d1f0',
  65. 'only_matching': True,
  66. }, {
  67. 'url': 'http://rtlxl.nl/?_ga=1.204735956.572365465.1466978370#!/rtl-nieuws-132237/3c487912-023b-49ac-903e-2c5d79f8410f',
  68. 'only_matching': True,
  69. }, {
  70. 'url': 'https://www.rtl.nl/video/c603c9c2-601d-4b5e-8175-64f1e942dc7d/',
  71. 'only_matching': True,
  72. }]
  73. def _real_extract(self, url):
  74. uuid = self._match_id(url)
  75. info = self._download_json(
  76. 'http://www.rtl.nl/system/s4m/vfd/version=2/uuid=%s/fmt=adaptive/' % uuid,
  77. uuid)
  78. material = info['material'][0]
  79. title = info['abstracts'][0]['name']
  80. subtitle = material.get('title')
  81. if subtitle:
  82. title += ' - %s' % subtitle
  83. description = material.get('synopsis')
  84. meta = info.get('meta', {})
  85. # m3u8 streams are encrypted and may not be handled properly by older ffmpeg/avconv.
  86. # To workaround this previously adaptive -> flash trick was used to obtain
  87. # unencrypted m3u8 streams (see https://github.com/rg3/youtube-dl/issues/4118)
  88. # and bypass georestrictions as well.
  89. # Currently, unencrypted m3u8 playlists are (intentionally?) invalid and therefore
  90. # unusable albeit can be fixed by simple string replacement (see
  91. # https://github.com/rg3/youtube-dl/pull/6337)
  92. # Since recent ffmpeg and avconv handle encrypted streams just fine encrypted
  93. # streams are used now.
  94. videopath = material['videopath']
  95. m3u8_url = meta.get('videohost', 'http://manifest.us.rtl.nl') + videopath
  96. formats = self._extract_m3u8_formats(
  97. m3u8_url, uuid, 'mp4', m3u8_id='hls', fatal=False)
  98. video_urlpart = videopath.split('/adaptive/')[1][:-5]
  99. PG_URL_TEMPLATE = 'http://pg.us.rtl.nl/rtlxl/network/%s/progressive/%s.mp4'
  100. PG_FORMATS = (
  101. ('a2t', 512, 288),
  102. ('a3t', 704, 400),
  103. ('nettv', 1280, 720),
  104. )
  105. def pg_format(format_id, width, height):
  106. return {
  107. 'url': PG_URL_TEMPLATE % (format_id, video_urlpart),
  108. 'format_id': 'pg-%s' % format_id,
  109. 'protocol': 'http',
  110. 'width': width,
  111. 'height': height,
  112. }
  113. if not formats:
  114. formats = [pg_format(*pg_tuple) for pg_tuple in PG_FORMATS]
  115. else:
  116. pg_formats = []
  117. for format_id, width, height in PG_FORMATS:
  118. try:
  119. # Find hls format with the same width and height corresponding
  120. # to progressive format and copy metadata from it.
  121. f = next(f for f in formats if f.get('height') == height)
  122. # hls formats may have invalid width
  123. f['width'] = width
  124. f_copy = f.copy()
  125. f_copy.update(pg_format(format_id, width, height))
  126. pg_formats.append(f_copy)
  127. except StopIteration:
  128. # Missing hls format does mean that no progressive format with
  129. # such width and height exists either.
  130. pass
  131. formats.extend(pg_formats)
  132. self._sort_formats(formats)
  133. thumbnails = []
  134. for p in ('poster_base_url', '"thumb_base_url"'):
  135. if not meta.get(p):
  136. continue
  137. thumbnails.append({
  138. 'url': self._proto_relative_url(meta[p] + uuid),
  139. 'width': int_or_none(self._search_regex(
  140. r'/sz=([0-9]+)', meta[p], 'thumbnail width', fatal=False)),
  141. 'height': int_or_none(self._search_regex(
  142. r'/sz=[0-9]+x([0-9]+)',
  143. meta[p], 'thumbnail height', fatal=False))
  144. })
  145. return {
  146. 'id': uuid,
  147. 'title': title,
  148. 'formats': formats,
  149. 'timestamp': material['original_date'],
  150. 'description': description,
  151. 'duration': parse_duration(material.get('duration')),
  152. 'thumbnails': thumbnails,
  153. }