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.

138 lines
4.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. unified_strdate,
  6. parse_duration,
  7. qualities,
  8. url_basename,
  9. )
  10. class NPOIE(InfoExtractor):
  11. IE_NAME = 'npo.nl'
  12. _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
  16. 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
  17. 'info_dict': {
  18. 'id': 'VPWON_1220719',
  19. 'ext': 'm4v',
  20. 'title': 'Nieuwsuur',
  21. 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
  22. 'upload_date': '20140622',
  23. },
  24. },
  25. {
  26. 'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800',
  27. 'md5': 'da50a5787dbfc1603c4ad80f31c5120b',
  28. 'info_dict': {
  29. 'id': 'VARA_101191800',
  30. 'ext': 'm4v',
  31. 'title': 'De Mega Mike & Mega Thomas show',
  32. 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4',
  33. 'upload_date': '20090227',
  34. 'duration': 2400,
  35. },
  36. },
  37. {
  38. 'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289',
  39. 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
  40. 'info_dict': {
  41. 'id': 'VPWON_1169289',
  42. 'ext': 'm4v',
  43. 'title': 'Tegenlicht',
  44. 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
  45. 'upload_date': '20130225',
  46. 'duration': 3000,
  47. },
  48. }
  49. ]
  50. def _real_extract(self, url):
  51. mobj = re.match(self._VALID_URL, url)
  52. video_id = mobj.group('id')
  53. return self._get_info(video_id)
  54. def _get_info(self, video_id):
  55. metadata = self._download_json(
  56. 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
  57. video_id,
  58. # We have to remove the javascript callback
  59. transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//.*$', r'\1', j)
  60. )
  61. token_page = self._download_webpage(
  62. 'http://ida.omroep.nl/npoplayer/i.js',
  63. video_id,
  64. note='Downloading token'
  65. )
  66. token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
  67. formats = []
  68. quality = qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std'])
  69. for format_id in metadata['pubopties']:
  70. format_info = self._download_json(
  71. 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s' % (video_id, format_id, token),
  72. video_id, 'Downloading %s JSON' % format_id)
  73. if format_info.get('error_code', 0) or format_info.get('errorcode', 0):
  74. continue
  75. streams = format_info.get('streams')
  76. if streams:
  77. video_info = self._download_json(
  78. streams[0] + '&type=json',
  79. video_id, 'Downloading %s stream JSON' % format_id)
  80. else:
  81. video_info = format_info
  82. video_url = video_info.get('url')
  83. if not video_url:
  84. continue
  85. if format_id == 'adaptive':
  86. formats.extend(self._extract_m3u8_formats(video_url, video_id))
  87. else:
  88. formats.append({
  89. 'url': video_url,
  90. 'format_id': format_id,
  91. 'quality': quality(format_id),
  92. })
  93. self._sort_formats(formats)
  94. return {
  95. 'id': video_id,
  96. 'title': metadata['titel'],
  97. 'description': metadata['info'],
  98. 'thumbnail': metadata.get('images', [{'url': None}])[-1]['url'],
  99. 'upload_date': unified_strdate(metadata.get('gidsdatum')),
  100. 'duration': parse_duration(metadata.get('tijdsduur')),
  101. 'formats': formats,
  102. }
  103. class TegenlichtVproIE(NPOIE):
  104. IE_NAME = 'tegenlicht.vpro.nl'
  105. _VALID_URL = r'https?://tegenlicht\.vpro\.nl/afleveringen/.*?'
  106. _TESTS = [
  107. {
  108. 'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html',
  109. 'md5': 'f8065e4e5a7824068ed3c7e783178f2c',
  110. 'info_dict': {
  111. 'id': 'VPWON_1169289',
  112. 'ext': 'm4v',
  113. 'title': 'Tegenlicht',
  114. 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1',
  115. 'upload_date': '20130225',
  116. },
  117. },
  118. ]
  119. def _real_extract(self, url):
  120. name = url_basename(url)
  121. webpage = self._download_webpage(url, name)
  122. urn = self._html_search_meta('mediaurn', webpage)
  123. info_page = self._download_json(
  124. 'http://rs.vpro.nl/v2/api/media/%s.json' % urn, name)
  125. return self._get_info(info_page['mid'])