summaryrefslogtreecommitdiffstats
path: root/yt_dlp/extractor/expressen.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:49:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:49:24 +0000
commit2415e66f889f38503b73e8ebc5f43ca342390e5c (patch)
treeac48ab69d1d96bae3d83756134921e0d90593aa5 /yt_dlp/extractor/expressen.py
parentInitial commit. (diff)
downloadyt-dlp-2415e66f889f38503b73e8ebc5f43ca342390e5c.tar.xz
yt-dlp-2415e66f889f38503b73e8ebc5f43ca342390e5c.zip
Adding upstream version 2024.03.10.upstream/2024.03.10
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'yt_dlp/extractor/expressen.py')
-rw-r--r--yt_dlp/extractor/expressen.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/yt_dlp/extractor/expressen.py b/yt_dlp/extractor/expressen.py
new file mode 100644
index 0000000..b96f2e4
--- /dev/null
+++ b/yt_dlp/extractor/expressen.py
@@ -0,0 +1,96 @@
+from .common import InfoExtractor
+from ..utils import (
+ determine_ext,
+ int_or_none,
+ unescapeHTML,
+ unified_timestamp,
+)
+
+
+class ExpressenIE(InfoExtractor):
+ _VALID_URL = r'''(?x)
+ https?://
+ (?:www\.)?(?:expressen|di)\.se/
+ (?:(?:tvspelare/video|video-?player/embed)/)?
+ (?:tv|nyheter)/(?:[^/?#]+/)*
+ (?P<id>[^/?#&]+)
+ '''
+ _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?(?:expressen|di)\.se/(?:tvspelare/video|videoplayer/embed)/tv/.+?)\1']
+ _TESTS = [{
+ 'url': 'https://www.expressen.se/tv/ledare/ledarsnack/ledarsnack-om-arbetslosheten-bland-kvinnor-i-speciellt-utsatta-omraden/',
+ 'md5': 'deb2ca62e7b1dcd19fa18ba37523f66e',
+ 'info_dict': {
+ 'id': 'ba90f5a9-78d1-4511-aa02-c177b9c99136',
+ 'display_id': 'ledarsnack-om-arbetslosheten-bland-kvinnor-i-speciellt-utsatta-omraden',
+ 'ext': 'mp4',
+ 'title': 'Ledarsnack: Om arbetslösheten bland kvinnor i speciellt utsatta områden',
+ 'description': 'md5:f38c81ff69f3de4d269bbda012fcbbba',
+ 'thumbnail': r're:^https?://.*\.jpg$',
+ 'duration': 788,
+ 'timestamp': 1526639109,
+ 'upload_date': '20180518',
+ },
+ }, {
+ 'url': 'https://www.expressen.se/tv/kultur/kulturdebatt-med-expressens-karin-olsson/',
+ 'only_matching': True,
+ }, {
+ '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',
+ 'only_matching': True,
+ }, {
+ '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',
+ 'only_matching': True,
+ }, {
+ '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',
+ 'only_matching': True,
+ }, {
+ 'url': 'https://www.expressen.se/video-player/embed/tv/nyheter/ekero-fodda-olof-gustafsson-forvaltar-knarkbaronen-pablo-escobars-namn',
+ 'only_matching': True,
+ }, {
+ 'url': 'https://www.expressen.se/nyheter/efter-egna-telefonbluffen-escobar-stammer-klarna/',
+ 'only_matching': True,
+ }]
+
+ def _real_extract(self, url):
+ display_id = self._match_id(url)
+
+ webpage = self._download_webpage(url, display_id)
+
+ def extract_data(name):
+ return self._parse_json(
+ self._search_regex(
+ r'data-%s=(["\'])(?P<value>(?:(?!\1).)+)\1' % name,
+ webpage, 'info', group='value'),
+ display_id, transform_source=unescapeHTML)
+
+ info = extract_data('video-tracking-info')
+ video_id = info['contentId']
+
+ data = extract_data('article-data')
+ stream = data['stream']
+
+ if determine_ext(stream) == 'm3u8':
+ formats = self._extract_m3u8_formats(
+ stream, display_id, 'mp4', entry_protocol='m3u8_native',
+ m3u8_id='hls')
+ else:
+ formats = [{
+ 'url': stream,
+ }]
+
+ title = info.get('titleRaw') or data['title']
+ description = info.get('descriptionRaw')
+ thumbnail = info.get('socialMediaImage') or data.get('image')
+ duration = int_or_none(info.get('videoTotalSecondsDuration')
+ or data.get('totalSecondsDuration'))
+ timestamp = unified_timestamp(info.get('publishDate'))
+
+ return {
+ 'id': video_id,
+ 'display_id': display_id,
+ 'title': title,
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'duration': duration,
+ 'timestamp': timestamp,
+ 'formats': formats,
+ }