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.

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