From 277c089adcc238421e6fb6ed744112dd58db3d5e Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 3 Oct 2023 13:33:59 +0530 Subject: [PATCH] feat: audio in lessons --- lms/hooks.py | 1 + lms/plugins.py | 8 ++++--- lms/www/batch/edit.js | 52 ++++++++++++++++++++++++++++++---------- lms/www/batches/batch.py | 4 ++-- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index ab6ac7b4..a8913578 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -305,6 +305,7 @@ lms_markdown_macro_renderers = { "Video": "lms.plugins.video_renderer", "Assignment": "lms.plugins.assignment_renderer", "Embed": "lms.plugins.embed_renderer", + "Audio": "lms.plugins.audio_renderer", } # page_renderer to manage profile pages diff --git a/lms/plugins.py b/lms/plugins.py index 59dcd3ab..590820f3 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -178,9 +178,11 @@ def embed_renderer(details): def video_renderer(src): - return ( - f"" - ) + return f"" + + +def audio_renderer(src): + return f"" def assignment_renderer(detail): diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js index 9b124812..8922626b 100644 --- a/lms/www/batch/edit.js +++ b/lms/www/batch/edit.js @@ -119,6 +119,16 @@ const parse_string_to_lesson = (type) => { type: "upload", data: { file_url: video, + file_type: "video", + }, + }); + } else if (block.includes("{{ Audio")) { + let audio = block.match(/\(["']([^"']+?)["']\)/)[1]; + blocks.push({ + type: "upload", + data: { + file_url: audio, + file_type: "audio", }, }); } else if (block.includes("{{ Embed")) { @@ -136,6 +146,7 @@ const parse_string_to_lesson = (type) => { type: "upload", data: { file_url: image, + file_type: "image", }, }); } else if (block.includes("#")) { @@ -184,9 +195,12 @@ const parse_content_to_string = (data, type) => { lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`; } else if (block.type == "upload") { let url = block.data.file_url; - lesson_content += block.data.is_video - ? `{{ Video("${url}") }}\n` - : `![](${url})`; + lesson_content += + block.data.file_type == "video" + ? `{{ Video("${url}") }}\n` + : block.data.file_type == "audio" + ? `{{ Audio("${url}") }}\n` + : `![](${url})`; } else if (block.type == "header") { lesson_content += "#".repeat(block.data.level) + ` ${block.data.text}\n`; @@ -211,8 +225,6 @@ const parse_content_to_string = (data, type) => { }; const save = () => { - console.log(this.instructor_notes_data); - console.log(this.lesson_content_data); validate_mandatory(this.lesson_content_data); let lesson = $("#lesson-title").data("lesson"); frappe.call({ @@ -260,10 +272,22 @@ const validate_mandatory = (lesson_content) => { } }; -const is_video = (url) => { +const get_file_type = (url) => { let video_types = ["mov", "mp4", "mkv"]; let video_extension = url.split(".").pop(); - return video_types.indexOf(video_extension) >= 0; + + if (video_types.indexOf(video_extension) >= 0) { + return "video"; + } + + let audio_types = ["mp3", "wav", "ogg"]; + let audio_extension = url.split(".").pop(); + + if (audio_types.indexOf(audio_extension) >= 0) { + return "audio"; + } + + return "image"; }; class YouTubeVideo { @@ -444,7 +468,7 @@ class Upload { folder: "Home/Attachments", make_attachments_public: true, restrictions: { - allowed_file_types: ["image/*", "video/*"], + allowed_file_types: ["image/*", "video/*", "audio/*"], }, on_success: (file_doc) => { self.file_url = file_doc.file_url; @@ -454,11 +478,15 @@ class Upload { } render_upload(url) { - this.is_video = is_video(url); - if (this.is_video) { - return `