Skip to content

Commit 22e4687

Browse files
files: support videos as additional files
1 parent 805a40d commit 22e4687

File tree

11 files changed

+327
-123
lines changed

11 files changed

+327
-123
lines changed

Bruno Collection - CDS Videos Publish Video.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"params": [],
8080
"body": {
8181
"mode": "json",
82-
"json": "{\n \"$schema\": \"https://localhost:5000/schemas/deposits/records/videos/project/project-v1.0.0.json\",\n \"_access\": {\n \"update\": [\n \"admin@test.ch\",\n \"your-egroup@cern.ch\"\n ],\n \"read\": [ // If you want to restrict the project, add access read\n \"your-egroup@cern.ch\"\n ]\n },\n // Add category and type\n \"category\": \"ATLAS\",\n \"type\": \"VIDEO\"\n}",
82+
"json": "{\n \"_access\": {\n \"update\": [\n \"admin@test.ch\",\n \"your-egroup@cern.ch\"\n ],\n \"read\": [ // If you want to restrict the project, add access read\n \"your-egroup@cern.ch\"\n ]\n },\n // Add category and type\n \"category\": \"ATLAS\",\n \"type\": \"VIDEO\"\n}",
8383
"formUrlEncoded": [],
8484
"multipartForm": []
8585
},
@@ -111,7 +111,7 @@
111111
"params": [],
112112
"body": {
113113
"mode": "json",
114-
"json": "{\n \"$schema\":\"https://localhost:5000/schemas/deposits/records/videos/video/video-v1.0.0.json\",\n \"_project_id\":\"{{project_id}}\",\n \"title\":\n {\n \"title\":\"your_title\"\n },\n \"_access\": {\n \"read\": [\n \"your-egroup@cern.ch\"\n ]\n },\n \"vr\": false,\n \"featured\": false,\n \"language\": \"en\",\n \"contributors\": [\n {\n \"name\": \"Surname, Name\",\n \"ids\": [\n {\n \"value\": \"cern id\",\n \"source\": \"cern\"\n }\n ],\n \"email\": \"test@cern.ch\",\n \"role\": \"Co-Producer\"\n }\n ],\n \"description\": \"Description\",\n \"date\": \"2024-11-12\",\n \"keywords\":[\n {\n \"name\": \"keyword\",\n \"value\": {\n \"name\": \"keyword\"\n }\n },\n {\n \"name\": \"keyword2\",\n \"value\": {\n \"name\": \"keyword2\"\n }\n }\n ],\n \"related_links\":[\n {\n \"name\": \"related link\",\n \"url\": \"https://relatedlink\"\n }\n ]\n}",
114+
"json": "{\n \"_project_id\":\"{{project_id}}\",\n \"language\":\"en\",\n \"title\":\n {\n \"title\":\"your_title\"\n },\n \"_access\": {\n \"read\": [\n \"your-egroup@cern.ch\"\n ]\n },\n \"vr\": false,\n \"featured\": false,\n \"language\": \"en\",\n \"contributors\": [\n {\n \"name\": \"Surname, Name\",\n \"ids\": [\n {\n \"value\": \"cern id\",\n \"source\": \"cern\"\n }\n ],\n \"email\": \"test@cern.ch\",\n \"role\": \"Co-Producer\"\n }\n ],\n \"description\": \"Description\",\n \"date\": \"2024-11-12\",\n \"keywords\":[\n {\n \"name\": \"keyword\",\n \"value\": {\n \"name\": \"keyword\"\n }\n },\n {\n \"name\": \"keyword2\",\n \"value\": {\n \"name\": \"keyword2\"\n }\n }\n ],\n \"related_links\":[\n {\n \"name\": \"related link\",\n \"url\": \"https://relatedlink\"\n }\n ]\n}",
115115
"formUrlEncoded": [],
116116
"multipartForm": []
117117
},
@@ -200,7 +200,13 @@
200200
"request": {
201201
"url": "{{baseURL}}/api/files/{{bucket_id}}/{{additional_file}}",
202202
"method": "PUT",
203-
"headers": [],
203+
"headers": [
204+
{
205+
"name": "X-Invenio-File-Tags",
206+
"value": "context_type=additional_file",
207+
"enabled": true
208+
}
209+
],
204210
"params": [],
205211
"body": {
206212
"mode": "json",
@@ -284,9 +290,6 @@
284290
"allow": true
285291
}
286292
},
287-
"ignore": [
288-
"node_modules",
289-
".git"
290-
]
293+
"ignore": ["node_modules", ".git"]
291294
}
292-
}
295+
}

