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.

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