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.

143 lines
4.8 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. float_or_none,
  8. unified_strdate,
  9. )
  10. class NRKIE(InfoExtractor):
  11. _VALID_URL = r'http://(?:www\.)?nrk\.no/(?:video|lyd)/[^/]+/(?P<id>[\dA-F]{16})'
  12. _TESTS = [
  13. {
  14. 'url': 'http://www.nrk.no/video/dompap_og_andre_fugler_i_piip_show/D0FA54B5C8B6CE59/emne/piipshow/',
  15. 'md5': 'a6eac35052f3b242bb6bb7f43aed5886',
  16. 'info_dict': {
  17. 'id': '150533',
  18. 'ext': 'flv',
  19. 'title': 'Dompap og andre fugler i Piip-Show',
  20. 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f'
  21. }
  22. },
  23. {
  24. 'url': 'http://www.nrk.no/lyd/lyd_av_oppleser_for_blinde/AEFDDD5473BA0198/',
  25. 'md5': '3471f2a51718195164e88f46bf427668',
  26. 'info_dict': {
  27. 'id': '154915',
  28. 'ext': 'flv',
  29. 'title': 'Slik høres internett ut når du er blind',
  30. 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
  31. }
  32. },
  33. ]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('id')
  37. page = self._download_webpage(url, video_id)
  38. video_id = self._html_search_regex(r'<div class="nrk-video" data-nrk-id="(\d+)">', page, 'video id')
  39. data = self._download_json(
  40. 'http://v7.psapi.nrk.no/mediaelement/%s' % video_id, video_id, 'Downloading media JSON')
  41. if data['usageRights']['isGeoBlocked']:
  42. raise ExtractorError('NRK har ikke rettig-heter til å vise dette programmet utenfor Norge', expected=True)
  43. video_url = data['mediaUrl'] + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124'
  44. images = data.get('images')
  45. if images:
  46. thumbnails = images['webImages']
  47. thumbnails.sort(key=lambda image: image['pixelWidth'])
  48. thumbnail = thumbnails[-1]['imageUrl']
  49. else:
  50. thumbnail = None
  51. return {
  52. 'id': video_id,
  53. 'url': video_url,
  54. 'ext': 'flv',
  55. 'title': data['title'],
  56. 'description': data['description'],
  57. 'thumbnail': thumbnail,
  58. }
  59. class NRKTVIE(InfoExtractor):
  60. _VALID_URL = r'http://tv\.nrk(?:super)?\.no/(?:serie/[^/]+|program)/(?P<id>[a-z]{4}\d{8})'
  61. _TESTS = [
  62. {
  63. 'url': 'http://tv.nrk.no/serie/20-spoersmaal-tv/muhh48000314/23-05-2014',
  64. 'md5': '7b96112fbae1faf09a6f9ae1aff6cb84',
  65. 'info_dict': {
  66. 'id': 'muhh48000314',
  67. 'ext': 'flv',
  68. 'title': '20 spørsmål',
  69. 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
  70. 'upload_date': '20140523',
  71. 'duration': 1741.52,
  72. }
  73. },
  74. {
  75. 'url': 'http://tv.nrk.no/program/mdfp15000514',
  76. 'md5': 'af01795a31f1cf7265c8657534d8077b',
  77. 'info_dict': {
  78. 'id': 'mdfp15000514',
  79. 'ext': 'flv',
  80. 'title': 'Kunnskapskanalen: Grunnlovsjubiléet - Stor ståhei for ingenting',
  81. 'description': 'md5:654c12511f035aed1e42bdf5db3b206a',
  82. 'upload_date': '20140524',
  83. 'duration': 4605.0,
  84. }
  85. },
  86. ]
  87. def _real_extract(self, url):
  88. mobj = re.match(self._VALID_URL, url)
  89. video_id = mobj.group('id')
  90. page = self._download_webpage(url, video_id)
  91. title = self._html_search_meta('title', page, 'title')
  92. description = self._html_search_meta('description', page, 'description')
  93. thumbnail = self._html_search_regex(r'data-posterimage="([^"]+)"', page, 'thumbnail', fatal=False)
  94. upload_date = unified_strdate(self._html_search_meta('rightsfrom', page, 'upload date', fatal=False))
  95. duration = float_or_none(
  96. self._html_search_regex(r'data-duration="([^"]+)"', page, 'duration', fatal=False))
  97. formats = []
  98. f4m_url = re.search(r'data-media="([^"]+)"', page)
  99. if f4m_url:
  100. formats.append({
  101. 'url': f4m_url.group(1) + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124',
  102. 'format_id': 'f4m',
  103. 'ext': 'flv',
  104. })
  105. m3u8_url = re.search(r'data-hls-media="([^"]+)"', page)
  106. if m3u8_url:
  107. formats.append({
  108. 'url': m3u8_url.group(1),
  109. 'format_id': 'm3u8',
  110. })
  111. self._sort_formats(formats)
  112. return {
  113. 'id': video_id,
  114. 'title': title,
  115. 'description': description,
  116. 'thumbnail': thumbnail,
  117. 'upload_date': upload_date,
  118. 'duration': duration,
  119. 'formats': formats,
  120. }