Merge 0cca4de1ae173b4f2623ce317acfb9a1a0c15ab0 into 2b4fbfce25902d557b86b003cf48f738129efce4

This commit is contained in:
Anders Törnkvist 2025-03-26 08:12:19 +00:00 committed by GitHub
commit 7b4e833522
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,13 +8,13 @@ from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
parse_iso8601, parse_iso8601,
# try_get, try_get,
update_url_query, update_url_query,
) )
class BoxIE(InfoExtractor): class BoxIE(InfoExtractor):
_VALID_URL = r'https?://(?:[^.]+\.)?app\.box\.com/s/(?P<shared_name>[^/]+)/file/(?P<id>\d+)' _VALID_URL = r'https?://(?P<prefix>(?:[^.]+\.)?)app\.box\.com/s/(?P<shared_name>[^/]+)(?:/file/(?P<id>\d+))?'
_TEST = { _TEST = {
'url': 'https://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538', 'url': 'https://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538',
'md5': '1f81b2fd3960f38a40a3b8823e5fcd43', 'md5': '1f81b2fd3960f38a40a3b8823e5fcd43',
@ -30,20 +30,22 @@ class BoxIE(InfoExtractor):
} }
def _real_extract(self, url): def _real_extract(self, url):
shared_name, file_id = re.match(self._VALID_URL, url).groups() prefix, shared_name, file_id = re.match(self._VALID_URL, url).groups()
webpage = self._download_webpage(url, file_id) webpage = self._download_webpage(url, file_id)
if not file_id:
file_id = re.search(r'"typedID":\s*"f_(\d+)"', webpage).group(1)
request_token = self._parse_json(self._search_regex( request_token = self._parse_json(self._search_regex(
r'Box\.config\s*=\s*({.+?});', webpage, r'Box\.config\s*=\s*({.+?});', webpage,
'Box config'), file_id)['requestToken'] 'Box config'), file_id)['requestToken']
access_token = self._download_json( access_token = self._download_json(
'https://app.box.com/app-api/enduserapp/elements/tokens', file_id, 'https://' + prefix + 'app.box.com/app-api/enduserapp/elements/tokens', file_id,
'Downloading token JSON metadata', 'Downloading token JSON metadata',
data=json.dumps({'fileIDs': [file_id]}).encode(), headers={ data=json.dumps({'fileIDs': [file_id]}).encode(), headers={
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Request-Token': request_token, 'X-Request-Token': request_token,
'X-Box-EndUser-API': 'sharedName=' + shared_name, 'X-Box-EndUser-API': 'sharedName=' + shared_name,
})[file_id]['read'] })[file_id]['read']
shared_link = 'https://app.box.com/s/' + shared_name shared_link = 'https://' + prefix + 'app.box.com/s/' + shared_name
f = self._download_json( f = self._download_json(
'https://api.box.com/2.0/files/' + file_id, file_id, 'https://api.box.com/2.0/files/' + file_id, file_id,
'Downloading file JSON metadata', headers={ 'Downloading file JSON metadata', headers={
@ -51,7 +53,7 @@ class BoxIE(InfoExtractor):
'BoxApi': 'shared_link=' + shared_link, 'BoxApi': 'shared_link=' + shared_link,
'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats 'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats
}, query={ }, query={
'fields': 'authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size' 'fields': 'permissions,authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size'
}) })
title = f['name'] title = f['name']
@ -62,20 +64,24 @@ class BoxIE(InfoExtractor):
formats = [] formats = []
# for entry in (try_get(f, lambda x: x['representations']['entries'], list) or []): for entry in (try_get(f, lambda x: x['representations']['entries'], list) or []):
# entry_url_template = try_get( entry_url_template = try_get(
# entry, lambda x: x['content']['url_template']) entry, lambda x: x['content']['url_template'])
# if not entry_url_template: if not entry_url_template:
# continue continue
# representation = entry.get('representation') representation = entry.get('representation')
# if representation == 'dash': if representation == 'dash':
# TODO: append query to every fragment URL extracted = self._extract_mpd_formats(
# formats.extend(self._extract_mpd_formats( entry_url_template.replace('{+asset_path}', 'manifest.mpd'),
# entry_url_template.replace('{+asset_path}', 'manifest.mpd'), file_id, query=query)
# file_id, query=query)) for extracted_format in extracted:
for fragment in extracted_format['fragments']:
fragment['path'] = update_url_query(fragment['path'], query)
formats.extend(extracted)
authenticated_download_url = f.get('authenticated_download_url') authenticated_download_url = f.get('authenticated_download_url')
if authenticated_download_url and f.get('is_download_available'): permissions = f.get('permissions') or {}
if authenticated_download_url and f.get('is_download_available') and permissions.get('can_download', True):
formats.append({ formats.append({
'ext': f.get('extension') or determine_ext(title), 'ext': f.get('extension') or determine_ext(title),
'filesize': f.get('size'), 'filesize': f.get('size'),