]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/expressen.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / expressen.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 unescapeHTML,
6 unified_timestamp,
7 )
8
9
10 class ExpressenIE(InfoExtractor):
11 _VALID_URL = r'''(?x)
12 https?://
13 (?:www\.)?(?:expressen|di)\.se/
14 (?:(?:tvspelare/video|videoplayer/embed)/)?
15 tv/(?:[^/]+/)*
16 (?P<id>[^/?#&]+)
17 '''
18 _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?(?:expressen|di)\.se/(?:tvspelare/video|videoplayer/embed)/tv/.+?)\1']
19 _TESTS = [{
20 'url': 'https://www.expressen.se/tv/ledare/ledarsnack/ledarsnack-om-arbetslosheten-bland-kvinnor-i-speciellt-utsatta-omraden/',
21 'md5': 'deb2ca62e7b1dcd19fa18ba37523f66e',
22 'info_dict': {
23 'id': 'ba90f5a9-78d1-4511-aa02-c177b9c99136',
24 'display_id': 'ledarsnack-om-arbetslosheten-bland-kvinnor-i-speciellt-utsatta-omraden',
25 'ext': 'mp4',
26 'title': 'Ledarsnack: Om arbetslösheten bland kvinnor i speciellt utsatta områden',
27 'description': 'md5:f38c81ff69f3de4d269bbda012fcbbba',
28 'thumbnail': r're:^https?://.*\.jpg$',
29 'duration': 788,
30 'timestamp': 1526639109,
31 'upload_date': '20180518',
32 },
33 }, {
34 'url': 'https://www.expressen.se/tv/kultur/kulturdebatt-med-expressens-karin-olsson/',
35 'only_matching': True,
36 }, {
37 'url': 'https://www.expressen.se/tvspelare/video/tv/ditv/ekonomistudion/experterna-har-ar-fragorna-som-avgor-valet/?embed=true&external=true&autoplay=true&startVolume=0&partnerId=di',
38 'only_matching': True,
39 }, {
40 'url': 'https://www.expressen.se/videoplayer/embed/tv/ditv/ekonomistudion/experterna-har-ar-fragorna-som-avgor-valet/?embed=true&external=true&autoplay=true&startVolume=0&partnerId=di',
41 'only_matching': True,
42 }, {
43 'url': 'https://www.di.se/videoplayer/embed/tv/ditv/borsmorgon/implantica-rusar-70--under-borspremiaren-hor-styrelsemedlemmen/?embed=true&external=true&autoplay=true&startVolume=0&partnerId=di',
44 'only_matching': True,
45 }]
46
47 def _real_extract(self, url):
48 display_id = self._match_id(url)
49
50 webpage = self._download_webpage(url, display_id)
51
52 def extract_data(name):
53 return self._parse_json(
54 self._search_regex(
55 r'data-%s=(["\'])(?P<value>(?:(?!\1).)+)\1' % name,
56 webpage, 'info', group='value'),
57 display_id, transform_source=unescapeHTML)
58
59 info = extract_data('video-tracking-info')
60 video_id = info['contentId']
61
62 data = extract_data('article-data')
63 stream = data['stream']
64
65 if determine_ext(stream) == 'm3u8':
66 formats = self._extract_m3u8_formats(
67 stream, display_id, 'mp4', entry_protocol='m3u8_native',
68 m3u8_id='hls')
69 else:
70 formats = [{
71 'url': stream,
72 }]
73
74 title = info.get('titleRaw') or data['title']
75 description = info.get('descriptionRaw')
76 thumbnail = info.get('socialMediaImage') or data.get('image')
77 duration = int_or_none(info.get('videoTotalSecondsDuration')
78 or data.get('totalSecondsDuration'))
79 timestamp = unified_timestamp(info.get('publishDate'))
80
81 return {
82 'id': video_id,
83 'display_id': display_id,
84 'title': title,
85 'description': description,
86 'thumbnail': thumbnail,
87 'duration': duration,
88 'timestamp': timestamp,
89 'formats': formats,
90 }