]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/urplay.py
debian/patches: Remove unneeded patches.
[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\.)?urplay\.se/program/(?P<id>[0-9]+)'
9 _TEST = {
10 'url': 'http://urplay.se/program/190031-tripp-trapp-trad-sovkudde',
11 'md5': '15ca67b63fd8fb320ac2bcd854bad7b6',
12 'info_dict': {
13 'id': '190031',
14 'ext': 'mp4',
15 'title': 'Tripp, Trapp, Träd : Sovkudde',
16 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
17 }
18 }
19
20 def _real_extract(self, url):
21 video_id = self._match_id(url)
22
23 webpage = self._download_webpage(url, video_id)
24 urplayer_data = self._parse_json(self._search_regex(
25 r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
26 host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
27
28 formats = []
29 for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
30 file_rtmp = urplayer_data.get('file_rtmp' + quality_attr)
31 if file_rtmp:
32 formats.append({
33 'url': 'rtmp://%s/urplay/mp4:%s' % (host, file_rtmp),
34 'format_id': quality + '-rtmp',
35 'ext': 'flv',
36 'preference': preference,
37 })
38 file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
39 if file_http:
40 file_http_base_url = 'http://%s/%s' % (host, file_http)
41 formats.extend(self._extract_f4m_formats(
42 file_http_base_url + 'manifest.f4m', video_id,
43 preference, '%s-hds' % quality, fatal=False))
44 formats.extend(self._extract_m3u8_formats(
45 file_http_base_url + 'playlist.m3u8', video_id, 'mp4',
46 'm3u8_native', preference, '%s-hls' % quality, fatal=False))
47 self._sort_formats(formats)
48
49 subtitles = {}
50 for subtitle in urplayer_data.get('subtitles', []):
51 subtitle_url = subtitle.get('file')
52 kind = subtitle.get('kind')
53 if subtitle_url or kind and kind != 'captions':
54 continue
55 subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
56 'url': subtitle_url,
57 })
58
59 return {
60 'id': video_id,
61 'title': urplayer_data['title'],
62 'description': self._og_search_description(webpage),
63 'thumbnail': urplayer_data.get('image'),
64 'series': urplayer_data.get('series_title'),
65 'subtitles': subtitles,
66 'formats': formats,
67 }