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.

167 lines
6.8 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=
  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': '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': '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. def _real_extract(self, url):
  71. uuid = self._match_id(url)
  72. info = self._download_json(
  73. 'http://www.rtl.nl/system/s4m/vfd/version=2/uuid=%s/fmt=adaptive/' % uuid,
  74. uuid)
  75. material = info['material'][0]
  76. title = info['abstracts'][0]['name']
  77. subtitle = material.get('title')
  78. if subtitle:
  79. title += ' - %s' % subtitle
  80. description = material.get('synopsis')
  81. meta = info.get('meta', {})
  82. # m3u8 streams are encrypted and may not be handled properly by older ffmpeg/avconv.
  83. # To workaround this previously adaptive -> flash trick was used to obtain
  84. # unencrypted m3u8 streams (see https://github.com/rg3/youtube-dl/issues/4118)
  85. # and bypass georestrictions as well.
  86. # Currently, unencrypted m3u8 playlists are (intentionally?) invalid and therefore
  87. # unusable albeit can be fixed by simple string replacement (see
  88. # https://github.com/rg3/youtube-dl/pull/6337)
  89. # Since recent ffmpeg and avconv handle encrypted streams just fine encrypted
  90. # streams are used now.
  91. videopath = material['videopath']
  92. m3u8_url = meta.get('videohost', 'http://manifest.us.rtl.nl') + videopath
  93. formats = self._extract_m3u8_formats(
  94. m3u8_url, uuid, 'mp4', m3u8_id='hls', fatal=False)
  95. video_urlpart = videopath.split('/adaptive/')[1][:-5]
  96. PG_URL_TEMPLATE = 'http://pg.us.rtl.nl/rtlxl/network/%s/progressive/%s.mp4'
  97. PG_FORMATS = (
  98. ('a2t', 512, 288),
  99. ('a3t', 704, 400),
  100. ('nettv', 1280, 720),
  101. )
  102. def pg_format(format_id, width, height):
  103. return {
  104. 'url': PG_URL_TEMPLATE % (format_id, video_urlpart),
  105. 'format_id': 'pg-%s' % format_id,
  106. 'protocol': 'http',
  107. 'width': width,
  108. 'height': height,
  109. }
  110. if not formats:
  111. formats = [pg_format(*pg_tuple) for pg_tuple in PG_FORMATS]
  112. else:
  113. pg_formats = []
  114. for format_id, width, height in PG_FORMATS:
  115. try:
  116. # Find hls format with the same width and height corresponding
  117. # to progressive format and copy metadata from it.
  118. f = next(f for f in formats if f.get('height') == height)
  119. # hls formats may have invalid width
  120. f['width'] = width
  121. f_copy = f.copy()
  122. f_copy.update(pg_format(format_id, width, height))
  123. pg_formats.append(f_copy)
  124. except StopIteration:
  125. # Missing hls format does mean that no progressive format with
  126. # such width and height exists either.
  127. pass
  128. formats.extend(pg_formats)
  129. self._sort_formats(formats)
  130. thumbnails = []
  131. for p in ('poster_base_url', '"thumb_base_url"'):
  132. if not meta.get(p):
  133. continue
  134. thumbnails.append({
  135. 'url': self._proto_relative_url(meta[p] + uuid),
  136. 'width': int_or_none(self._search_regex(
  137. r'/sz=([0-9]+)', meta[p], 'thumbnail width', fatal=False)),
  138. 'height': int_or_none(self._search_regex(
  139. r'/sz=[0-9]+x([0-9]+)',
  140. meta[p], 'thumbnail height', fatal=False))
  141. })
  142. return {
  143. 'id': uuid,
  144. 'title': title,
  145. 'formats': formats,
  146. 'timestamp': material['original_date'],
  147. 'description': description,
  148. 'duration': parse_duration(material.get('duration')),
  149. 'thumbnails': thumbnails,
  150. }