]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/laxarxames.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / laxarxames.py
1 import json
2
3 from .brightcove import BrightcoveNewIE
4 from .common import InfoExtractor
5 from ..utils import ExtractorError
6 from ..utils.traversal import traverse_obj
7
8
9 class LaXarxaMesIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
11 _NETRC_MACHINE = 'laxarxames'
12 _TOKEN = None
13 _TESTS = [{
14 'url': 'https://www.laxarxames.cat/player/3459421',
15 'md5': '0966f46c34275934c19af78f3df6e2bc',
16 'info_dict': {
17 'id': '6339612436112',
18 'ext': 'mp4',
19 'title': 'Resum | UA Horta — UD Viladecans',
20 'timestamp': 1697905186,
21 'thumbnail': r're:https?://.*\.jpg',
22 'description': '',
23 'upload_date': '20231021',
24 'duration': 129.44,
25 'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
26 'uploader_id': '5779379807001',
27 },
28 'skip': 'Requires login',
29 }]
30
31 def _perform_login(self, username, password):
32 if self._TOKEN:
33 return
34
35 login = self._download_json(
36 'https://api.laxarxames.cat/Authorization/SignIn', None, note='Logging in', headers={
37 'X-Tenantorigin': 'https://laxarxames.cat',
38 'Content-Type': 'application/json',
39 }, data=json.dumps({
40 'Username': username,
41 'Password': password,
42 'Device': {
43 'PlatformCode': 'WEB',
44 'Name': 'Mac OS ()',
45 },
46 }).encode(), expected_status=401)
47
48 self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
49 if not self._TOKEN:
50 raise ExtractorError('Login failed', expected=True)
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54 if not self._TOKEN:
55 self.raise_login_required()
56
57 media_play_info = self._download_json(
58 'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
59 data=json.dumps({
60 'MediaId': int(video_id),
61 'StreamType': 'MAIN',
62 }).encode(), headers={
63 'Authorization': f'Bearer {self._TOKEN}',
64 'X-Tenantorigin': 'https://laxarxames.cat',
65 'Content-Type': 'application/json',
66 })
67
68 if not traverse_obj(media_play_info, ('ContentUrl', {str})):
69 self.raise_no_formats('No video found', expected=True)
70
71 return self.url_result(
72 f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
73 BrightcoveNewIE, video_id, media_play_info.get('Title'))