1 from .common
import InfoExtractor
13 class URPlayIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)'
16 'url': 'https://urplay.se/program/203704-ur-samtiden-livet-universum-och-rymdens-markliga-musik-om-vetenskap-kritiskt-tankande-och-motstand',
17 'md5': '5ba36643c77cc3d34ffeadad89937d1e',
21 'title': 'UR Samtiden - Livet, universum och rymdens märkliga musik : Om vetenskap, kritiskt tänkande och motstånd',
22 'description': 'md5:5344508a52aa78c1ced6c1b8b9e44e9a',
23 'thumbnail': r
're:^https?://.+\.jpg',
24 'timestamp': 1513292400,
25 'upload_date': '20171214',
26 'series': 'UR Samtiden - Livet, universum och rymdens märkliga musik',
28 'categories': ['Vetenskap & teknik'],
29 'tags': ['Kritiskt tänkande', 'Vetenskap', 'Vetenskaplig verksamhet'],
30 'episode': 'Om vetenskap, kritiskt tänkande och motstånd',
34 'url': 'https://urplay.se/program/222967-en-foralders-dagbok-mitt-barn-skadar-sig-sjalv',
38 'title': 'En förälders dagbok : Mitt barn skadar sig själv',
39 'description': 'md5:9f771eef03a732a213b367b52fe826ca',
40 'thumbnail': r
're:^https?://.+\.jpg',
41 'timestamp': 1629676800,
42 'upload_date': '20210823',
43 'series': 'En förälders dagbok',
47 'categories': 'count:2',
49 'episode': 'Mitt barn skadar sig själv',
52 'url': 'https://urskola.se/Produkter/190031-Tripp-Trapp-Trad-Sovkudde',
56 'title': 'Tripp, Trapp, Träd : Sovkudde',
57 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
58 'thumbnail': r
're:^https?://.+\.jpg',
59 'timestamp': 1440086400,
60 'upload_date': '20150820',
61 'series': 'Tripp, Trapp, Träd',
67 'episode': 'Sovkudde',
71 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden',
72 'only_matching': True,
75 def _real_extract(self
, url
):
76 video_id
= self
._match
_id
(url
)
77 url
= url
.replace('skola.se/Produkter', 'play.se/program')
78 webpage
= self
._download
_webpage
(url
, video_id
)
79 urplayer_data
= self
._search
_nextjs
_data
(webpage
, video_id
, fatal
=False) or {}
81 urplayer_data
= try_get(urplayer_data
, lambda x
: x
['props']['pageProps']['program'], dict)
83 raise ExtractorError('Unable to parse __NEXT_DATA__')
85 accessible_episodes
= self
._parse
_json
(self
._html
_search
_regex
(
86 r
'data-react-class="routes/Product/components/ProgramContainer/ProgramContainer"[^>]+data-react-props="({.+?})"',
87 webpage
, 'urplayer data'), video_id
)['accessibleEpisodes']
88 urplayer_data
= next(e
for e
in accessible_episodes
if e
.get('id') == int_or_none(video_id
))
89 episode
= urplayer_data
['title']
91 host
= self
._download
_json
('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id
)['redirect']
93 urplayer_streams
= urplayer_data
.get('streamingInfo', {})
95 for k
, v
in urplayer_streams
.get('raw', {}).items():
96 if not (k
in ('sd', 'hd', 'mp3', 'm4a') and isinstance(v
, dict)):
98 file_http
= v
.get('location')
100 formats
.extend(self
._extract
_wowza
_formats
(
101 f
'http://{host}/{file_http}playlist.m3u8',
102 video_id
, skip_protocols
=['f4m', 'rtmp', 'rtsp']))
106 def parse_lang_code(code
):
107 "3-character language code or None (utils candidate)"
111 if not ISO639Utils
.long2short(lang
):
112 lang
= ISO639Utils
.short2long(lang
)
115 for stream
in urplayer_data
['streamingInfo'].values():
116 for k
, v
in stream
.items():
117 if (k
in ('sd', 'hd') or not isinstance(v
, dict)):
119 lang
, sttl_url
= (v
.get(kk
) for kk
in ('language', 'location'))
122 lang
= parse_lang_code(lang
)
125 sttl
= subtitles
.get(lang
) or []
126 sttl
.append({'ext': k
, 'url': sttl_url
})
127 subtitles
[lang
] = sttl
129 image
= urplayer_data
.get('image') or {}
131 for k
, v
in image
.items():
139 'width': int_or_none(wh
[0]),
140 'height': int_or_none(wh
[1]),
144 series
= urplayer_data
.get('series') or {}
145 series_title
= dict_get(series
, ('seriesTitle', 'title')) or dict_get(urplayer_data
, ('seriesTitle', 'mainTitle'))
149 'title': f
'{series_title} : {episode}' if series_title
else episode
,
150 'description': urplayer_data
.get('description'),
151 'thumbnails': thumbnails
,
152 'timestamp': unified_timestamp(urplayer_data
.get('publishedAt')),
153 'series': series_title
,
155 'duration': int_or_none(urplayer_data
.get('duration')),
156 'categories': urplayer_data
.get('categories'),
157 'tags': urplayer_data
.get('keywords'),
158 'season': series
.get('label'),
160 'episode_number': int_or_none(urplayer_data
.get('episodeNumber')),
161 'age_limit': parse_age_limit(min(try_get(a
, lambda x
: x
['from'], int) or 0
162 for a
in urplayer_data
.get('ageRanges', []))),
163 'subtitles': subtitles
,