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.

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