Skip to content

Commit

Permalink
On Mediaupload attach video to currently selected playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahn committed Aug 30, 2023
1 parent 1f129c5 commit e09f38c
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 12 deletions.
16 changes: 8 additions & 8 deletions cronjobs/opencast_discover_videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public function execute($last_result, $parameters = array())
$video = Videos::findOneBySql("config_id = ? AND episode = ?", [$config['id'], $new_event_id]);
if (!$video) {
$video = new Videos;
$video->setData([
'episode' => $new_event_id,
'config_id' => $config['id'],
'title' => $events[$new_event_id]->title,
'description' => $events[$new_event_id]->description,
'duration' => $events[$new_event_id]->duration
]);
}
$video->setValue('available', true);
$video->setData([
'episode' => $new_event_id,
'config_id' => $config['id'],
'title' => $events[$new_event_id]->title,
'description' => $events[$new_event_id]->description,
'duration' => $events[$new_event_id]->duration,
'available' => true
]);
$video->store();

// create task to update permissions and everything else
Expand Down
1 change: 1 addition & 0 deletions lib/RouteMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function authenticatedRoutes()
$this->app->put('/videos/{token}', Routes\Video\VideoUpdate::class);
$this->app->put('/videos/{token}/restore', Routes\Video\VideoRestore::class);
$this->app->delete('/videos/{token}', Routes\Video\VideoDelete::class);
$this->app->post('/videos/{episode_id}', Routes\Video\VideoAdd::class);

$this->app->post('/videos/{token}/report', Routes\Video\VideoReport::class);
$this->app->post('/videos/{token}/playlists', Routes\Video\VideoAddToPlaylist::class);
Expand Down
61 changes: 61 additions & 0 deletions lib/Routes/Video/VideoAdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\Videos;

class VideoAdd extends OpencastController
{
use OpencastTrait;

public function __invoke(Request $request, Response $response, $args)
{
$json = $this->getRequestData($request);
$event = $json['event'];

$episode_id = $args['episode_id'];

$ret = [];

$video = Videos::findByEpisode($episode_id);
if (!empty($video) || !isset($event['config_id'])) {
$message = [
'type' => 'error',
'text' => _('Beim Erstellen des Videos ist ein Fehler aufgetreten.')
];
}
else {
$video = new Videos;
$video->setData([
'episode' => $episode_id,
'config_id' => $event['config_id'],
'title' => $event['title'],
'description' => $event['description'],
'duration' => $event['duration'],
'available' => false
]);
if (!$video->token) {
$video->token = bin2hex(random_bytes(8));
}
$video->store();

$ret = $video->toSanitizedArray();

$message = [
'type' => 'success',
'text' => _('Das Video wurde erfolgreich erstellt.')
];
}

return $this->createResponse([
'message' => $message,
'event' => $ret
], $response->withStatus(200));
}
}
2 changes: 1 addition & 1 deletion vueapp/common/upload.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class UploadService {
const xmlDoc = $.parseXML(mediaPackage);
episode_id = xmlDoc.documentElement.id;
if (episode_id) {
uploadDone(episode_id, workflowId);
uploadDone(episode_id, terms, workflowId);
}
} catch (ex) {
console.log(ex);
Expand Down
30 changes: 27 additions & 3 deletions vueapp/components/Videos/VideoUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ export default {
...mapGetters({
'config' : 'simple_config_list',
'course_config': 'course_config',
'cid' : 'cid'
'cid' : 'cid',
'playlist' : 'playlist'
}),
upload_workflows() {
Expand Down Expand Up @@ -368,15 +369,38 @@ export default {
progress: parseInt(Math.round((loaded / total) * 100 ))
}
},
uploadDone: (episode_id, workflow_id) => {
uploadDone: (episode_id, uploadData, workflow_id) => {
view.$emit('done');
view.$store.dispatch('createLogEvent', {
event: 'upload',
data: {
episode_id: episode_id,
workflow_id: workflow_id
}
})
});
// If a playlist is selected, add the Video to the playlist
if (view.playlist) {
view.$store.dispatch('createVideo', {
'episode': episode_id,
'config_id': view.selectedServer.id,
'title': uploadData.title,
'description': uploadData.description
})
.then(({ data }) => {
this.$store.dispatch('addMessage', data.message);
if(data.event?.token) {
this.$store.dispatch('addVideoToPlaylists', {
token: data.event.token,
playlists: [view.playlist],
})
.then(({data}) => {
this.$store.dispatch('addMessage', data.message);
})
}
});
}
}
});
},
Expand Down
4 changes: 4 additions & 0 deletions vueapp/store/videos.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ const actions = {
return ApiService.put('playlists/' + data.playlist_token + '/positions', data.sortedVideos)
},

async createVideo(context, event) {
return ApiService.post('videos/' + event.episode, {event: event});
},

async deleteVideo(context, token) {
return ApiService.delete('videos/' + token);
},
Expand Down

0 comments on commit e09f38c

Please sign in to comment.