4 from .common
import InfoExtractor
11 from ..utils
.traversal
import traverse_obj
14 class BoxIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:[^.]+\.)?app\.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'}
,
43 def _real_extract(self
, url
):
44 shared_name
, file_id
= self
._match
_valid
_url
(url
).groups()
45 webpage
= self
._download
_webpage
(url
, file_id
or shared_name
)
48 post_stream_data
= self
._search
_json
(
49 r
'Box\.postStreamData\s*=', webpage
, 'Box post-stream data', shared_name
)
50 shared_item
= traverse_obj(
51 post_stream_data
, ('/app-api/enduserapp/shared-item', {dict}
)) or {}
52 if shared_item
.get('itemType') != 'file':
53 raise ExtractorError('The requested resource is not a file', expected
=True)
55 file_id
= str(shared_item
['itemID'])
57 request_token
= self
._search
_json
(
58 r
'Box\.config\s*=', webpage
, 'Box config', file_id
)['requestToken']
59 access_token
= self
._download
_json
(
60 'https://app.box.com/app-api/enduserapp/elements/tokens', file_id
,
61 'Downloading token JSON metadata',
62 data
=json
.dumps({'fileIDs': [file_id]}
).encode(), headers
={
63 'Content-Type': 'application/json',
64 'X-Request-Token': request_token
,
65 'X-Box-EndUser-API': 'sharedName=' + shared_name
,
67 shared_link
= 'https://app.box.com/s/' + shared_name
68 f
= self
._download
_json
(
69 'https://api.box.com/2.0/files/' + file_id
, file_id
,
70 'Downloading file JSON metadata', headers
={
71 'Authorization': 'Bearer ' + access_token
,
72 'BoxApi': 'shared_link=' + shared_link
,
73 'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats
75 'fields': 'authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size',
80 'access_token': access_token
,
81 'shared_link': shared_link
,
86 for url_tmpl
in traverse_obj(f
, (
87 'representations', 'entries', lambda _
, v
: v
['representation'] == 'dash',
88 'content', 'url_template', {url_or_none}
,
90 manifest_url
= update_url_query(url_tmpl
.replace('{+asset_path}', 'manifest.mpd'), query
)
91 fmts
= self
._extract
_mpd
_formats
(manifest_url
, file_id
)
93 fmt
['extra_param_to_segment_url'] = urllib
.parse
.urlparse(manifest_url
).query
96 creator
= f
.get('created_by') or {}
102 'description': f
.get('description') or None,
103 'uploader': creator
.get('name'),
104 'timestamp': parse_iso8601(f
.get('created_at')),
105 'uploader_id': creator
.get('id'),