]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/urplay.py
Update README.md
[youtubedl] / youtube_dl / extractor / urplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import unified_timestamp
6
7
8 class URPlayIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)'
10 _TESTS = [{
11 'url': 'https://urplay.se/program/203704-ur-samtiden-livet-universum-och-rymdens-markliga-musik-om-vetenskap-kritiskt-tankande-och-motstand',
12 'md5': 'ff5b0c89928f8083c74bbd5099c9292d',
13 'info_dict': {
14 'id': '203704',
15 'ext': 'mp4',
16 'title': 'UR Samtiden - Livet, universum och rymdens märkliga musik : Om vetenskap, kritiskt tänkande och motstånd',
17 'description': 'md5:5344508a52aa78c1ced6c1b8b9e44e9a',
18 'timestamp': 1513512768,
19 'upload_date': '20171217',
20 },
21 }, {
22 'url': 'https://urskola.se/Produkter/190031-Tripp-Trapp-Trad-Sovkudde',
23 'info_dict': {
24 'id': '190031',
25 'ext': 'mp4',
26 'title': 'Tripp, Trapp, Träd : Sovkudde',
27 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
28 'timestamp': 1440093600,
29 'upload_date': '20150820',
30 },
31 }, {
32 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden',
33 'only_matching': True,
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
38
39 webpage = self._download_webpage(url, video_id)
40 urplayer_data = self._parse_json(self._search_regex(
41 r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
42 host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
43
44 formats = []
45 for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
46 file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
47 if file_http:
48 formats.extend(self._extract_wowza_formats(
49 'http://%s/%splaylist.m3u8' % (host, file_http), video_id, skip_protocols=['rtmp', 'rtsp']))
50 self._sort_formats(formats)
51
52 subtitles = {}
53 for subtitle in urplayer_data.get('subtitles', []):
54 subtitle_url = subtitle.get('file')
55 kind = subtitle.get('kind')
56 if not subtitle_url or (kind and kind != 'captions'):
57 continue
58 subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
59 'url': subtitle_url,
60 })
61
62 return {
63 'id': video_id,
64 'title': urplayer_data['title'],
65 'description': self._og_search_description(webpage),
66 'thumbnail': urplayer_data.get('image'),
67 'timestamp': unified_timestamp(self._html_search_meta(('uploadDate', 'schema:uploadDate'), webpage, 'timestamp')),
68 'series': urplayer_data.get('series_title'),
69 'subtitles': subtitles,
70 'formats': formats,
71 }