[infomaniak] Improve VOD2 extractor

Address PR review comments
This commit is contained in:
hwang-cadent 2025-12-16 10:04:08 -06:00
parent 6effd78ce0
commit 72c199983c

View file

@ -1,10 +1,17 @@
# coding: utf-8
from __future__ import unicode_literals
from ..compat import compat_str as str
from .common import InfoExtractor
from ..utils import (
ExtractorError,
merge_dicts,
parse_duration,
str_or_none,
T,
traverse_obj,
url_or_none,
)
@ -13,15 +20,16 @@ class InfomaniakVod2IE(InfoExtractor):
_VALID_URL = r'https?://player\.vod2\.infomaniak\.com/embed/(?P<id>[0-9a-z]+)'
_TEST = {
'url': 'https://player.vod2.infomaniak.com/embed/1jhvl2uqg6ywp',
'md5': '08c3a89906b70a614fa0fdb057e8a22e',
'info_dict': {
'id': '1jhvl2uqg6xis',
'display_id': '1jhvl2uqg6ywp',
'ext': 'mp4',
'title': 'Conférence à Dyo, octobre 2022',
'thumbnail': r're:^https?://.*\.(?:jpe?g|png)$',
'thumbnail': r're:https?://.+\.(?:jpe?g|png)$',
},
'params': {
'skip_download': True,
'format': 'http',
},
}
@ -30,20 +38,11 @@ class InfomaniakVod2IE(InfoExtractor):
share = self._download_json(
'https://api.infomaniak.com/2/vod/res/shares/%s.json' % share_id,
share_id)
data = (share or {}).get('data') or {}
media = data.get('media') or []
entries = []
for m in media:
if not isinstance(m, dict):
continue
media_id = m.get('id') or share_id
title = m.get('title') or share_id
duration = parse_duration(m.get('duration'))
thumbnails = m.get('thumbnails') or {}
thumbnail = thumbnails.get('poster') or thumbnails.get('image')
source = m.get('source') or {}
for media in traverse_obj(share, (
'data', 'media', lambda _, v: v.get('source').get)):
media_id = media.get('id') or share_id
source = media['source']
formats = []
hls_url = source.get('hls')
@ -62,27 +61,33 @@ class InfomaniakVod2IE(InfoExtractor):
formats.append({
'url': best_url,
'format_id': 'http',
'preference': 10,
})
self._sort_formats(formats)
entries.append({
'id': media_id,
'display_id': share_id,
'title': title,
'duration': duration,
'thumbnail': thumbnail,
'formats': formats,
'webpage_url': url,
})
entries.append(merge_dicts(
traverse_obj(media, {
'id': ('id', T(str_or_none)),
'title': ('title', T(str)),
'duration': ('duration', T(parse_duration)),
'thumbnail': ('thumbnails', ('poster', 'image'), T(url_or_none), any),
}), {
'display_id': share_id,
'formats': formats,
}))
if len(entries) == 1:
return merge_dicts({
'id': share_id,
'display_id': share_id,
}, entries[0], rev=True)
entries = [e for e in entries if e.get('id')]
if not entries:
# Keep the error message actionable for site support requests
raise ExtractorError('Unable to find any media in share JSON', expected=True)
if len(entries) == 1:
return entries[0]
return self.playlist_result(entries, playlist_id=share_id)