rtlnl.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/6e4203a6-0a5e-3596-8424-c599a59e0677',
  20. 'md5': 'cc16baa36a6c169391f0764fa6b16654',
  21. 'info_dict': {
  22. 'id': '6e4203a6-0a5e-3596-8424-c599a59e0677',
  23. 'ext': 'mp4',
  24. 'title': 'RTL Nieuws - Laat',
  25. 'description': 'md5:6b61f66510c8889923b11f2778c72dc5',
  26. 'timestamp': 1408051800,
  27. 'upload_date': '20140814',
  28. 'duration': 576.880,
  29. },
  30. }, {
  31. 'url': 'http://www.rtl.nl/system/videoplayer/derden/rtlnieuws/video_embed.html#uuid=84ae5571-ac25-4225-ae0c-ef8d9efb2aed/autoplay=false',
  32. 'md5': 'dea7474214af1271d91ef332fb8be7ea',
  33. 'info_dict': {
  34. 'id': '84ae5571-ac25-4225-ae0c-ef8d9efb2aed',
  35. 'ext': 'mp4',
  36. 'timestamp': 1424039400,
  37. 'title': 'RTL Nieuws - Nieuwe beelden Kopenhagen: chaos direct na aanslag',
  38. 'thumbnail': 're:^https?://screenshots\.rtl\.nl/system/thumb/sz=[0-9]+x[0-9]+/uuid=84ae5571-ac25-4225-ae0c-ef8d9efb2aed$',
  39. 'upload_date': '20150215',
  40. '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.',
  41. }
  42. }, {
  43. # encrypted m3u8 streams
  44. 'url': 'http://www.rtlxl.nl/#!/afl-2-257632/52a74543-c504-4cde-8aa8-ec66fe8d68a7',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://www.rtl.nl/system/videoplayer/derden/embed.html#!/uuid=bb0353b0-d6a4-1dad-90e9-18fe75b8d1f0',
  48. 'only_matching': True,
  49. }]
  50. def _real_extract(self, url):
  51. uuid = self._match_id(url)
  52. info = self._download_json(
  53. 'http://www.rtl.nl/system/s4m/vfd/version=2/uuid=%s/fmt=adaptive/' % uuid,
  54. uuid)
  55. material = info['material'][0]
  56. progname = info['abstracts'][0]['name']
  57. subtitle = material['title'] or info['episodes'][0]['name']
  58. description = material.get('synopsis') or info['episodes'][0]['synopsis']
  59. meta = info.get('meta', {})
  60. # Use unencrypted m3u8 streams (See https://github.com/rg3/youtube-dl/issues/4118)
  61. videopath = material['videopath'].replace('/adaptive/', '/flash/')
  62. m3u8_url = meta.get('videohost', 'http://manifest.us.rtl.nl') + videopath
  63. formats = self._extract_m3u8_formats(m3u8_url, uuid, ext='mp4')
  64. video_urlpart = videopath.split('/flash/')[1][:-5]
  65. PG_URL_TEMPLATE = 'http://pg.us.rtl.nl/rtlxl/network/%s/progressive/%s.mp4'
  66. formats.extend([
  67. {
  68. 'url': PG_URL_TEMPLATE % ('a2m', video_urlpart),
  69. 'format_id': 'pg-sd',
  70. },
  71. {
  72. 'url': PG_URL_TEMPLATE % ('a3m', video_urlpart),
  73. 'format_id': 'pg-hd',
  74. 'quality': 0,
  75. }
  76. ])
  77. self._sort_formats(formats)
  78. thumbnails = []
  79. for p in ('poster_base_url', '"thumb_base_url"'):
  80. if not meta.get(p):
  81. continue
  82. thumbnails.append({
  83. 'url': self._proto_relative_url(meta[p] + uuid),
  84. 'width': int_or_none(self._search_regex(
  85. r'/sz=([0-9]+)', meta[p], 'thumbnail width', fatal=False)),
  86. 'height': int_or_none(self._search_regex(
  87. r'/sz=[0-9]+x([0-9]+)',
  88. meta[p], 'thumbnail height', fatal=False))
  89. })
  90. return {
  91. 'id': uuid,
  92. 'title': '%s - %s' % (progname, subtitle),
  93. 'formats': formats,
  94. 'timestamp': material['original_date'],
  95. 'description': description,
  96. 'duration': parse_duration(material.get('duration')),
  97. 'thumbnails': thumbnails,
  98. }