Merge pull request #632 from pateljannat/audio-in-lesson
feat: audio in lessons
This commit is contained in:
@@ -305,6 +305,7 @@ lms_markdown_macro_renderers = {
|
|||||||
"Video": "lms.plugins.video_renderer",
|
"Video": "lms.plugins.video_renderer",
|
||||||
"Assignment": "lms.plugins.assignment_renderer",
|
"Assignment": "lms.plugins.assignment_renderer",
|
||||||
"Embed": "lms.plugins.embed_renderer",
|
"Embed": "lms.plugins.embed_renderer",
|
||||||
|
"Audio": "lms.plugins.audio_renderer",
|
||||||
}
|
}
|
||||||
|
|
||||||
# page_renderer to manage profile pages
|
# page_renderer to manage profile pages
|
||||||
|
|||||||
@@ -178,9 +178,11 @@ def embed_renderer(details):
|
|||||||
|
|
||||||
|
|
||||||
def video_renderer(src):
|
def video_renderer(src):
|
||||||
return (
|
return f"<video controls width='100%' controls controlsList='nodownload'><source src={quote(src)} type='video/mp4'></video>"
|
||||||
f"<video controls width='100%'><source src={quote(src)} type='video/mp4'></video>"
|
|
||||||
)
|
|
||||||
|
def audio_renderer(src):
|
||||||
|
return f"<audio width='100%' controls controlsList='nodownload'><source src={quote(src)} type='audio/mp3'></audio>"
|
||||||
|
|
||||||
|
|
||||||
def assignment_renderer(detail):
|
def assignment_renderer(detail):
|
||||||
|
|||||||
@@ -119,6 +119,16 @@ const parse_string_to_lesson = (type) => {
|
|||||||
type: "upload",
|
type: "upload",
|
||||||
data: {
|
data: {
|
||||||
file_url: video,
|
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")) {
|
} else if (block.includes("{{ Embed")) {
|
||||||
@@ -136,6 +146,7 @@ const parse_string_to_lesson = (type) => {
|
|||||||
type: "upload",
|
type: "upload",
|
||||||
data: {
|
data: {
|
||||||
file_url: image,
|
file_url: image,
|
||||||
|
file_type: "image",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (block.includes("#")) {
|
} else if (block.includes("#")) {
|
||||||
@@ -184,8 +195,11 @@ const parse_content_to_string = (data, type) => {
|
|||||||
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
|
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
|
||||||
} else if (block.type == "upload") {
|
} else if (block.type == "upload") {
|
||||||
let url = block.data.file_url;
|
let url = block.data.file_url;
|
||||||
lesson_content += block.data.is_video
|
lesson_content +=
|
||||||
|
block.data.file_type == "video"
|
||||||
? `{{ Video("${url}") }}\n`
|
? `{{ Video("${url}") }}\n`
|
||||||
|
: block.data.file_type == "audio"
|
||||||
|
? `{{ Audio("${url}") }}\n`
|
||||||
: ``;
|
: ``;
|
||||||
} else if (block.type == "header") {
|
} else if (block.type == "header") {
|
||||||
lesson_content +=
|
lesson_content +=
|
||||||
@@ -211,8 +225,6 @@ const parse_content_to_string = (data, type) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
console.log(this.instructor_notes_data);
|
|
||||||
console.log(this.lesson_content_data);
|
|
||||||
validate_mandatory(this.lesson_content_data);
|
validate_mandatory(this.lesson_content_data);
|
||||||
let lesson = $("#lesson-title").data("lesson");
|
let lesson = $("#lesson-title").data("lesson");
|
||||||
frappe.call({
|
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_types = ["mov", "mp4", "mkv"];
|
||||||
let video_extension = url.split(".").pop();
|
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 {
|
class YouTubeVideo {
|
||||||
@@ -444,7 +468,7 @@ class Upload {
|
|||||||
folder: "Home/Attachments",
|
folder: "Home/Attachments",
|
||||||
make_attachments_public: true,
|
make_attachments_public: true,
|
||||||
restrictions: {
|
restrictions: {
|
||||||
allowed_file_types: ["image/*", "video/*"],
|
allowed_file_types: ["image/*", "video/*", "audio/*"],
|
||||||
},
|
},
|
||||||
on_success: (file_doc) => {
|
on_success: (file_doc) => {
|
||||||
self.file_url = file_doc.file_url;
|
self.file_url = file_doc.file_url;
|
||||||
@@ -454,11 +478,15 @@ class Upload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_upload(url) {
|
render_upload(url) {
|
||||||
this.is_video = is_video(url);
|
this.file_type = get_file_type(url);
|
||||||
if (this.is_video) {
|
if (this.file_type == "video") {
|
||||||
return `<video controls width='100%'>
|
return `<video controls width='100%' controls controlsList='nodownload'>
|
||||||
<source src=${encodeURI(url)} type='video/mp4'>
|
<source src=${encodeURI(url)} type='video/mp4'>
|
||||||
</video>`;
|
</video>`;
|
||||||
|
} else if (this.file_type == "audio") {
|
||||||
|
return `<audio controls width='100%' controls controlsList='nodownload'>
|
||||||
|
<source src=${encodeURI(url)} type='audio/mp3'>
|
||||||
|
</audio>`;
|
||||||
} else {
|
} else {
|
||||||
return `<img src=${encodeURI(url)} width='100%'>`;
|
return `<img src=${encodeURI(url)} width='100%'>`;
|
||||||
}
|
}
|
||||||
@@ -471,7 +499,7 @@ class Upload {
|
|||||||
save(block_content) {
|
save(block_content) {
|
||||||
return {
|
return {
|
||||||
file_url: this.data.file_url || this.file_url,
|
file_url: this.data.file_url || this.file_url,
|
||||||
is_video: this.is_video,
|
file_type: this.file_type,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ def get_context(context):
|
|||||||
custom_tabs = frappe.get_hooks("lms_batch_tabs")
|
custom_tabs = frappe.get_hooks("lms_batch_tabs")
|
||||||
|
|
||||||
if custom_tabs:
|
if custom_tabs:
|
||||||
context.custom_tabs_header = (custom_tabs.get("header_html")[0],)
|
context.custom_tabs_header = custom_tabs.get("header_html")[0]
|
||||||
context.custom_tabs_content = (custom_tabs.get("content_html")[0],)
|
context.custom_tabs_content = custom_tabs.get("content_html")[0]
|
||||||
context.update(frappe.get_attr(custom_tabs.get("context")[0])())
|
context.update(frappe.get_attr(custom_tabs.get("context")[0])())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user