]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | dict_get, | |
7 | int_or_none, | |
8 | unified_timestamp, | |
9 | ) | |
10 | ||
11 | ||
12 | class URPlayIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://(?:www\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)' | |
14 | _TESTS = [{ | |
15 | 'url': 'https://urplay.se/program/203704-ur-samtiden-livet-universum-och-rymdens-markliga-musik-om-vetenskap-kritiskt-tankande-och-motstand', | |
16 | 'md5': 'ff5b0c89928f8083c74bbd5099c9292d', | |
17 | 'info_dict': { | |
18 | 'id': '203704', | |
19 | 'ext': 'mp4', | |
20 | 'title': 'UR Samtiden - Livet, universum och rymdens märkliga musik : Om vetenskap, kritiskt tänkande och motstånd', | |
21 | 'description': 'md5:5344508a52aa78c1ced6c1b8b9e44e9a', | |
22 | 'timestamp': 1513292400, | |
23 | 'upload_date': '20171214', | |
24 | }, | |
25 | }, { | |
26 | 'url': 'https://urskola.se/Produkter/190031-Tripp-Trapp-Trad-Sovkudde', | |
27 | 'info_dict': { | |
28 | 'id': '190031', | |
29 | 'ext': 'mp4', | |
30 | 'title': 'Tripp, Trapp, Träd : Sovkudde', | |
31 | 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1', | |
32 | 'timestamp': 1440086400, | |
33 | 'upload_date': '20150820', | |
34 | }, | |
35 | }, { | |
36 | 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden', | |
37 | 'only_matching': True, | |
38 | }] | |
39 | ||
40 | def _real_extract(self, url): | |
41 | video_id = self._match_id(url) | |
42 | url = url.replace('skola.se/Produkter', 'play.se/program') | |
43 | webpage = self._download_webpage(url, video_id) | |
44 | urplayer_data = self._parse_json(self._html_search_regex( | |
45 | r'data-react-class="routes/Product/components/ProgramContainer/ProgramContainer"[^>]+data-react-props="({.+?})"', | |
46 | webpage, 'urplayer data'), video_id)['accessibleEpisodes'][0] | |
47 | episode = urplayer_data['title'] | |
48 | ||
49 | host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect'] | |
50 | formats = [] | |
51 | urplayer_streams = urplayer_data.get('streamingInfo', {}) | |
52 | ||
53 | for k, v in urplayer_streams.get('raw', {}).items(): | |
54 | if not (k in ('sd', 'hd') and isinstance(v, dict)): | |
55 | continue | |
56 | file_http = v.get('location') | |
57 | if file_http: | |
58 | formats.extend(self._extract_wowza_formats( | |
59 | 'http://%s/%splaylist.m3u8' % (host, file_http), | |
60 | video_id, skip_protocols=['f4m', 'rtmp', 'rtsp'])) | |
61 | self._sort_formats(formats) | |
62 | ||
63 | subtitles = {} | |
64 | subs = urplayer_streams.get("sweComplete", {}).get("tt", {}).get("location") | |
65 | if subs: | |
66 | subtitles.setdefault('Svenska', []).append({ | |
67 | 'url': subs, | |
68 | }) | |
69 | ||
70 | image = urplayer_data.get('image') or {} | |
71 | thumbnails = [] | |
72 | for k, v in image.items(): | |
73 | t = { | |
74 | 'id': k, | |
75 | 'url': v, | |
76 | } | |
77 | wh = k.split('x') | |
78 | if len(wh) == 2: | |
79 | t.update({ | |
80 | 'width': int_or_none(wh[0]), | |
81 | 'height': int_or_none(wh[1]), | |
82 | }) | |
83 | thumbnails.append(t) | |
84 | ||
85 | series = urplayer_data.get('series') or {} | |
86 | series_title = dict_get(series, ('seriesTitle', 'title')) or dict_get(urplayer_data, ('seriesTitle', 'mainTitle')) | |
87 | ||
88 | return { | |
89 | 'id': video_id, | |
90 | 'subtitles': subtitles, | |
91 | 'title': '%s : %s' % (series_title, episode) if series_title else episode, | |
92 | 'description': urplayer_data.get('description'), | |
93 | 'thumbnails': thumbnails, | |
94 | 'timestamp': unified_timestamp(urplayer_data.get('publishedAt')), | |
95 | 'series': series_title, | |
96 | 'formats': formats, | |
97 | 'duration': int_or_none(urplayer_data.get('duration')), | |
98 | 'categories': urplayer_data.get('categories'), | |
99 | 'tags': urplayer_data.get('keywords'), | |
100 | 'season': series.get('label'), | |
101 | 'episode': episode, | |
102 | 'episode_number': int_or_none(urplayer_data.get('episodeNumber')), | |
103 | } |