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.

71 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. unified_strdate,
  6. qualities,
  7. )
  8. class NPOIE(InfoExtractor):
  9. IE_NAME = 'npo.nl'
  10. _VALID_URL = r'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)'
  11. _TEST = {
  12. 'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719',
  13. 'md5': '4b3f9c429157ec4775f2c9cb7b911016',
  14. 'info_dict': {
  15. 'id': 'VPWON_1220719',
  16. 'ext': 'm4v',
  17. 'title': 'Nieuwsuur',
  18. 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.',
  19. 'upload_date': '20140622',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. metadata = self._download_json(
  26. 'http://e.omroep.nl/metadata/aflevering/%s' % video_id,
  27. video_id,
  28. # We have to remove the javascript callback
  29. transform_source=lambda j: re.sub(r'parseMetadata\((.*?)\);\n//.*$', r'\1', j)
  30. )
  31. token_page = self._download_webpage(
  32. 'http://ida.omroep.nl/npoplayer/i.js',
  33. video_id,
  34. note='Downloading token'
  35. )
  36. token = self._search_regex(r'npoplayer\.token = "(.+?)"', token_page, 'token')
  37. formats = []
  38. quality = qualities(['adaptive', 'h264_sb', 'h264_bb', 'h264_std'])
  39. for format_id in metadata['pubopties']:
  40. streams_info = self._download_json(
  41. 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s' % (video_id, format_id, token),
  42. video_id, 'Downloading %s streams info' % format_id)
  43. stream_info = self._download_json(
  44. streams_info['streams'][0] + '&type=json',
  45. video_id, 'Downloading %s stream info' % format_id)
  46. if format_id == 'adaptive':
  47. formats.extend(self._extract_m3u8_formats(stream_info['url'], video_id))
  48. else:
  49. formats.append({
  50. 'url': stream_info['url'],
  51. 'format_id': format_id,
  52. 'quality': quality(format_id),
  53. })
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': metadata['titel'],
  58. 'description': metadata['info'],
  59. 'thumbnail': metadata['images'][-1]['url'],
  60. 'upload_date': unified_strdate(metadata['gidsdatum']),
  61. 'formats': formats,
  62. }