Added remuxing for mkv videos. Potential for future options too.

This commit is contained in:
Maxim Stewart 2019-01-23 22:25:19 -06:00
parent 35402f3906
commit c4ba8ab715
5 changed files with 54 additions and 13 deletions

View File

@ -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() {

View File

@ -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 =
"<p class=\"error\" style=\"width:100%;text-align:center;\"> "
+ "No content returned. Check the folder path.</p>";
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;

View File

@ -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;

View File

@ -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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$GeneratedXML .= "<REMUX_PATH>" . $PTH . $HASHED_NAME ."</REMUX_PATH>";
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"]);

View File

@ -0,0 +1 @@
Place Holder....