[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / laxarxames.py
blobf6d515b2185c722252039139a2859c0814ae062e
1 import json
3 from .brightcove import BrightcoveNewIE
4 from .common import InfoExtractor
5 from ..utils import ExtractorError
6 from ..utils.traversal import traverse_obj
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',
28 'skip': 'Requires login',
31 def _perform_login(self, username, password):
32 if self._TOKEN:
33 return
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 ()',
46 }).encode(), expected_status=401)
48 self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
49 if not self._TOKEN:
50 raise ExtractorError('Login failed', expected=True)
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54 if not self._TOKEN:
55 self.raise_login_required()
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',
68 if not traverse_obj(media_play_info, ('ContentUrl', {str})):
69 self.raise_no_formats('No video found', expected=True)
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'))