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.

56 lines
1.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. )
  7. class SVTPlayIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?svtplay\.se/video/(?P<id>[0-9]+)'
  9. _TEST = {
  10. 'url': 'http://www.svtplay.se/video/2609989/sm-veckan/sm-veckan-rally-final-sasong-1-sm-veckan-rally-final',
  11. 'md5': 'f4a184968bc9c802a9b41316657aaa80',
  12. 'info_dict': {
  13. 'id': '2609989',
  14. 'ext': 'mp4',
  15. 'title': 'SM veckan vinter, Örebro - Rally, final',
  16. 'duration': 4500,
  17. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. info = self._download_json(
  23. 'http://www.svtplay.se/video/%s?output=json' % video_id, video_id)
  24. title = info['context']['title']
  25. thumbnail = info['context'].get('thumbnailImage')
  26. video_info = info['video']
  27. formats = []
  28. for vr in video_info['videoReferences']:
  29. vurl = vr['url']
  30. if determine_ext(vurl) == 'm3u8':
  31. formats.extend(self._extract_m3u8_formats(
  32. vurl, video_id,
  33. ext='mp4', entry_protocol='m3u8_native',
  34. m3u8_id=vr.get('playerType')))
  35. else:
  36. formats.append({
  37. 'format_id': vr.get('playerType'),
  38. 'url': vurl,
  39. })
  40. self._sort_formats(formats)
  41. duration = video_info.get('materialLength')
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'formats': formats,
  46. 'thumbnail': thumbnail,
  47. 'duration': duration,
  48. }