Skip to content

Commit

Permalink
Differentiate between different recording types
Browse files Browse the repository at this point in the history
 - Store raw recording type
 - Multi-language support for friendly recording types
 - When possible, fix previously stored recording types
 - Corrected syntax to satisfy code checker
 - Apply suggestions from code review

Co-authored-by: Jonathan Champ <[email protected]>
  • Loading branch information
cbounphengsy and jrchamp committed Apr 18, 2024
1 parent 5f7a1ce commit 248cb07
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 23 deletions.
31 changes: 17 additions & 14 deletions classes/task/get_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public function execute() {

mtrace('Finding meeting recordings for this account...');

$recordingtypestrings = [
'audio' => get_string('recordingtypeaudio', 'mod_zoom'),
'video' => get_string('recordingtypevideo', 'mod_zoom'),
];

$localmeetings = zoom_get_all_meeting_records();

$now = time();
Expand Down Expand Up @@ -109,17 +104,28 @@ public function execute() {
$zoomrecordings = $service->get_user_recordings($hostid, $from, $to);

foreach ($zoomrecordings as $recordingid => $recording) {
if (isset($localrecordings[$recording->meetinguuid][$recordingid])) {
mtrace('Recording id: ' . $recordingid . ' exists...skipping');
continue;
}

if (empty($meetings[$recording->meetingid])) {
// Skip meetings that are not in Moodle.
mtrace('Meeting id: ' . $recording->meetingid . ' does not exist...skipping');
continue;
}

$zoom = $meetings[$recording->meetingid];

if (isset($localrecordings[$recording->meetinguuid][$recordingid])) {
mtrace('Recording id: ' . $recordingid . ' exists...skipping');
$localrecording = $localrecordings[$recording->meetinguuid][$recordingid];

if ($localrecording->recordingtype !== $zoom->recordingtype) {
$updatemeeting = (object) [
'id' => $localrecording->id,
'recordingtype' => $zoom->recordingtype,
];
$DB->update_record('zoom_meeting_recordings', $updatemeeting);
}
continue;
}

// As of 2023-09-24, 'password' is not present in the user recordings API response.
if (empty($meetingpasscodes[$recording->meetinguuid])) {
try {
Expand All @@ -130,16 +136,13 @@ public function execute() {
}
}

$zoom = $meetings[$recording->meetingid];

$recordingtype = $recording->recordingtype;
$recordingtypestring = $recordingtypestrings[$recordingtype];

$record = new stdClass();
$record->zoomid = $zoom->id;
$record->meetinguuid = $recording->meetinguuid;
$record->zoomrecordingid = $recordingid;
$record->name = trim($zoom->name) . ' (' . $recordingtypestring . ')';
$record->name = $zoom->name;
$record->externalurl = $recording->url;
$record->passcode = $meetingpasscodes[$recording->meetinguuid];
$record->recordingtype = $recordingtype;
Expand Down
20 changes: 14 additions & 6 deletions classes/webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,9 @@ public function get_recording_url_list($meetingid) {
$allowedrecordingtypes = [
'MP4' => 'video',
'M4A' => 'audio',
'TRANSCRIPT' => 'transcript',
'CHAT' => 'chat',
'CC' => 'captions',
];

try {
Expand All @@ -1002,13 +1005,14 @@ public function get_recording_url_list($meetingid) {

if (!empty($response->recording_files)) {
foreach ($response->recording_files as $recording) {
if (!empty($recording->play_url) && isset($allowedrecordingtypes[$recording->file_type])) {
$url = $recording->play_url ?? $recording->download_url ?? null;
if (!empty($url) && isset($allowedrecordingtypes[$recording->file_type])) {
$recordinginfo = new stdClass();
$recordinginfo->recordingid = $recording->id;
$recordinginfo->meetinguuid = $response->uuid;
$recordinginfo->url = $recording->play_url;
$recordinginfo->url = $url;
$recordinginfo->filetype = $recording->file_type;
$recordinginfo->recordingtype = $allowedrecordingtypes[$recording->file_type];
$recordinginfo->recordingtype = $recording->recording_type;
$recordinginfo->passcode = $response->password;
$recordinginfo->recordingstart = strtotime($recording->recording_start);

Expand Down Expand Up @@ -1041,6 +1045,9 @@ public function get_user_recordings($userid, $from, $to) {
$allowedrecordingtypes = [
'MP4' => 'video',
'M4A' => 'audio',
'TRANSCRIPT' => 'transcript',
'CHAT' => 'chat',
'CC' => 'captions',
];

try {
Expand All @@ -1050,14 +1057,15 @@ public function get_user_recordings($userid, $from, $to) {

foreach ($response as $meeting) {
foreach ($meeting->recording_files as $recording) {
if (!empty($recording->play_url) && isset($allowedrecordingtypes[$recording->file_type])) {
$url = $recording->play_url ?? $recording->download_url ?? null;
if (!empty($url) && isset($allowedrecordingtypes[$recording->file_type])) {
$recordinginfo = new stdClass();
$recordinginfo->recordingid = $recording->id;
$recordinginfo->meetingid = $meeting->id;
$recordinginfo->meetinguuid = $meeting->uuid;
$recordinginfo->url = $recording->play_url;
$recordinginfo->url = $url;
$recordinginfo->filetype = $recording->file_type;
$recordinginfo->recordingtype = $allowedrecordingtypes[$recording->file_type];
$recordinginfo->recordingtype = $recording->recording_type;
$recordinginfo->recordingstart = strtotime($recording->recording_start);

$recordings[$recording->id] = $recordinginfo;
Expand Down
12 changes: 12 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,5 +965,17 @@ function xmldb_zoom_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2024030100, 'zoom');
}

if ($oldversion < 2024030101) {
// Update existing recording names to default for translatable recordingtype strings.
$meetings = $DB->get_records('zoom');

foreach ($meetings as $meeting) {
$DB->set_field_select('zoom_meeting_recordings', 'name', $meeting->name, 'zoomid = ?', [$meeting->id]);
}

// Zoom savepoint reached.
upgrade_mod_savepoint(true, 2024030101, 'zoom');
}

return true;
}
21 changes: 19 additions & 2 deletions lang/en/zoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,25 @@
$string['recordings'] = 'Recordings';
$string['recordingshow'] = 'Show Recording (Currently Hidden)';
$string['recordingshowtoggle'] = 'Toggle Show Recording';
$string['recordingtypeaudio'] = 'Audio only';
$string['recordingtypevideo'] = 'Video and Audio';
$string['recordingtype_active_speaker'] = 'Active Speaker';
$string['recordingtype_audio_interpretation'] = 'Audio Interpretation';
$string['recordingtype_audio_only'] = 'Audio Only';
$string['recordingtype_audio_transcript'] = 'Audio Transcript';
$string['recordingtype_chat'] = 'Chat File';
$string['recordingtype_closed_caption'] = 'Closed Caption';
$string['recordingtype_gallery'] = 'Gallery View';
$string['recordingtype_poll'] = 'Poll';
$string['recordingtype_production_studio'] = 'Production Studio';
$string['recordingtype_shared'] = 'Shared Screen';
$string['recordingtype_shared_gallery'] = 'Shared Screen with Gallery View';
$string['recordingtype_shared_speaker'] = 'Shared Screen with Speaker View';
$string['recordingtype_shared_speaker_cc'] = 'Shared Screen with Speaker View (CC)';
$string['recordingtype_sign'] = 'Sign Interpretation';
$string['recordingtype_speaker'] = 'Speaker View';
$string['recordingtype_summary'] = 'Summary';
$string['recordingtype_summary_next_steps'] = 'Summary Next Steps';
$string['recordingtype_summary_smart_chapters'] = 'Summary Smart Chapters';
$string['recordingtype_timeline'] = 'Timeline';
$string['recordingurl'] = 'Recording URL';
$string['recordingview'] = 'View Recordings';
$string['recordingvisibility'] = 'Are recordings for this meeting visible by default?';
Expand Down
41 changes: 40 additions & 1 deletion recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@
$recordingshowhtml = html_writer::div($recordingshowbuttonhtml);
}

$recordingname = trim($recording->name) . ' (' . zoom_get_recording_type_string($recording->recordingtype). ')';
$params = ['id' => $cm->id, 'recordingid' => $recording->id];
$recordingurl = new moodle_url('/mod/zoom/loadrecording.php', $params);
$recordinglink = html_writer::link($recordingurl, $recording->name);
$recordinglink = html_writer::link($recordingurl, $recordingname);
$recordinglinkhtml = html_writer::span($recordinglink, 'recording-link', ['style' => 'margin-right:1rem']);
$recordinghtml .= html_writer::div($recordinglinkhtml, 'recording', ['style' => 'margin-bottom:.5rem']);
}
Expand All @@ -135,6 +136,44 @@
}
}

/**
* Get the display name for a Zoom recording type.
*
* @package mod_zoom
* @param string $recordingtype Zoom recording type.
* @return string
*/
function zoom_get_recording_type_string($recordingtype) {
$recordingtypestringmap = [
'active_speaker' => 'recordingtype_active_speaker',
'audio_interpretation' => 'recordingtype_audio_interpretation',
'audio_only' => 'recordingtype_audio_only',
'audio_transcript' => 'recordingtype_audio_transcript',
'chat_file' => 'recordingtype_chat',
'closed_caption' => 'recordingtype_closed_caption',
'gallery_view' => 'recordingtype_gallery',
'poll' => 'recordingtype_poll',
'production_studio' => 'recordingtype_production_studio',
'shared_screen' => 'recordingtype_shared',
'shared_screen_with_gallery_view' => 'recordingtype_shared_gallery',
'shared_screen_with_speaker_view' => 'recordingtype_shared_speaker',
'shared_screen_with_speaker_view(CC)' => 'recordingtype_shared_speaker_cc',
'sign_interpretation' => 'recordingtype_sign',
'speaker_view' => 'recordingtype_speaker',
'summary' => 'recordingtype_summary',
'summary_next_steps' => 'recordingtype_summary_next_steps',
'summary_smart_chapters' => 'recordingtype_summary_smart_chapters',
'timeline' => 'recordingtype_timeline',
];

// Return some default string in case new recordingtype values are added in the future.
if (empty($recordingtypestringmap[$recordingtype])) {
return $recordingtype;
}

return get_string($recordingtypestringmap[$recordingtype], 'mod_zoom');
}

echo html_writer::table($table);

echo $OUTPUT->footer();

0 comments on commit 248cb07

Please sign in to comment.