Skip to content

Commit

Permalink
load captions seperately
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahn committed Jun 5, 2023
1 parent 0c54a23 commit 8abb4d3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 22 deletions.
47 changes: 30 additions & 17 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ public static function parseEvent($eventType, $episode, $video)
$presenter_download = [];
$presentation_download = [];
$audio_download = [];
$caption_download = [];
$annotation_tool = false;
$duration = 0;

Expand Down Expand Up @@ -665,20 +664,6 @@ public static function parseEvent($eventType, $episode, $video)
}
}

// Get caption files
$api_event_client = ApiEventsClient::getInstance($video->config_id);
$media_tracks = $api_event_client->getMedia($episode->identifier);

foreach($media_tracks as $track) {
if (substr($track->flavor, 0, 9) === 'captions/' &&
$track->mimetype === 'text/vtt')
{
$caption_download[$track->flavor] = [
'url' => $track->uri
];
}
}

foreach ($episode->publications as $publication) {
if ($publication->channel == 'engage-player') {
$track_link = $publication->url;
Expand All @@ -704,8 +689,7 @@ public static function parseEvent($eventType, $episode, $video)
'downloads' => [
'presenter' => $presenter_download,
'presentation' => $presentation_download,
'audio' => $audio_download,
'caption' => $caption_download
'audio' => $audio_download
],
'annotation_tool' => $annotation_tool,
'track_link' => $track_link
Expand Down Expand Up @@ -822,4 +806,33 @@ public static function addToCoursePlaylist($eventType, $episode, $video)
}
}
}

/**
* Fetch caption data for a given token
*
* @param string $token
*
* @return Array which contains urls for the caption files
*/
public static function getCaptionByToken($token)
{
$caption_download = [];
$video = self::findByToken($token);

// Get caption files
$api_event_client = ApiEventsClient::getInstance($video->config_id);
$media_tracks = $api_event_client->getMedia($video->episode);

foreach($media_tracks as $track) {
if (substr($track->flavor, 0, 9) === 'captions/' &&
$track->mimetype === 'text/vtt')
{
$caption_download[$track->flavor] = [
'url' => $track->uri
];
}
}

return $caption_download;
}
}
1 change: 1 addition & 0 deletions lib/RouteMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function authenticatedRoutes()
$this->app->post('/videos/{token}/report', Routes\Video\VideoReport::class);
$this->app->post('/videos/{token}/playlists', Routes\Video\VideoAddToPlaylist::class);

$this->app->get('/videos/{token}/captions', Routes\Video\VideoCaptions::class);
$this->app->get('/videos/{token}/shares', Routes\Video\VideoSharesList::class);
$this->app->put('/videos/{token}/shares', Routes\Video\VideoSharesUpdate::class);
$this->app->post('/videos/{course_id}/copy', Routes\Video\VideoCopyToCourse::class);
Expand Down
27 changes: 27 additions & 0 deletions lib/Routes/Video/VideoCaptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Opencast\Routes\Video;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Opencast\Errors\AuthorizationFailedException;
use Opencast\Errors\Error;
use Opencast\OpencastTrait;
use Opencast\OpencastController;
use Opencast\Models\Filter;
use Opencast\Models\Videos;

class VideoCaptions extends OpencastController
{
use OpencastTrait;

public function __invoke(Request $request, Response $response, $args)
{
$token = $args['token'];
$captions = Videos::getCaptionByToken($token);

return $this->createResponse([
'caption' => $captions
], $response);
}
}
16 changes: 11 additions & 5 deletions vueapp/components/Videos/Actions/CaptionUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export default {
computed: {
...mapGetters({
'config' : 'simple_config_list',
'course_config': 'course_config'
'course_config': 'course_config',
'videoCaptions': 'videoCaptions'
}),
uploadButtonClasses() {
Expand Down Expand Up @@ -208,6 +209,7 @@ export default {
this.$store.dispatch('simpleConfigListRead').then(() => {
this.selectedServer = this.config['server'][this.config.settings['OPENCAST_DEFAULT_SERVER']];
});
this.$store.dispatch('loadCaption', this.event.token);
// Add support for StudIP languages
for (let key in window.OpencastPlugin.STUDIP_LANGUAGES) {
Expand All @@ -216,21 +218,25 @@ export default {
flavor: 'captions/source+' + key.split('_')[0]
});
}
},
if (this.event?.publication?.downloads?.caption) {
for (var flavor in this.event.publication.downloads.caption) {
watch: {
videoCaptions(newCaptions) {
if (Object.keys(newCaptions).length > 0) {
for (var flavor in newCaptions) {
let language = this.languages.find(language => language.flavor === flavor);
if (language) {
this.files[flavor] = [];
this.files[flavor].push({
'url': this.event.publication.downloads.caption[flavor].url,
'name': this.event.publication.downloads.caption[flavor].url.split('/').pop()
'url': newCaptions[flavor].url,
'name': newCaptions[flavor].url.split('/').pop()
});
this.files[flavor]['language'] = language.lang;
}
}
}
}
}
}
</script>
23 changes: 23 additions & 0 deletions vueapp/store/videos.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const state = {
items: 0
},
availableVideoTags: [],
videoCaptions: {},
playlistForVideos: null,
videoShares: {},
courseVideosToCopy: [],
Expand Down Expand Up @@ -52,6 +53,10 @@ const getters = {
return state.availableVideoTags
},

videoCaptions(state) {
return state.videoCaptions
},

playlistForVideos(state) {
return state.playlistForVideos
},
Expand Down Expand Up @@ -191,6 +196,14 @@ const actions = {
return ApiService.put('videos/' + data.token + '/shares', data.shares);
},

async loadCaption({commit}, token) {
return ApiService.get('videos/' + token + '/captions')
.then(({ data }) => {
data.token = token
commit('setCaptionForToken', data)
});
},

setPage({commit}, page) {
commit('setPage', page);
},
Expand Down Expand Up @@ -264,6 +277,16 @@ const mutations = {

setAvailableVideoTags(state, data) {
state.availableVideoTags = data;
},

setCaptionForToken(state, data) {
let key = Object.keys(state.videos).find(key => state.videos[key].token === data.token)
if (key) {
state.videoCaptions = data.caption;
}
else {
state.videoCaptions = {};
}
}
}

Expand Down

0 comments on commit 8abb4d3

Please sign in to comment.