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.

124 lines
4.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. )
  8. class SVTBaseIE(InfoExtractor):
  9. def _extract_video(self, url, video_id):
  10. info = self._download_json(url, video_id)
  11. title = info['context']['title']
  12. thumbnail = info['context'].get('thumbnailImage')
  13. video_info = info['video']
  14. formats = []
  15. for vr in video_info['videoReferences']:
  16. player_type = vr.get('playerType')
  17. vurl = vr['url']
  18. ext = determine_ext(vurl)
  19. if ext == 'm3u8':
  20. formats.extend(self._extract_m3u8_formats(
  21. vurl, video_id,
  22. ext='mp4', entry_protocol='m3u8_native',
  23. m3u8_id=player_type, fatal=False))
  24. elif ext == 'f4m':
  25. formats.extend(self._extract_f4m_formats(
  26. vurl + '?hdcore=3.3.0', video_id,
  27. f4m_id=player_type, fatal=False))
  28. elif ext == 'mpd':
  29. if player_type == 'dashhbbtv':
  30. formats.extend(self._extract_mpd_formats(
  31. vurl, video_id, mpd_id=player_type, fatal=False))
  32. else:
  33. formats.append({
  34. 'format_id': player_type,
  35. 'url': vurl,
  36. })
  37. self._sort_formats(formats)
  38. subtitles = {}
  39. subtitle_references = video_info.get('subtitleReferences')
  40. if isinstance(subtitle_references, list):
  41. for sr in subtitle_references:
  42. subtitle_url = sr.get('url')
  43. if subtitle_url:
  44. subtitles.setdefault('sv', []).append({'url': subtitle_url})
  45. duration = video_info.get('materialLength')
  46. age_limit = 18 if video_info.get('inappropriateForChildren') else 0
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'formats': formats,
  51. 'subtitles': subtitles,
  52. 'thumbnail': thumbnail,
  53. 'duration': duration,
  54. 'age_limit': age_limit,
  55. }
  56. class SVTIE(SVTBaseIE):
  57. _VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
  58. _TEST = {
  59. 'url': 'http://www.svt.se/wd?widgetId=23991&sectionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
  60. 'md5': '9648197555fc1b49e3dc22db4af51d46',
  61. 'info_dict': {
  62. 'id': '2900353',
  63. 'ext': 'flv',
  64. 'title': 'Här trycker Jagr till Giroux (under SVT-intervjun)',
  65. 'duration': 27,
  66. 'age_limit': 0,
  67. },
  68. }
  69. @staticmethod
  70. def _extract_url(webpage):
  71. mobj = re.search(
  72. r'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE._VALID_URL, webpage)
  73. if mobj:
  74. return mobj.group('url')
  75. def _real_extract(self, url):
  76. mobj = re.match(self._VALID_URL, url)
  77. widget_id = mobj.group('widget_id')
  78. article_id = mobj.group('id')
  79. return self._extract_video(
  80. 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id),
  81. article_id)
  82. class SVTPlayIE(SVTBaseIE):
  83. IE_DESC = 'SVT Play and Öppet arkiv'
  84. _VALID_URL = r'https?://(?:www\.)?(?P<host>svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)'
  85. _TEST = {
  86. 'url': 'http://www.svtplay.se/video/5996901/flygplan-till-haile-selassie/flygplan-till-haile-selassie-2',
  87. 'md5': '2b6704fe4a28801e1a098bbf3c5ac611',
  88. 'info_dict': {
  89. 'id': '5996901',
  90. 'ext': 'mp4',
  91. 'title': 'Flygplan till Haile Selassie',
  92. 'duration': 3527,
  93. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  94. 'age_limit': 0,
  95. 'subtitles': {
  96. 'sv': [{
  97. 'ext': 'wsrt',
  98. }]
  99. },
  100. },
  101. }
  102. def _real_extract(self, url):
  103. mobj = re.match(self._VALID_URL, url)
  104. video_id = mobj.group('id')
  105. host = mobj.group('host')
  106. return self._extract_video(
  107. 'http://www.%s.se/video/%s?output=json' % (host, video_id),
  108. video_id)