diff --git a/resources/js/ajax.js b/resources/js/ajax.js index c93ebae..cfbc18e 100644 --- a/resources/js/ajax.js +++ b/resources/js/ajax.js @@ -14,7 +14,7 @@ const getFavesList = () => { doAjax("resources/php/dbController.php", "getTabs=true"); } -const doAjax = (actionPath, data) => { +const doAjax = async (actionPath, data) => { let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { diff --git a/resources/js/uiActions.js b/resources/js/uiActions.js index 63625c9..613f810 100644 --- a/resources/js/uiActions.js +++ b/resources/js/uiActions.js @@ -48,7 +48,7 @@ const disableEdits = () => { this.readOnly = "true"; } -const showMedia = (mediaLoc, type) => { +const showMedia = async (mediaLoc, type) => { let path = document.getElementById("path").innerHTML; let tempRef = mediaLoc.toLowerCase(); let fullMedia = path + mediaLoc; @@ -86,17 +86,37 @@ const showMedia = (mediaLoc, type) => { imgTag.src = fullMedia; imgDiv.appendChild(imgTag); - if (tempRef.includes(".mp4") || tempRef.includes(".webm") || - tempRef.includes(".mp3") || tempRef.includes(".ogg") || - tempRef.includes(".pdf") || tempRef.includes(".flac") || - tempRef.includes(".mkv") || tempRef.includes(".avi")) { - if (tempRef.includes(".mkv") || tempRef.includes(".avi")) { + + + if ((/\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|mp3|webm|flac|ogg|pdf)$/i).test(tempRef)) { + if ((/\.(mkv)$/i).test(tempRef)) { + let data = "remuxVideo=true&mediaPth=" + fullMedia; + + // This kinda sucks but calling doAjax wont return data for some reason + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState === 4 && this.status === 200) { + // Send the returned data to further process + if (this.responseXML != null) { + data = this.responseXML; + fullMedia = data.getElementsByTagName("REMUX_PATH")[0].innerHTML; + } else { + document.getElementById('dynDiv').innerHTML = + "

" + + "No content returned. Check the folder path.

"; + return ; + } + } + }; + xhttp.open("POST", "resources/php/filesystemActions.php", false); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.overrideMimeType('application/xml'); // Force return to be XML + xhttp.send(data); + } else if ((/\.(avi|flv|mov|m4v|mpg|wmv)$/i).test(tempRef)) { openInLocalProg(fullMedia); - return; - // Future option to convert container and view certain media. - // fullMedia = quickRemux(fullMedia); + return ; } - } + } iframe.id = "fileViewInner"; iframe.src = fullMedia; diff --git a/resources/js/uiEvents.js b/resources/js/uiEvents.js index 646232b..274e100 100644 --- a/resources/js/uiEvents.js +++ b/resources/js/uiEvents.js @@ -38,7 +38,7 @@ document.ondblclick = (event) => { // If clicking on dir icon } else if (callingID == "dirID") { let node = obj.parentNode; - getDir(node.children[1].value, "dir"); + getDir(node.children[1].value); // If clicking on movie thumbnail } else if (callingID == "movieID") { let node = obj.parentNode; diff --git a/resources/php/filesystemActions.php b/resources/php/filesystemActions.php index d82703a..39b7393 100644 --- a/resources/php/filesystemActions.php +++ b/resources/php/filesystemActions.php @@ -135,9 +135,29 @@ function openFile($FILE) { serverMessage("success", $message); } +function remuxVideo($FILE) { + $FILE = trim($FILE); + $PTH = "resources/tmp/"; + $HASHED_NAME = hash('sha256', $FILE) . '.mp4'; + $EXTNSN = strtolower(pathinfo($FILE, PATHINFO_EXTENSION)); + + if (!file_exists($PTH . $HASHED_NAME)) { + if (preg_match('(mp4)', $EXTNSN) === 1) { + $COMMAND = 'ffmpeg -i "' . $FILE . '" -movflags +faststart -codec copy ' . $PTH . $HASHED_NAME; + shell_exec($COMMAND . " > /dev/null &"); + } + } + + $GeneratedXML = ""; + $GeneratedXML .= "" . $PTH . $HASHED_NAME .""; + echo $GeneratedXML; +} + chdir("../../"); -if (isset($_POST["createItem"], +if (isset($_POST["remuxVideo"], $_POST["mediaPth"])) { + remuxVideo($_POST["mediaPth"]); +} else if (isset($_POST["createItem"], $_POST["item"], $_POST["type"])) { createItem($_POST["item"], $_POST["type"]); diff --git a/resources/tmp/PLACE_HOLDERtxt b/resources/tmp/PLACE_HOLDERtxt new file mode 100644 index 0000000..4e201b1 --- /dev/null +++ b/resources/tmp/PLACE_HOLDERtxt @@ -0,0 +1 @@ +Place Holder....