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.

66 lines
2.2 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class NRKIE(InfoExtractor):
  7. _VALID_URL = r'http://(?:www\.)?nrk\.no/(?:video|lyd)/[^/]+/(?P<id>[\dA-F]{16})'
  8. _TESTS = [
  9. {
  10. 'url': 'http://www.nrk.no/video/dompap_og_andre_fugler_i_piip_show/D0FA54B5C8B6CE59/emne/piipshow/',
  11. 'md5': 'a6eac35052f3b242bb6bb7f43aed5886',
  12. 'info_dict': {
  13. 'id': '150533',
  14. 'ext': 'flv',
  15. 'title': 'Dompap og andre fugler i Piip-Show',
  16. 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f'
  17. }
  18. },
  19. {
  20. 'url': 'http://www.nrk.no/lyd/lyd_av_oppleser_for_blinde/AEFDDD5473BA0198/',
  21. 'md5': '3471f2a51718195164e88f46bf427668',
  22. 'info_dict': {
  23. 'id': '154915',
  24. 'ext': 'flv',
  25. 'title': 'Slik høres internett ut når du er blind',
  26. 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
  27. }
  28. },
  29. ]
  30. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('id')
  33. page = self._download_webpage(url, video_id)
  34. video_id = self._html_search_regex(r'<div class="nrk-video" data-nrk-id="(\d+)">', page, 'video id')
  35. data = self._download_json(
  36. 'http://v7.psapi.nrk.no/mediaelement/%s' % video_id, video_id, 'Downloading media JSON')
  37. if data['usageRights']['isGeoBlocked']:
  38. raise ExtractorError('NRK har ikke rettig-heter til å vise dette programmet utenfor Norge', expected=True)
  39. video_url = data['mediaUrl'] + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124'
  40. images = data.get('images')
  41. if images:
  42. thumbnails = images['webImages']
  43. thumbnails.sort(key=lambda image: image['pixelWidth'])
  44. thumbnail = thumbnails[-1]['imageUrl']
  45. else:
  46. thumbnail = None
  47. return {
  48. 'id': video_id,
  49. 'url': video_url,
  50. 'ext': 'flv',
  51. 'title': data['title'],
  52. 'description': data['description'],
  53. 'thumbnail': thumbnail,
  54. }