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.

82 lines
2.7 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 SVTPlayIE(InfoExtractor):
  9. IE_DESC = 'SVT Play and Öppet arkiv'
  10. _VALID_URL = r'https?://(?:www\.)?(?P<host>svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.svtplay.se/video/2609989/sm-veckan/sm-veckan-rally-final-sasong-1-sm-veckan-rally-final',
  13. 'md5': 'ade3def0643fa1c40587a422f98edfd9',
  14. 'info_dict': {
  15. 'id': '2609989',
  16. 'ext': 'flv',
  17. 'title': 'SM veckan vinter, Örebro - Rally, final',
  18. 'duration': 4500,
  19. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  20. 'age_limit': 0,
  21. },
  22. }, {
  23. 'url': 'http://www.oppetarkiv.se/video/1058509/rederiet-sasong-1-avsnitt-1-av-318',
  24. 'md5': 'c3101a17ce9634f4c1f9800f0746c187',
  25. 'info_dict': {
  26. 'id': '1058509',
  27. 'ext': 'flv',
  28. 'title': 'Farlig kryssning',
  29. 'duration': 2566,
  30. 'thumbnail': 're:^https?://.*[\.-]jpg$',
  31. 'age_limit': 0,
  32. },
  33. 'skip': 'Only works from Sweden',
  34. }]
  35. def _real_extract(self, url):
  36. mobj = re.match(self._VALID_URL, url)
  37. video_id = mobj.group('id')
  38. host = mobj.group('host')
  39. info = self._download_json(
  40. 'http://www.%s.se/video/%s?output=json' % (host, video_id), video_id)
  41. title = info['context']['title']
  42. thumbnail = info['context'].get('thumbnailImage')
  43. video_info = info['video']
  44. formats = []
  45. for vr in video_info['videoReferences']:
  46. vurl = vr['url']
  47. ext = determine_ext(vurl)
  48. if ext == 'm3u8':
  49. formats.extend(self._extract_m3u8_formats(
  50. vurl, video_id,
  51. ext='mp4', entry_protocol='m3u8_native',
  52. m3u8_id=vr.get('playerType')))
  53. elif ext == 'f4m':
  54. formats.extend(self._extract_f4m_formats(
  55. vurl + '?hdcore=3.3.0', video_id,
  56. f4m_id=vr.get('playerType')))
  57. else:
  58. formats.append({
  59. 'format_id': vr.get('playerType'),
  60. 'url': vurl,
  61. })
  62. self._sort_formats(formats)
  63. duration = video_info.get('materialLength')
  64. age_limit = 18 if video_info.get('inappropriateForChildren') else 0
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'formats': formats,
  69. 'thumbnail': thumbnail,
  70. 'duration': duration,
  71. 'age_limit': age_limit,
  72. }