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.

117 lines
3.9 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. vurl = vr['url']
  17. ext = determine_ext(vurl)
  18. if ext == 'm3u8':
  19. formats.extend(self._extract_m3u8_formats(
  20. vurl, video_id,
  21. ext='mp4', entry_protocol='m3u8_native',
  22. m3u8_id=vr.get('playerType')))
  23. elif ext == 'f4m':
  24. formats.extend(self._extract_f4m_formats(
  25. vurl + '?hdcore=3.3.0', video_id,
  26. f4m_id=vr.get('playerType')))
  27. else:
  28. formats.append({
  29. 'format_id': vr.get('playerType'),
  30. 'url': vurl,
  31. })
  32. self._sort_formats(formats)
  33. duration = video_info.get('materialLength')
  34. age_limit = 18 if video_info.get('inappropriateForChildren') else 0
  35. return {
  36. 'id': video_id,
  37. 'title': title,
  38. 'formats': formats,
  39. 'thumbnail': thumbnail,
  40. 'duration': duration,
  41. 'age_limit': age_limit,
  42. }
  43. class SVTIE(SVTBaseIE):
  44. _VALID_URL = r'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
  45. _TEST = {
  46. 'url': 'http://www.svt.se/wd?widgetId=23991&sectionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
  47. 'md5': '9648197555fc1b49e3dc22db4af51d46',
  48. 'info_dict': {
  49. 'id': '2900353',
  50. 'ext': 'flv',
  51. 'title': 'Här trycker Jagr till Giroux (under SVT-intervjun)',
  52. 'duration': 27,
  53. 'age_limit': 0,
  54. },
  55. }
  56. @staticmethod
  57. def _extract_url(webpage):
  58. mobj = re.search(
  59. r'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE._VALID_URL, webpage)
  60. if mobj:
  61. return mobj.group('url')
  62. def _real_extract(self, url):
  63. mobj = re.match(self._VALID_URL, url)
  64. widget_id = mobj.group('widget_id')
  65. article_id = mobj.group('id')
  66. return self._extract_video(
  67. 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id, article_id),
  68. article_id)
  69. class SVTPlayIE(SVTBaseIE):
  70. IE_DESC = 'SVT Play and Öppet arkiv'
  71. _VALID_URL = r'https?://(?:www\.)?(?P<host>svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)'
  72. _TESTS = [{
  73. 'url': 'http://www.svtplay.se/video/2609989/sm-veckan/sm-veckan-rally-final-sasong-1-sm-veckan-rally-final',
  74. 'md5': 'ade3def0643fa1c40587a422f98edfd9',
  75. 'info_dict': {
  76. 'id': '2609989',
  77. 'ext': 'flv',
  78. 'title': 'SM veckan vinter, Örebro - Rally, final',
  79. 'duration': 4500,
  80. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  81. 'age_limit': 0,
  82. },
  83. }, {
  84. 'url': 'http://www.oppetarkiv.se/video/1058509/rederiet-sasong-1-avsnitt-1-av-318',
  85. 'md5': 'c3101a17ce9634f4c1f9800f0746c187',
  86. 'info_dict': {
  87. 'id': '1058509',
  88. 'ext': 'flv',
  89. 'title': 'Farlig kryssning',
  90. 'duration': 2566,
  91. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  92. 'age_limit': 0,
  93. },
  94. 'skip': 'Only works from Sweden',
  95. }]
  96. def _real_extract(self, url):
  97. mobj = re.match(self._VALID_URL, url)
  98. video_id = mobj.group('id')
  99. host = mobj.group('host')
  100. return self._extract_video(
  101. 'http://www.%s.se/video/%s?output=json' % (host, video_id),
  102. video_id)