]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/urplay.py
debian/{compat,control}: Update to debhelper compatibility level 12.
[youtubedl] / youtube_dl / extractor / urplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class URPlayIE(InfoExtractor):
8 _VALID_URL = r'https?://(?:www\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)'
9 _TESTS = [{
10 'url': 'http://urplay.se/program/190031-tripp-trapp-trad-sovkudde',
11 'md5': 'ad5f0de86f16ca4c8062cd103959a9eb',
12 'info_dict': {
13 'id': '190031',
14 'ext': 'mp4',
15 'title': 'Tripp, Trapp, Träd : Sovkudde',
16 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
17 },
18 }, {
19 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden',
20 'only_matching': True,
21 }]
22
23 def _real_extract(self, url):
24 video_id = self._match_id(url)
25
26 webpage = self._download_webpage(url, video_id)
27 urplayer_data = self._parse_json(self._search_regex(
28 r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
29 host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
30
31 formats = []
32 for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
33 file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
34 if file_http:
35 formats.extend(self._extract_wowza_formats(
36 'http://%s/%splaylist.m3u8' % (host, file_http), video_id, skip_protocols=['rtmp', 'rtsp']))
37 self._sort_formats(formats)
38
39 subtitles = {}
40 for subtitle in urplayer_data.get('subtitles', []):
41 subtitle_url = subtitle.get('file')
42 kind = subtitle.get('kind')
43 if not subtitle_url or (kind and kind != 'captions'):
44 continue
45 subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
46 'url': subtitle_url,
47 })
48
49 return {
50 'id': video_id,
51 'title': urplayer_data['title'],
52 'description': self._og_search_description(webpage),
53 'thumbnail': urplayer_data.get('image'),
54 'series': urplayer_data.get('series_title'),
55 'subtitles': subtitles,
56 'formats': formats,
57 }