]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/svt.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class SVTBaseIE(InfoExtractor
):
16 _GEO_COUNTRIES
= ['SE']
18 def _extract_video(self
, video_info
, video_id
):
20 for vr
in video_info
['videoReferences']:
21 player_type
= vr
.get('playerType') or vr
.get('format')
23 ext
= determine_ext(vurl
)
25 formats
.extend(self
._extract
_m
3u8_formats
(
27 ext
='mp4', entry_protocol
='m3u8_native',
28 m3u8_id
=player_type
, fatal
=False))
30 formats
.extend(self
._extract
_f
4m
_formats
(
31 vurl
+ '?hdcore=3.3.0', video_id
,
32 f4m_id
=player_type
, fatal
=False))
34 if player_type
== 'dashhbbtv':
35 formats
.extend(self
._extract
_mpd
_formats
(
36 vurl
, video_id
, mpd_id
=player_type
, fatal
=False))
39 'format_id': player_type
,
42 if not formats
and video_info
.get('rights', {}).get('geoBlockedSweden'):
43 self
.raise_geo_restricted(
44 'This video is only available in Sweden',
45 countries
=self
._GEO
_COUNTRIES
)
46 self
._sort
_formats
(formats
)
49 subtitle_references
= dict_get(video_info
, ('subtitles', 'subtitleReferences'))
50 if isinstance(subtitle_references
, list):
51 for sr
in subtitle_references
:
52 subtitle_url
= sr
.get('url')
53 subtitle_lang
= sr
.get('language', 'sv')
55 if determine_ext(subtitle_url
) == 'm3u8':
56 # TODO(yan12125): handle WebVTT in m3u8 manifests
59 subtitles
.setdefault(subtitle_lang
, []).append({'url': subtitle_url
})
61 title
= video_info
.get('title')
63 series
= video_info
.get('programTitle')
64 season_number
= int_or_none(video_info
.get('season'))
65 episode
= video_info
.get('episodeTitle')
66 episode_number
= int_or_none(video_info
.get('episodeNumber'))
68 duration
= int_or_none(dict_get(video_info
, ('materialLength', 'contentDuration')))
71 video_info
, ('inappropriateForChildren', 'blockedForChildren'),
72 skip_false_values
=False)
74 age_limit
= 18 if adult
else 0
80 'subtitles': subtitles
,
82 'age_limit': age_limit
,
84 'season_number': season_number
,
86 'episode_number': episode_number
,
90 class SVTIE(SVTBaseIE
):
91 _VALID_URL
= r
'https?://(?:www\.)?svt\.se/wd\?(?:.*?&)?widgetId=(?P<widget_id>\d+)&.*?\barticleId=(?P<id>\d+)'
93 'url': 'http://www.svt.se/wd?widgetId=23991§ionId=541&articleId=2900353&type=embed&contextSectionId=123&autostart=false',
94 'md5': '33e9a5d8f646523ce0868ecfb0eed77d',
98 'title': 'Stjärnorna skojar till det - under SVT-intervjun',
105 def _extract_url(webpage
):
107 r
'(?:<iframe src|href)="(?P<url>%s[^"]*)"' % SVTIE
._VALID
_URL
, webpage
)
109 return mobj
.group('url')
111 def _real_extract(self
, url
):
112 mobj
= re
.match(self
._VALID
_URL
, url
)
113 widget_id
= mobj
.group('widget_id')
114 article_id
= mobj
.group('id')
116 info
= self
._download
_json
(
117 'http://www.svt.se/wd?widgetId=%s&articleId=%s&format=json&type=embed&output=json' % (widget_id
, article_id
),
120 info_dict
= self
._extract
_video
(info
['video'], article_id
)
121 info_dict
['title'] = info
['context']['title']
125 class SVTPlayIE(SVTBaseIE
):
126 IE_DESC
= 'SVT Play and Öppet arkiv'
127 _VALID_URL
= r
'https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp)/(?P<id>[0-9]+)'
129 'url': 'http://www.svtplay.se/video/5996901/flygplan-till-haile-selassie/flygplan-till-haile-selassie-2',
130 'md5': '2b6704fe4a28801e1a098bbf3c5ac611',
134 'title': 'Flygplan till Haile Selassie',
136 'thumbnail': r
're:^https?://.*[\.-]jpg$',
145 # geo restricted to Sweden
146 'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
147 'only_matching': True,
149 'url': 'http://www.svtplay.se/klipp/9023742/stopptid-om-bjorn-borg',
150 'only_matching': True,
153 def _real_extract(self
, url
):
154 video_id
= self
._match
_id
(url
)
156 webpage
= self
._download
_webpage
(url
, video_id
)
158 data
= self
._parse
_json
(
160 r
'root\["__svtplay"\]\s*=\s*([^;]+);',
161 webpage
, 'embedded data', default
='{}'),
162 video_id
, fatal
=False)
164 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
167 video_info
= try_get(
168 data
, lambda x
: x
['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video'],
171 info_dict
= self
._extract
_video
(video_info
, video_id
)
173 'title': data
['context']['dispatcher']['stores']['MetaStore']['title'],
174 'thumbnail': thumbnail
,
178 video_id
= self
._search
_regex
(
179 r
'<video[^>]+data-video-id=["\']([\da
-zA
-Z
-]+)',
180 webpage, 'video
id', default=None)
183 data = self._download_json(
184 'https
://api
.svt
.se
/videoplayer
-api
/video
/%s' % video_id,
185 video_id, headers=self.geo_verification_headers())
186 info_dict = self._extract_video(data, video_id)
187 if not info_dict.get('title
'):
188 info_dict['title
'] = re.sub(
190 info_dict.get('episode
') or self._og_search_title(webpage))