Skip to content

Commit

Permalink
MED-100: Add Vimeo source
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 15, 2024
1 parent db77fb1 commit 06abb21
Show file tree
Hide file tree
Showing 20 changed files with 6,066 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.1'
- php: '8.3'
moodle-branch: 'master'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'master'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
Expand All @@ -39,7 +45,7 @@ jobs:
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
database: 'pgsql'

steps:
- name: Check out repository code
Expand Down
43 changes: 43 additions & 0 deletions source/vimeo/amd/src/file_upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var upload;

import * as tus from 'mediatimesrc_streamio/tus';
import Log from 'core/log';
import cfg from 'core/config';

const options = {
endpoint: cfg.wwwroot + '/api/v1/videos/tus',
metadata: {},
onError: Log.debug,
onProgress: function(bytesUploaded, bytesTotal) {
document.querySelectorAll('.progress').forEach(indicator => {
indicator.style.width = (bytesUploaded / bytesTotal * 100) + '%';
});
},
onSuccess: function() {
document.getElementById('upload_resource_form').submit();
Log.debug(upload.url);
}
};

export default {
init: function(token) {
options.metadata.uploadtoken = token;
document.body.removeEventListener('click', this.handleClick);
document.body.addEventListener('click', this.handleClick);
},

handleClick: function(e) {
const button = e.target.closest('button[name="upload"]');
if (button) {
const file = document.querySelector('input[name="streamiofile"]').files[0];
e.preventDefault();
options.metadata.filename = file.name;
options.metadata.filetype = file.type;
Log.debug(options);
Log.debug(tus);

upload = new tus.Upload(file, options);
upload.start();
}
}
};
4,973 changes: 4,973 additions & 0 deletions source/vimeo/amd/src/tus.js

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions source/vimeo/classes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Manage Streamio source files
*
* @package mediatimesrc_vimeo
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mediatimesrc_vimeo;

use moodle_exception;
use stdClass;

/**
* Manage Streamio source files
*
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class api extends \videotimeplugin_repository\api {
}
30 changes: 30 additions & 0 deletions source/vimeo/classes/event/resource_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace mediatimesrc_vimeo\event;

/**
* The resource_created event class.
*
* @package mediatimesrc_vimeo
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_created extends core_event\base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.
}
134 changes: 134 additions & 0 deletions source/vimeo/classes/form/edit_resource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Media Time media edit form
*
* @package mediatimesrc_vimeo
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mediatimesrc_vimeo\form;

use context_system;
use moodleform;
use videotimeplugin_repository\api;
use mediatimesrc_vimeo\output\media_resource;

/**
* Media Time media edit form
*
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_resource extends \tool_mediatime\form\edit_resource {

/**
* Definition
*/
public function definition() {
$mform = $this->_form;

$mform->addElement('hidden', 'create');
$mform->setType('create', PARAM_TEXT);

$mform->addElement('hidden', 'source');
$mform->setType('source', PARAM_TEXT);
$mform->setDefault('source', 'vimeo');

$mform->addElement('text', 'name', get_string('resourcename', 'tool_mediatime'));
$mform->setType('name', PARAM_TEXT);
$mform->addHelpButton('name', 'resourcename', 'tool_mediatime');

$mform->addElement('text', 'title', get_string('title', 'tool_mediatime'));
$mform->setType('title', PARAM_TEXT);
$mform->addHelpButton('title', 'title', 'tool_mediatime');

$mform->addElement('hidden', 'edit');
$mform->setType('edit', PARAM_INT);

$filesource = [
$mform->createElement('radio', 'newfile', '', get_string('uploadnewfile', 'mediatimesrc_vimeo'), 1, []),
$mform->createElement('radio', 'newfile', '', get_string('selectexistingfile', 'mediatimesrc_vimeo'), 0, []),
$mform->createElement('radio', 'newfile', '', get_string('selecturl', 'mediatimesrc_vimeo'), 2, []),
];
$mform->addGroup($filesource, 'filesource', get_string('videofile', 'mediatimesrc_vimeo'), [' '], false);
$mform->setType('newfile', PARAM_INT);
$mform->addHelpButton('filesource', 'videofile', 'mediatimesrc_vimeo');

$mform->addElement('url', 'vimeo_url', get_string('vimeo_url', 'mod_videotime'));
$mform->hideIf('vimeo_url', 'newfile', 'neq', 2);
$mform->setType('vimeo_url', PARAM_URL);

$mform->addElement('textarea', 'description', get_string('description'));
$mform->setType('description', PARAM_TEXT);

$this->tag_elements();

$this->add_action_buttons();
}

/**
* Display resource or add file fields
*/
public function definition_after_data() {
global $DB, $OUTPUT;

$mform =& $this->_form;

$id = $mform->getElementValue('edit');
$record = $DB->get_record('tool_mediatime', ['id' => $id]);
$context = context_system::instance();
if ($record) {
$resource = new media_resource($record);
$content = json_decode($record->content);
$mform->insertElementBefore(
$mform->createElement('html', $content->embed->html),
'name'
);
$mform->insertElementBefore(
$mform->createElement('static', 'vimeolink', get_string('vimeolink', 'mediatimesrc_vimeo'), $content->link),
'filesource'
);
$mform->removeElement('filesource');
} else {
if (has_capability('mediatimesrc/vimeo:viewall', $context)) {
$options = [null => ''];
$api = new api();
$videos = $api->request('/me/videos')['body']['data'];
foreach ($videos as $video) {
$options[$video['uri']] = $video['name'];
}

$mform->insertElementBefore(
$mform->createElement('autocomplete', 'file', '', $options, [
]),
'description'
);
$mform->hideIf('file', 'newfile', 'neq', 0);
$mform->setDefault('newfile', 1);
$mform->setDefault('file', []);
} else if (has_capability('mediatimesrc/vimeo:upload', context_system::instance())) {
$mform->removeElement('filesource');
$mform->insertElementBefore(
$mform->createElement('hidden', 'newfile', 1),
'description'
);
}
}
}
}
Loading

0 comments on commit 06abb21

Please sign in to comment.