README.rst

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,6 @@ Step 1: Create a Project
258258
- **Location**
259259
- **Description**
260260
- **Required/Optional**
261-
* - **$schema**
262-
- string
263-
- body
264-
- Schema URL for the project creation.
265-
- Required
266261
* - **category**
267262
- string
268263
- body
@@ -307,7 +302,6 @@ To restrict the project, add ``_access/read``:
307302
.. code-block:: json
308303
309304
{
310-
"$schema": "https://localhost:5000/schemas/deposits/records/videos/project/project-v1.0.0.json",
311305
"_access": {
312306
"update": [
313307
"admin@test.ch",
@@ -379,11 +373,6 @@ Step 2: Create a Video
379373
- **Location**
380374
- **Description**
381375
- **Required/Optional**
382-
* - **$schema**
383-
- string
384-
- body
385-
- Schema URL for video creation.
386-
- Required
387376
* - **_project_id**
388377
- string
389378
- body
@@ -423,7 +412,7 @@ Step 2: Create a Video
423412
- string
424413
- body
425414
- Language of the video.
426-
- Optional
415+
- Required
427416
* - **featured**
428417
- boolean
429418
- body
@@ -447,7 +436,6 @@ To restrict the video, add ``_access/read``. The ``_access/update`` will be the
447436
.. code-block:: json
448437
449438
{
450-
"$schema":"https://localhost:5000/schemas/deposits/records/videos/video/video-v1.0.0.json",
451439
"_project_id":"{{project_id}}",
452440
"title":
453441
{
@@ -495,7 +483,8 @@ To restrict the video, add ``_access/read``. The ``_access/update`` will be the
495483
"name": "related link",
496484
"url": "https://relatedlink"
497485
}
498-
]
486+
],
487+
"language": "en"
499488
}
500489
501490
**Response:**
@@ -605,6 +594,10 @@ Step 5: (Optional) Upload Additional File
605594

606595
``PUT`` ``{{baseURL}}/api/files/{{bucket_id}}/{{additional_file}}``
607596

597+
**Headers:**
598+
599+
- ``X-Invenio-File-Tags: context_type=additional_file``
600+
608601
**Parameters:**
609602

610603
.. list-table::

cds/modules/deposit/api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -862,15 +862,7 @@ def _rename_subtitles(self):
862862
subtitle_obj_key = "{}_{}.vtt".format(
863863
self["report_number"][0], match.group("iso_lang")
864864
)
865-
obj = ObjectVersion.create(
866-
bucket=subtitle_obj.bucket,
867-
key=subtitle_obj_key,
868-
_file_id=subtitle_obj.file_id,
869-
)
870-
# copy tags to the newly created object version
871-
for tag in subtitle_obj.tags:
872-
tag.object_version = obj
873-
subtitle_obj.remove()
865+
subtitle_obj.key = subtitle_obj_key
874866

875867
def _rename_master_file(self, master_file):
876868
"""Rename master file."""

cds/modules/deposit/ext.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
"""CDSDeposit app for Webhook receivers."""
2626

2727
import re
28+
import mimetypes
2829

2930
from invenio_base.signals import app_loaded
3031
from invenio_db import db
3132
from invenio_files_rest.models import ObjectVersionTag
3233
from invenio_files_rest.signals import file_uploaded
34+
from invenio_files_rest.errors import InvalidKeyError
3335
from invenio_indexer.signals import before_record_index
3436
from invenio_records_files.utils import sorted_files_from_bucket
3537

@@ -45,38 +47,37 @@
4547

4648
def _create_tags(obj):
4749
"""Create additional tags for file."""
48-
# Subtitle file
49-
pattern = re.compile(".*_([a-zA-Z]{2})\.vtt$")
50+
pattern_subtitle = re.compile(r".*_([a-zA-Z]{2})\.vtt$")
51+
pattern_poster = re.compile(r"^poster\.(jpg|png)$")
52+
53+
# Get the media_type and content_type(file ext)
54+
file_name = obj.key
55+
mimetypes.add_type("subtitle/vtt", ".vtt")
56+
guessed_type = mimetypes.guess_type(file_name)[0]
57+
if guessed_type is None:
58+
raise InvalidKeyError(description=f"Unsupported File: {file_name}")
59+
60+
media_type = guessed_type.split("/")[0]
61+
file_ext = guessed_type.split("/")[1]
62+
5063
with db.session.begin_nested():
51-
# language tag
52-
found = pattern.findall(obj.key)
53-
if len(found) == 1:
54-
lang = found[0]
55-
ObjectVersionTag.create_or_update(obj, "language", lang)
56-
else:
57-
# clean to be sure there is no some previous value
58-
ObjectVersionTag.delete(obj, "language")
59-
# other tags
60-
ObjectVersionTag.create_or_update(obj, "content_type", "vtt")
61-
ObjectVersionTag.create_or_update(obj, "context_type", "subtitle")
62-
ObjectVersionTag.create_or_update(obj, "media_type", "subtitle")
63-
# refresh object
64-
db.session.add(obj)
64+
ObjectVersionTag.create_or_update(obj, "content_type", file_ext)
65+
ObjectVersionTag.create_or_update(obj, "media_type", media_type)
66+
if file_ext == "vtt":
67+
# language tag
68+
match = pattern_subtitle.search(file_name)
69+
if match:
70+
ObjectVersionTag.create_or_update(obj, "language", match.group(1))
71+
else:
72+
ObjectVersionTag.delete(obj, "language")
73+
# other tags
74+
ObjectVersionTag.create_or_update(obj, "content_type", "vtt")
75+
ObjectVersionTag.create_or_update(obj, "context_type", "subtitle")
76+
# poster tag
77+
elif pattern_poster.match(file_name):
78+
ObjectVersionTag.create_or_update(obj, "context_type", "poster")
6579

66-
# Poster frame
67-
pattern = re.compile("^poster\.(jpg|png)$")
68-
try:
69-
poster = pattern.findall(obj.key)
70-
if poster:
71-
ext = pattern.findall(poster.key)[0]
72-
# frame tags
73-
ObjectVersionTag.create_or_update(poster, "content_type", ext)
74-
ObjectVersionTag.create_or_update(poster, "context_type", "poster")
75-
ObjectVersionTag.create_or_update(poster, "media_type", "image")
76-
# refresh object
77-
db.session.add(poster)
78-
except IndexError:
79-
return
80+
db.session.add(obj)
8081

8182

8283
def create_tags_on_file_upload(sender, obj):

cds/modules/deposit/static/templates/cds_deposit/deposits.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ <h5 class="text-muted"><strong>Tips</strong></h5>
3939
<h3>Click here to select videos to upload</h3>
4040
</div>
4141
<p class="cds-deposit-box-upload-description">You can also <strong>Drag & Drop</strong> video files here</p>
42+
<p class="text-muted mt-20">supported files <mark>{{ $ctrl.videoExtensions }}</mark></p>
4243
</div>
4344
</div>
4445
</div>

cds/modules/deposit/static/templates/cds_deposit/types/video/uploader.html

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- Master video and subformats -->
1010
<div ng-show="$ctrl.files.length > 0" class="panel panel-default">
1111
<div class="panel-heading">
12-
Master & Subformats files
12+
Main & Subformats files
1313
</div>
1414
<table class="table">
1515
<tr>
@@ -224,12 +224,12 @@ <h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
224224
</table>
225225
</div>
226226
<!-- Subtitles -->
227-
<!-- Other -->
228-
<div ng-show="($ctrl.files | removeBy:'context_type':'poster' |removeBy:'context_type':'master' | removeBy:'context_type':'subtitle' || []).length > 0" class="panel panel-default">
227+
<!-- Additional files -->
228+
<div class="panel panel-default">
229229
<div class="panel-heading">
230-
Other files
230+
Additional files
231231
</div>
232-
<div class="panel-heading">
232+
<div ng-show="($ctrl.files | removeBy:'context_type':'poster' |removeBy:'context_type':'master' | removeBy:'context_type':'subtitle' || []).length > 0" class="panel-heading">
233233
<div class="row">
234234
<div class="col-sm-6">
235235
<p ng-show="$ctrl.files.length > 0" class="text-muted">
@@ -242,7 +242,7 @@ <h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
242242
</div>
243243
</div>
244244
</div>
245-
<table class="table">
245+
<table ng-show="($ctrl.files | removeBy:'context_type':'poster' |removeBy:'context_type':'master' | removeBy:'context_type':'subtitle' || []).length > 0" class="table">
246246
<tr>
247247
<th>Filename</th>
248248
<th>Size</th>
@@ -271,6 +271,31 @@ <h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
271271
</td>
272272
</tr>
273273
</table>
274+
<!-- Upload Additional files -->
275+
<div class="panel-body">
276+
<div class="cds-deposit-box" ng-if="!$ctrl.cdsDepositCtrl.isPublished()">
277+
<div
278+
ngf-drag-over-class="'cds-deposit-dragover'"
279+
ngf-drop=""
280+
ngf-change="$ctrl.addFiles($newFiles, $invalidFiles)"
281+
ngf-select=""
282+
ngf-model-options="{allowInvalid: false}"
283+
ngf-max-size="500GB"
284+
ngf-multiple="true"
285+
>
286+
<div class="pa-10 cds-deposit-box-upload-wrapper text-center">
287+
<p class="cds-deposit-box-upload-icon mb-20">
288+
<i class="fa fa-3x fa-files-o" aria-hidden="true"></i>
289+
</p>
290+
<div class="cds-deposit-box-upload-content">
291+
<h4>Upload complimentary files for this video</h4>
292+
<p class="cds-deposit-box-upload-description">Or Drag & Drop files</p>
293+
</div>
294+
</div>
295+
</div>
296+
</div>
297+
</div>
298+
<!-- Upload Additional files -->
274299
</div>
275300
<hr class="my-20" />
276301
<!-- Error alert -->
@@ -283,39 +308,43 @@ <h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
283308
</ul>
284309
</div>
285310
<!-- Error alert -->
286-
<div class="cds-deposit-box" ng-if="!$ctrl.cdsDepositCtrl.isPublished()">
287-
<div
288-
ngf-drag-over-class="'cds-deposit-dragover'"
289-
ngf-drop=""
290-
ngf-change="$ctrl.addFiles($newFiles, $invalidFiles)"
291-
ngf-select=""
292-
ngf-model-options="{allowInvalid: false}"
293-
ngf-max-size="500GB"
294-
ngf-multiple="true"
295-
>
296-
<div class="pa-10 cds-deposit-box-upload-wrapper text-center">
297-
<p class="cds-deposit-box-upload-icon mb-20">
298-
<i class="fa fa-3x fa-files-o" aria-hidden="true"></i>
299-
</p>
300-
<div class="cds-deposit-box-upload-content">
301-
<div class="cds-deposit-box-upload-title">
302-
<h4>Upload complimentary files for this video</h4>
311+
312+
<!-- Replacing Master Video File -->
313+
<div class="panel panel-default" ng-if="!$ctrl.cdsDepositCtrl.isPublished()">
314+
<div class="panel-heading panel-heading-warning">
315+
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Replace Video File
316+
</div>
317+
<div class="panel-body">
318+
<div class="cds-deposit-box" >
319+
<div
320+
ngf-drag-over-class="{accept: 'cds-deposit-dragover', delay:100}"
321+
ngf-drop=""
322+
ngf-change="$ctrl.replaceMasterFile($newFiles, $invalidFiles)"
323+
ngf-select=""
324+
ngf-model-options="{allowInvalid: false}"
325+
ngf-max-size="500GB"
326+
ngf-multiple="true"
327+
ngf-accept="'{{$ctrl.cdsDepositsCtrl.videoExtensions}}'"
328+
ngf-pattern="'{{$ctrl.cdsDepositsCtrl.videoExtensions}}'"
329+
>
330+
<div class="pa-10 cds-deposit-box-upload-wrapper text-center">
331+
<p class="cds-deposit-box-upload-icon mb-20">
332+
<i class="fa fa-2x fa-video-camera" aria-hidden="true"></i>
333+
</p>
334+
<div class="cds-deposit-box-upload-content">
335+
<h4>To replace the video file, just upload a video here.</h4>
336+
<p class="cds-deposit-box-upload-description">Or Drag & Drop files</p>
337+
</div>
303338
</div>
304-
<p class="cds-deposit-box-upload-description"> Or Drag & Drop files</p>
305339
</div>
306340
</div>
307341
</div>
308-
<hr class="my-10" />
309-
<div class="text-muted">
310-
<h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
311-
<ul>
312-
<li>To replace the video file, just upload another video.</li>
313-
</ul>
314-
</div>
315342
</div>
343+
344+
316345
<div ng-if="$ctrl.cdsDepositCtrl.isPublished()" class="cds-deposit-box text-muted">
317346
<h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
318347
<ul>
319348
<li>Click the <strong>Edit</strong> button on the top right corner to add more files.</li>
320349
</ul>
321-
</div>
350+
</div>

0 commit comments

Comments
 (0)