4 from .common
import InfoExtractor
11 from ..utils
.traversal
import traverse_obj
14 class BoxIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:[^.]+\.)?(?P<service>app|ent)\.box\.com/s/(?P<shared_name>[^/?#]+)(?:/file/(?P<id>\d+))?'
17 'url': 'https://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538',
18 'md5': '1f81b2fd3960f38a40a3b8823e5fcd43',
22 'title': 'Garber St. Louis will be 28th MLS team +scarving.mp4',
24 'timestamp': 1566320259,
25 'upload_date': '20190820',
26 'uploader_id': '235196876',
28 'params': {'skip_download': 'dash fragment too small'},
30 'url': 'https://utexas.app.box.com/s/2x6vanv85fdl8j2eqlcxmv0gp1wvps6e',
34 'title': 'Webinar recording: Take the Leap!.mp4',
35 'uploader': 'Patricia Mosele',
36 'timestamp': 1615824864,
37 'upload_date': '20210315',
38 'uploader_id': '239068974',
40 'params': {'skip_download': 'dash fragment too small'},
42 'url': 'https://thejacksonlaboratory.ent.box.com/s/2x09dm6vcg6y28o0oox1so4l0t8wzt6l/file/1536173056065',
44 'id': '1536173056065',
46 'uploader_id': '18523128264',
47 'uploader': 'Lexi Hennigan',
48 'title': 'iPSC Symposium recording part 1.mp4',
49 'timestamp': 1716228343,
50 'upload_date': '20240520',
52 'params': {'skip_download': 'dash fragment too small'},
55 def _real_extract(self
, url
):
56 shared_name
, file_id
, service
= self
._match
_valid
_url
(url
).group('shared_name', 'id', 'service')
57 webpage
= self
._download
_webpage
(url
, file_id
or shared_name
)
60 post_stream_data
= self
._search
_json
(
61 r
'Box\.postStreamData\s*=', webpage
, 'Box post-stream data', shared_name
)
62 shared_item
= traverse_obj(
63 post_stream_data
, ('/app-api/enduserapp/shared-item', {dict}
)) or {}
64 if shared_item
.get('itemType') != 'file':
65 raise ExtractorError('The requested resource is not a file', expected
=True)
67 file_id
= str(shared_item
['itemID'])
69 request_token
= self
._search
_json
(
70 r
'Box\.config\s*=', webpage
, 'Box config', file_id
)['requestToken']
71 access_token
= self
._download
_json
(
72 f
'https://{service}.box.com/app-api/enduserapp/elements/tokens', file_id
,
73 'Downloading token JSON metadata',
74 data
=json
.dumps({'fileIDs': [file_id
]}).encode(), headers
={
75 'Content-Type': 'application/json',
76 'X-Request-Token': request_token
,
77 'X-Box-EndUser-API': 'sharedName=' + shared_name
,
79 shared_link
= f
'https://{service}.box.com/s/{shared_name}'
80 f
= self
._download
_json
(
81 'https://api.box.com/2.0/files/' + file_id
, file_id
,
82 'Downloading file JSON metadata', headers
={
83 'Authorization': 'Bearer ' + access_token
,
84 'BoxApi': 'shared_link=' + shared_link
,
85 'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats
87 'fields': 'authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size',
92 'access_token': access_token
,
93 'shared_link': shared_link
,
98 for url_tmpl
in traverse_obj(f
, (
99 'representations', 'entries', lambda _
, v
: v
['representation'] == 'dash',
100 'content', 'url_template', {url_or_none}
,
102 manifest_url
= update_url_query(url_tmpl
.replace('{+asset_path}', 'manifest.mpd'), query
)
103 fmts
= self
._extract
_mpd
_formats
(manifest_url
, file_id
)
105 fmt
['extra_param_to_segment_url'] = urllib
.parse
.urlparse(manifest_url
).query
108 creator
= f
.get('created_by') or {}
114 'description': f
.get('description') or None,
115 'uploader': creator
.get('name'),
116 'timestamp': parse_iso8601(f
.get('created_at')),
117 'uploader_id': creator
.get('id'),