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