2020-11-26 22:57:34 +05:30
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..utils import (
|
|
|
|
|
int_or_none,
|
2025-11-19 00:52:55 +01:00
|
|
|
url_or_none,
|
2020-11-26 22:57:34 +05:30
|
|
|
)
|
2025-11-19 00:52:55 +01:00
|
|
|
from ..utils.traversal import traverse_obj
|
2020-11-26 22:57:34 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class MedalTVIE(InfoExtractor):
|
2023-03-12 19:38:27 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?medal\.tv/games/[^/?#&]+/clips/(?P<id>[^/?#&]+)'
|
2020-11-26 22:57:34 +05:30
|
|
|
_TESTS = [{
|
2022-08-22 22:04:12 +02:00
|
|
|
'url': 'https://medal.tv/games/valorant/clips/jTBFnLKdLy15K',
|
2024-01-29 02:23:52 +05:00
|
|
|
'md5': '03e4911fdcf7fce563090705c2e79267',
|
2022-08-22 22:04:12 +02:00
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'jTBFnLKdLy15K',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': "Mornu's clutch",
|
|
|
|
|
'description': '',
|
|
|
|
|
'uploader': 'Aciel',
|
|
|
|
|
'timestamp': 1651628243,
|
|
|
|
|
'upload_date': '20220504',
|
|
|
|
|
'uploader_id': '19335460',
|
|
|
|
|
'uploader_url': 'https://medal.tv/users/19335460',
|
|
|
|
|
'comment_count': int,
|
|
|
|
|
'view_count': int,
|
|
|
|
|
'like_count': int,
|
|
|
|
|
'duration': 13,
|
2025-11-19 00:52:55 +01:00
|
|
|
'thumbnail': r're:https://cdn\.medal\.tv/ugcp/content-thumbnail/.*\.jpg',
|
|
|
|
|
'tags': ['headshot', 'valorant', '4k', 'clutch', 'mornu'],
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2020-11-26 22:57:34 +05:30
|
|
|
}, {
|
2024-01-29 02:23:52 +05:00
|
|
|
'url': 'https://medal.tv/games/cod-cold-war/clips/2um24TWdty0NA',
|
2020-11-26 22:57:34 +05:30
|
|
|
'md5': 'b6dc76b78195fff0b4f8bf4a33ec2148',
|
|
|
|
|
'info_dict': {
|
2021-05-06 21:31:20 +05:30
|
|
|
'id': '2um24TWdty0NA',
|
2020-11-26 22:57:34 +05:30
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'u tk me i tk u bigger',
|
2025-11-19 00:52:55 +01:00
|
|
|
'description': '',
|
|
|
|
|
'uploader': 'zahl',
|
2020-11-26 22:57:34 +05:30
|
|
|
'timestamp': 1605580939,
|
|
|
|
|
'upload_date': '20201117',
|
2021-05-06 21:31:20 +05:30
|
|
|
'uploader_id': '5156321',
|
2025-11-19 00:52:55 +01:00
|
|
|
'thumbnail': r're:https://cdn\.medal\.tv/source/.*\.png',
|
2022-08-22 22:04:12 +02:00
|
|
|
'uploader_url': 'https://medal.tv/users/5156321',
|
|
|
|
|
'comment_count': int,
|
|
|
|
|
'view_count': int,
|
|
|
|
|
'like_count': int,
|
|
|
|
|
'duration': 9,
|
2024-06-12 01:09:58 +02:00
|
|
|
},
|
2021-05-06 21:31:20 +05:30
|
|
|
}, {
|
2025-11-19 00:52:55 +01:00
|
|
|
# API requires auth
|
2022-08-22 22:04:12 +02:00
|
|
|
'url': 'https://medal.tv/games/valorant/clips/2WRj40tpY_EU9',
|
2025-11-19 00:52:55 +01:00
|
|
|
'md5': '6c6bb6569777fd8b4ef7b33c09de8dcf',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2WRj40tpY_EU9',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': '1v5 clutch',
|
|
|
|
|
'description': '',
|
|
|
|
|
'uploader': 'adny',
|
|
|
|
|
'uploader_id': '6256941',
|
|
|
|
|
'uploader_url': 'https://medal.tv/users/6256941',
|
|
|
|
|
'comment_count': int,
|
|
|
|
|
'view_count': int,
|
|
|
|
|
'like_count': int,
|
|
|
|
|
'duration': 25,
|
|
|
|
|
'thumbnail': r're:https://cdn\.medal\.tv/source/.*\.jpg',
|
|
|
|
|
'timestamp': 1612896680,
|
|
|
|
|
'upload_date': '20210209',
|
|
|
|
|
},
|
|
|
|
|
'expected_warnings': ['Video formats are not available through API'],
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://medal.tv/games/valorant/clips/37rMeFpryCC-9',
|
2021-05-06 21:31:20 +05:30
|
|
|
'only_matching': True,
|
2020-11-26 22:57:34 +05:30
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
video_id = self._match_id(url)
|
2022-08-22 22:04:12 +02:00
|
|
|
|
2025-11-19 00:52:55 +01:00
|
|
|
content_data = self._download_json(
|
|
|
|
|
f'https://medal.tv/api/content/{video_id}', video_id,
|
|
|
|
|
headers={'Accept': 'application/json'})
|
2020-11-26 22:57:34 +05:30
|
|
|
|
|
|
|
|
formats = []
|
2025-11-19 00:52:55 +01:00
|
|
|
if m3u8_url := url_or_none(content_data.get('contentUrlHls')):
|
|
|
|
|
formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls'))
|
|
|
|
|
if http_url := url_or_none(content_data.get('contentUrl')):
|
|
|
|
|
formats.append({
|
|
|
|
|
'url': http_url,
|
|
|
|
|
'format_id': 'http-source',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'quality': 1,
|
|
|
|
|
})
|
|
|
|
|
formats = [fmt for fmt in formats if 'video/privacy-protected-guest' not in fmt['url']]
|
|
|
|
|
if not formats:
|
|
|
|
|
# Fallback, does not require auth
|
|
|
|
|
self.report_warning('Video formats are not available through API, falling back to social video URL')
|
|
|
|
|
urlh = self._request_webpage(
|
|
|
|
|
f'https://medal.tv/api/content/{video_id}/socialVideoUrl', video_id,
|
|
|
|
|
note='Checking social video URL')
|
|
|
|
|
formats.append({
|
|
|
|
|
'url': urlh.url,
|
|
|
|
|
'format_id': 'social-video',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'quality': -1,
|
|
|
|
|
})
|
2020-11-26 22:57:34 +05:30
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'formats': formats,
|
2025-11-19 00:52:55 +01:00
|
|
|
**traverse_obj(content_data, {
|
|
|
|
|
'title': ('contentTitle', {str}),
|
|
|
|
|
'description': ('contentDescription', {str}),
|
|
|
|
|
'timestamp': ('created', {int_or_none(scale=1000)}),
|
|
|
|
|
'duration': ('videoLengthSeconds', {int_or_none}),
|
|
|
|
|
'view_count': ('views', {int_or_none}),
|
|
|
|
|
'like_count': ('likes', {int_or_none}),
|
|
|
|
|
'comment_count': ('comments', {int_or_none}),
|
|
|
|
|
'uploader': ('poster', 'displayName', {str}),
|
|
|
|
|
'uploader_id': ('poster', 'userId', {str}),
|
|
|
|
|
'uploader_url': ('poster', 'userId', {str}, filter, {lambda x: x and f'https://medal.tv/users/{x}'}),
|
|
|
|
|
'tags': ('tags', ..., {str}),
|
|
|
|
|
'thumbnail': ('thumbnailUrl', {url_or_none}),
|
|
|
|
|
}),
|
2020-11-26 22:57:34 +05:30
|
|
|
}
|