]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/svtplay.py
[ssa] Add extractor (Closes #5169)
[yt-dlp.git] / youtube_dl / extractor / svtplay.py
CommitLineData
28f12728 1# coding: utf-8
1309b396
PH
2from __future__ import unicode_literals
3
df5ae3eb
S
4import re
5
1309b396
PH
6from .common import InfoExtractor
7from ..utils import (
8 determine_ext,
9)
10
11
12class SVTPlayIE(InfoExtractor):
df5ae3eb
S
13 IE_DESC = 'SVT Play and Öppet arkiv'
14 _VALID_URL = r'https?://(?:www\.)?(?P<host>svtplay|oppetarkiv)\.se/video/(?P<id>[0-9]+)'
15 _TESTS = [{
1309b396 16 'url': 'http://www.svtplay.se/video/2609989/sm-veckan/sm-veckan-rally-final-sasong-1-sm-veckan-rally-final',
df5ae3eb 17 'md5': 'ade3def0643fa1c40587a422f98edfd9',
1309b396 18 'info_dict': {
28f12728 19 'id': '2609989',
df5ae3eb 20 'ext': 'flv',
28f12728 21 'title': 'SM veckan vinter, Örebro - Rally, final',
1309b396 22 'duration': 4500,
28f12728 23 'thumbnail': 're:^https?://.*[\.-]jpg$',
df5ae3eb 24 'age_limit': 0,
1309b396 25 },
df5ae3eb
S
26 }, {
27 'url': 'http://www.oppetarkiv.se/video/1058509/rederiet-sasong-1-avsnitt-1-av-318',
28 'md5': 'c3101a17ce9634f4c1f9800f0746c187',
29 'info_dict': {
30 'id': '1058509',
31 'ext': 'flv',
32 'title': 'Farlig kryssning',
33 'duration': 2566,
34 'thumbnail': 're:^https?://.*[\.-]jpg$',
35 'age_limit': 0,
36 },
37 'skip': 'Only works from Sweden',
38 }]
1309b396
PH
39
40 def _real_extract(self, url):
df5ae3eb
S
41 mobj = re.match(self._VALID_URL, url)
42 video_id = mobj.group('id')
43 host = mobj.group('host')
44
1309b396 45 info = self._download_json(
df5ae3eb 46 'http://www.%s.se/video/%s?output=json' % (host, video_id), video_id)
1309b396
PH
47
48 title = info['context']['title']
49 thumbnail = info['context'].get('thumbnailImage')
50
51 video_info = info['video']
52 formats = []
53 for vr in video_info['videoReferences']:
54 vurl = vr['url']
df5ae3eb
S
55 ext = determine_ext(vurl)
56 if ext == 'm3u8':
1309b396
PH
57 formats.extend(self._extract_m3u8_formats(
58 vurl, video_id,
59 ext='mp4', entry_protocol='m3u8_native',
60 m3u8_id=vr.get('playerType')))
df5ae3eb
S
61 elif ext == 'f4m':
62 formats.extend(self._extract_f4m_formats(
63 vurl + '?hdcore=3.3.0', video_id,
64 f4m_id=vr.get('playerType')))
1309b396
PH
65 else:
66 formats.append({
67 'format_id': vr.get('playerType'),
68 'url': vurl,
69 })
70 self._sort_formats(formats)
71
72 duration = video_info.get('materialLength')
df5ae3eb 73 age_limit = 18 if video_info.get('inappropriateForChildren') else 0
1309b396
PH
74
75 return {
76 'id': video_id,
77 'title': title,
78 'formats': formats,
79 'thumbnail': thumbnail,
80 'duration': duration,
df5ae3eb 81 'age_limit': age_limit,
1309b396 82 }