3 from .common
import InfoExtractor
12 class BoxIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:[^.]+\.)?app\.box\.com/s/(?P<shared_name>[^/]+)/file/(?P<id>\d+)'
15 'url': 'https://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538',
16 'md5': '1f81b2fd3960f38a40a3b8823e5fcd43',
20 'title': 'Garber St. Louis will be 28th MLS team +scarving.mp4',
21 'uploader': 'MLS Video',
22 'timestamp': 1566320259,
23 'upload_date': '20190820',
24 'uploader_id': '235196876',
28 def _real_extract(self
, url
):
29 shared_name
, file_id
= self
._match
_valid
_url
(url
).groups()
30 webpage
= self
._download
_webpage
(url
, file_id
)
31 request_token
= self
._parse
_json
(self
._search
_regex
(
32 r
'Box\.config\s*=\s*({.+?});', webpage
,
33 'Box config'), file_id
)['requestToken']
34 access_token
= self
._download
_json
(
35 'https://app.box.com/app-api/enduserapp/elements/tokens', file_id
,
36 'Downloading token JSON metadata',
37 data
=json
.dumps({'fileIDs': [file_id]}
).encode(), headers
={
38 'Content-Type': 'application/json',
39 'X-Request-Token': request_token
,
40 'X-Box-EndUser-API': 'sharedName=' + shared_name
,
42 shared_link
= 'https://app.box.com/s/' + shared_name
43 f
= self
._download
_json
(
44 'https://api.box.com/2.0/files/' + file_id
, file_id
,
45 'Downloading file JSON metadata', headers
={
46 'Authorization': 'Bearer ' + access_token
,
47 'BoxApi': 'shared_link=' + shared_link
,
48 'X-Rep-Hints': '[dash]', # TODO: extract `hls` formats
50 'fields': 'authenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size'
55 'access_token': access_token
,
56 'shared_link': shared_link
61 # for entry in (try_get(f, lambda x: x['representations']['entries'], list) or []):
62 # entry_url_template = try_get(
63 # entry, lambda x: x['content']['url_template'])
64 # if not entry_url_template:
66 # representation = entry.get('representation')
67 # if representation == 'dash':
68 # TODO: append query to every fragment URL
69 # formats.extend(self._extract_mpd_formats(
70 # entry_url_template.replace('{+asset_path}', 'manifest.mpd'),
71 # file_id, query=query))
73 authenticated_download_url
= f
.get('authenticated_download_url')
74 if authenticated_download_url
and f
.get('is_download_available'):
76 'ext': f
.get('extension') or determine_ext(title
),
77 'filesize': f
.get('size'),
78 'format_id': 'download',
79 'url': update_url_query(authenticated_download_url
, query
),
82 self
._sort
_formats
(formats
)
84 creator
= f
.get('created_by') or {}
90 'description': f
.get('description') or None,
91 'uploader': creator
.get('name'),
92 'timestamp': parse_iso8601(f
.get('created_at')),
93 'uploader_id': creator
.get('id'),