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