4 from .common
import InfoExtractor
10 from ..utils
.traversal
import traverse_obj
13 class BoxIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:[^.]+\.)?app\.box\.com/s/(?P<shared_name>[^/?#]+)/file/(?P<id>\d+)'
16 'url': 'https://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538',
17 'md5': '1f81b2fd3960f38a40a3b8823e5fcd43',
21 'title': 'Garber St. Louis will be 28th MLS team +scarving.mp4',
23 'timestamp': 1566320259,
24 'upload_date': '20190820',
25 'uploader_id': '235196876',
27 'params': {'skip_download': 'dash fragment too small'}
,
30 def _real_extract(self
, url
):
31 shared_name
, file_id
= self
._match
_valid
_url
(url
).groups()
32 webpage
= self
._download
_webpage
(url
, file_id
)
33 request_token
= self
._parse
_json
(self
._search
_regex
(
34 r
'Box\.config\s*=\s*({.+?});', webpage
,
35 'Box config'), file_id
)['requestToken']
36 access_token
= self
._download
_json
(
37 'https://app.box.com/app-api/enduserapp/elements/tokens', file_id
,
38 'Downloading token JSON metadata',
39 data
=json
.dumps({'fileIDs': [file_id]}
).encode(), headers
={
40 'Content-Type': 'application/json',
41 'X-Request-Token': request_token
,
42 'X-Box-EndUser-API': 'sharedName=' + shared_name
,
44 shared_link
= 'https://app.box.com/s/' + shared_name
45 f
= self
._download
_json
(
46 'https://api.box.com/2.0/files/' + file_id
, file_id
,
47 'Downloading file JSON metadata', headers
={
48 'Authorization': 'Bearer ' + access_token
,
49 'BoxApi': 'shared_link=' + shared_link
,
50 'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats
52 'fields': 'authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size'
57 'access_token': access_token
,
58 'shared_link': shared_link
63 for url_tmpl
in traverse_obj(f
, (
64 'representations', 'entries', lambda _
, v
: v
['representation'] == 'dash',
65 'content', 'url_template', {url_or_none}
67 manifest_url
= update_url_query(url_tmpl
.replace('{+asset_path}', 'manifest.mpd'), query
)
68 fmts
= self
._extract
_mpd
_formats
(manifest_url
, file_id
)
70 fmt
['extra_param_to_segment_url'] = urllib
.parse
.urlparse(manifest_url
).query
73 creator
= f
.get('created_by') or {}
79 'description': f
.get('description') or None,
80 'uploader': creator
.get('name'),
81 'timestamp': parse_iso8601(f
.get('created_at')),
82 'uploader_id': creator
.get('id'),