Have recursion option or season folders.

This commit is contained in:
Maxim Stewart 2018-04-23 01:46:19 -05:00
parent a572e723c5
commit 218e5a3afc
4 changed files with 65 additions and 40 deletions

View File

@ -24,6 +24,9 @@
<input type="button" value="New Dir" onclick="createItem('dir')"> <input type="button" value="New Dir" onclick="createItem('dir')">
<input type="button" value="New File" onclick="createItem('file')"> <input type="button" value="New File" onclick="createItem('file')">
<br/> <br/>
<label target="MergeType"> <input id="MergeType" type="checkbox">Merge Seasson Folders.</label>
<button type="button" name="button" onclick="getDir('./')">Refresh</button>
<button type="button" name="button" onclick="getDir('../')">../</button>
&nbsp;&nbsp;&nbsp;&nbsp;Path:&nbsp;&nbsp;<span id="path"></span> &nbsp;&nbsp;&nbsp;&nbsp;Path:&nbsp;&nbsp;<span id="path"></span>
</h2> </h2>

View File

@ -57,6 +57,7 @@ function getDir(query) {
// Get dir info... // Get dir info...
function process(path) { function process(path) {
var mergeType = document.getElementById("MergeType");
var xhttp = new XMLHttpRequest(); // Create the xhttp object var xhttp = new XMLHttpRequest(); // Create the xhttp object
// This is actually run after open and send are done // This is actually run after open and send are done
@ -75,7 +76,7 @@ function process(path) {
xhttp.open("POST", "resources/php/getDirList.php", true); // Open the connection xhttp.open("POST", "resources/php/getDirList.php", true); // Open the connection
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.overrideMimeType('application/xml'); // Force return to be XML xhttp.overrideMimeType('application/xml'); // Force return to be XML
xhttp.send(path); // Start the process xhttp.send(path + "&mergeType=" + mergeType.checked + "Here"); // Start the process
// Use a cookie for persistence during browser session.... // Use a cookie for persistence during browser session....
document.cookie = path + "; expires=Sun, 31 Dec 2034 12:00:00 UTC"; document.cookie = path + "; expires=Sun, 31 Dec 2034 12:00:00 UTC";

View File

@ -8,7 +8,7 @@ function renameItem(obj) {
console.log("Old name: " + oldName); console.log("Old name: " + oldName);
console.log("New name: " + newName); console.log("New name: " + newName);
xhttp.open("POST", "resources/php/filesystemActions.php", false); xhttp.open("POST", "resources/php/filesystemActions.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(formData); xhttp.send(formData);
} }
@ -20,9 +20,9 @@ function createItem(type) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
newItem.value = ""; newItem.value = "";
xhttp.open("POST", "resources/php/filesystemActions.php", false); xhttp.open("POST", "resources/php/filesystemActions.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("createItem=true&item=" + fullPth + "&type=" + type + ""); xhttp.send("createItem=true&item=" + fullPth + "&type=" + type);
} }
function startDeleteItem(item) { function startDeleteItem(item) {
@ -40,7 +40,7 @@ function deleteItem(item) {
if (answer == true) { if (answer == true) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.open("POST", "resources/php/filesystemActions.php", false); xhttp.open("POST", "resources/php/filesystemActions.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("deleteItem=true&item=" + fullPth); xhttp.send("deleteItem=true&item=" + fullPth);

View File

@ -2,51 +2,72 @@
session_start(); session_start();
// Retrieve data // Start of retrieving dir data
function dirListing($NEWPATH) { function startListing($NEWPATH, $MERGESEASSONS) {
if (is_dir($NEWPATH)) { if (is_dir($NEWPATH)) {
$GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DIR_LIST>" $GeneratedXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DIR_LIST>"
. "<PATH_HEAD>" . $NEWPATH . "</PATH_HEAD>"; . "<PATH_HEAD>" . $NEWPATH . "</PATH_HEAD>";
$subPath = ""; // This is used for season scanning as a means of properly getting
// the video src.... It's left blank when not in a sub dir
listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath);
$dirContents = scandir($NEWPATH);
foreach ($dirContents as $fileName) {
$fullPath = $NEWPATH . $fileName;
if (is_dir($NEWPATH . $fileName)) {
$GeneratedXML .= "<DIR>" . $fileName . "/</DIR>";
} elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) {
$NAMEHASH = hash('sha256', $fileName);
if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) {
shell_exec('resources/ffmpegthumbnailer -t 65% -s 320 -c jpg -i "'
. $fullPath . '" -o resources/images/thumbnails/'
. $NAMEHASH . '.jpg');
}
$GeneratedXML .=
"<VID_FILE>"
. "<VID_IMG>/resources/images/thumbnails/" . $NAMEHASH . ".jpg</VID_IMG>"
. "<VID_NAME>" . $fileName . "</VID_NAME>" .
"</VID_FILE>";
} elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) {
$GeneratedXML .=
"<IMG_FILE>"
. "<IMAGE_NAME>" . $fileName . "</IMAGE_NAME>"
. "</IMG_FILE>";
} else {
$GeneratedXML .=
"<FILE>"
. "<FILE_NAME>" . $fileName . "</FILE_NAME>"
. "</FILE>";
}
}
$GeneratedXML .= "</DIR_LIST>"; $GeneratedXML .= "</DIR_LIST>";
echo $GeneratedXML; echo $GeneratedXML;
} }
} }
// Used for recursion
function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) {
$dirContents = scandir($NEWPATH);
foreach ($dirContents as $fileName) {
// Filter for . and .. items We have controls for these actions
if ($fileName !== "." && $fileName !== "..") {
$fullPath = $NEWPATH . $fileName;
if ($MERGESEASSONS == "trueHere" && is_dir($fullPath) &&
strpos(strtolower($fileName), 'season') !== false) {
$fileName .= "/";
listDir($GeneratedXML, $fullPath, $MERGESEASSONS, $fileName);
} else {
processItem($GeneratedXML, $fullPath, $fileName, $subPath);
}
}
}
}
// Assign XML Markup based on file type
function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) {
if (is_dir($fullPath)) {
$GeneratedXML .= "<DIR>" . $fileName . "/</DIR>";
} elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) {
$NAMEHASH = hash('sha256', $fileName);
if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) {
shell_exec('resources/ffmpegthumbnailer -t 65% -s 320 -c jpg -i "'
. $subPath . $fullPath . '" -o resources/images/thumbnails/'
. $NAMEHASH . '.jpg');
}
$GeneratedXML .=
"<VID_FILE>"
. "<VID_IMG>/resources/images/thumbnails/" . $NAMEHASH . ".jpg</VID_IMG>"
. "<VID_NAME>" . $subPath . $fileName . "</VID_NAME>" .
"</VID_FILE>";
} elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) {
$GeneratedXML .=
"<IMG_FILE>"
. "<IMAGE_NAME>" . $subPath . $fileName . "</IMAGE_NAME>"
. "</IMG_FILE>";
} else {
$GeneratedXML .=
"<FILE>"
. "<FILE_NAME>" . $subPath . $fileName . "</FILE_NAME>"
. "</FILE>";
}
}
// Determin action // Determin action
chdir("../../"); chdir("../../");
if (isset($_POST['dirQuery'])) { if (isset($_POST['dirQuery'])) {
dirListing(trim($_POST['dirQuery'])); startListing(trim($_POST['dirQuery']), $_POST['mergeType']);
} else { } else {
echo "<h2 class='error'>Error! Illegal Access Method!</h2>"; echo "<h2 class='error'>Error! Illegal Access Method!</h2>";
} }