Fixed alphabet ordering and cleaned up xml data return.

This commit is contained in:
Maxim Stewart 2018-12-09 18:06:51 -06:00
parent d71187f861
commit 2f22d109cd
2 changed files with 83 additions and 53 deletions

View File

@ -37,30 +37,40 @@ const generateFavesList = (data) => {
const updateHTMLDirList = async (data) => { const updateHTMLDirList = async (data) => {
let isInFaves = data.getElementsByTagName('IN_FAVE')[0].innerHTML; let isInFaves = data.getElementsByTagName('IN_FAVE')[0].innerHTML;
let dirPath = data.getElementsByTagName('PATH_HEAD')[0].innerHTML; let dirPath = data.getElementsByTagName('PATH_HEAD')[0].innerHTML;
let dirs = data.getElementsByTagName('DIR'); let dirs = Array.prototype.slice.call(data.getElementsByTagName('DIR'), 0);
let videos = data.getElementsByTagName('VID_FILE'); let videos = Array.prototype.slice.call(data.getElementsByTagName('VID_FILE'), 0);
let images = data.getElementsByTagName('IMG_FILE'); let images = Array.prototype.slice.call(data.getElementsByTagName('IMG_FILE'), 0);
let files = data.getElementsByTagName('FILE'); let files = Array.prototype.slice.call(data.getElementsByTagName('FILE'), 0);
let dirImg = "resources/images/icons/folder.png"; let dirImg = "resources/images/icons/folder.png";
let i = 0; let i = 0;
let size = 0; let size = 0;
// Insert dirs
document.getElementById("path").innerHTML = dirPath; document.getElementById("path").innerHTML = dirPath;
insertArea.innerHTML = ""; insertArea.innerHTML = "";
// determin whether to style faves or nor // Setup background if there is a 000.* in selection
let bgImgPth = images[0] ? images[0].children[0].innerHTML : "";
if (bgImgPth.match(/000\.(jpg|png|gif)\b/) != null) {
updateBG(dirPath + bgImgPth);
} else {
updateBG("resources/images/backgrounds/000.jpg");
}
// determin whether to style faves or not
let elm = document.getElementById("faves");
if (isInFaves == "true") { if (isInFaves == "true") {
let elm = document.getElementById("faves");
elm.style.backgroundColor = "rgb(255, 255, 255)"; elm.style.backgroundColor = "rgb(255, 255, 255)";
elm.style.color = "rgb(0, 0, 0)"; elm.style.color = "rgb(0, 0, 0)";
} else { } else {
let elm = document.getElementById("faves");
elm.style.backgroundColor = ""; elm.style.backgroundColor = "";
elm.style.color = ""; elm.style.color = "";
} }
// Insert dirs
size = dirs.length; size = dirs.length;
sortElms(dirs);
for (; i < size; i++) { for (; i < size; i++) {
let dir = dirs[i].innerHTML; let dir = dirs[i].innerHTML;
@ -71,53 +81,70 @@ const updateHTMLDirList = async (data) => {
} }
// Insert videos // Insert videos
let thumbnail = ""; let thumbnail = "";
let vidNme = ""; let vidNme = "";
size = videos .length; size = videos.length;
console.log(videos);
sortVidElms(videos);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
thumbnail = videos[i].children[0].innerHTML; vidNme = videos[i].children[0].innerHTML;
vidNme = videos[i].children[1].innerHTML; thumbnail = videos[i].children[1].innerHTML;
createElmBlock("SPAN", "movieStyle", "movieID", "thumbnail", thumbnail, createElmBlock("SPAN", "movieStyle", "movieID", "thumbnail", thumbnail,
"movieTitle", vidNme); "movieTitle", vidNme);
} }
// Insert images // Insert images
let path = document.getElementById("path").innerHTML; thumbnail = "";
thumbnail = ""; size = images.length;
size = images.length;
// sortElms(images);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
thumbnail = images[i].children[0].innerHTML; thumbnail = images[i].innerHTML;
if (thumbnail.match(/000\.(jpg|png|gif)\b/) == null && if (thumbnail.match(/000\.(jpg|png|gif)\b/) == null &&
!thumbnail.includes("favicon.png")) { !thumbnail.includes("favicon.png")) {
let imgTag = document.createElement("IMG"); let imgTag = document.createElement("IMG");
imgTag.id = "imageID"; imgTag.id = "imageID";
imgTag.className = "iconImg"; imgTag.className = "iconImg";
imgTag.src = path + thumbnail; imgTag.src = dirPath + thumbnail;
imgTag.alt = thumbnail; imgTag.alt = thumbnail;
insertArea.appendChild(imgTag); insertArea.appendChild(imgTag);
} }
} }
// Setup background if there is a 000.* in selection
let bgImgPth = images[0] ? images[0].children[0].innerHTML : "";
if (bgImgPth.match(/000\.(jpg|png|gif)\b/) != null) {
updateBG(path + bgImgPth);
} else {
updateBG("resources/images/backgrounds/000.jpg");
}
// Insert files // Insert files
size = files.length; size = files.length;
sortElms(files);
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
let fileName = files[i].children[0].innerHTML; let fileName = files[i].innerHTML;
createElmBlock("DIV", "fileStyle", "fileID", "systemIcon", setFileIconType(fileName), createElmBlock("DIV", "fileStyle", "fileID", "systemIcon", setFileIconType(fileName),
"fileTitle", fileName); "fileTitle", fileName);
} }
} }
const sortVidElms = (obj) => {
obj.sort(function(a,b) {
var n1 = a.children[0].innerHTML;
var n2 = b.children[0].innerHTML;
if (n1 > n2) return 1;
if (n1 < n2) return -1;
return 0;
});
}
const sortElms = (obj) => {
obj.sort(function(a,b) {
var n1 = a.innerHTML;
var n2 = b.innerHTML;
if (n1 > n2) return 1;
if (n1 < n2) return -1;
return 0;
});
}
const createElmBlock = (contnrType, contnrClass, imgID, imgClass, const createElmBlock = (contnrType, contnrClass, imgID, imgClass,
imgSrc, inputClass, fileName) => { imgSrc, inputClass, fileName) => {
let contnrTag = document.createElement(contnrType); let contnrTag = document.createElement(contnrType);

View File

@ -9,9 +9,10 @@ function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
if (checkForLock($NEWPATH, $PASSWD) == false) { if (checkForLock($NEWPATH, $PASSWD) == false) {
$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 $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 // the video src.... It's left blank when not in a sub dir
listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath); listDir($GeneratedXML, $NEWPATH, $MERGESEASSONS, $subPath);
$GeneratedXML .= "<IN_FAVE>" . isInDBCheck($NEWPATH) . "</IN_FAVE>"; $GeneratedXML .= "<IN_FAVE>" . isInDBCheck($NEWPATH) . "</IN_FAVE>";
@ -26,22 +27,30 @@ function startListing($NEWPATH, $MERGESEASSONS, $PASSWD) {
} }
} }
// Used for recursion
function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) { function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) {
// $dirContents = scandir($NEWPATH);
$handle = opendir($NEWPATH); $handle = opendir($NEWPATH);
while (false !== ($fileName = readdir($handle))) {
// Filter for . and .. items We have controls for these actions // Note: We'll be filtering out . and .. items We have controls for these actions
if ($fileName !== "." && $fileName !== "..") { if ($MERGESEASSONS !== "trueHere") {
$fullPath = $NEWPATH . $fileName; while (false !== ($fileName = readdir($handle))) {
if ($MERGESEASSONS == "trueHere" && filetype($fullPath) == "dir" && if ($fileName !== "." && $fileName !== "..") {
strpos(strtolower($fileName), 'season') !== false) { $fullPath = $NEWPATH . $fileName;
$fileName .= "/";
listDir($GeneratedXML, $fullPath, $MERGESEASSONS, $fileName);
} else {
processItem($GeneratedXML, $fullPath, $fileName, $subPath); processItem($GeneratedXML, $fullPath, $fileName, $subPath);
} }
} }
} else {
while (false !== ($fileName = readdir($handle))) {
if ($fileName !== "." && $fileName !== "..") {
$fullPath = $NEWPATH . $fileName;
if (filetype($fullPath) == "dir" && strpos(strtolower($fileName),
'season') !== false) {
$fileName .= "/";
listDir($GeneratedXML, $fullPath, $MERGESEASSONS, $fileName);
} else {
processItem($GeneratedXML, $fullPath, $fileName, $subPath);
}
}
}
} }
closedir($handle); closedir($handle);
} }
@ -49,7 +58,7 @@ function listDir(&$GeneratedXML, &$NEWPATH, &$MERGESEASSONS, &$subPath) {
// Assign XML Markup based on file type // Assign XML Markup based on file type
function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) { function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) {
if (filetype($fullPath) == "dir") { if (filetype($fullPath) == "dir") {
$GeneratedXML .= "<DIR>" . $fileName . "/</DIR>"; $GeneratedXML .= "<DIR>" . $fileName . "/</DIR>";
} elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) { } elseif (preg_match('/^.*\.(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg|mp4|webm)$/i', strtolower($fileName))) {
$NAMEHASH = hash('sha256', $fileName); $NAMEHASH = hash('sha256', $fileName);
if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) { if (!file_exists('resources/images/thumbnails/' . $NAMEHASH . '.jpg')) {
@ -58,20 +67,14 @@ function processItem(&$GeneratedXML, &$fullPath, &$fileName, $subPath) {
. $NAMEHASH . '.jpg'); . $NAMEHASH . '.jpg');
} }
$GeneratedXML .= $GeneratedXML .=
"<VID_FILE>" "<VID_FILE>"
. "<VID_IMG>/resources/images/thumbnails/" . $NAMEHASH . ".jpg</VID_IMG>" . "<VID_NAME>" . $subPath . $fileName . "</VID_NAME>"
. "<VID_NAME>" . $subPath . $fileName . "</VID_NAME>" . . "<VID_IMG>/resources/images/thumbnails/" . $NAMEHASH . ".jpg</VID_IMG>" .
"</VID_FILE>"; "</VID_FILE>";
} elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) { } elseif (preg_match('/^.*\.(png|jpg|gif|jpeg)$/i', strtolower($fileName))) {
$GeneratedXML .= $GeneratedXML .= "<IMG_FILE>" . $subPath . $fileName . "</IMG_FILE>";
"<IMG_FILE>"
. "<IMAGE_NAME>" . $subPath . $fileName . "</IMAGE_NAME>"
. "</IMG_FILE>";
} else { } else {
$GeneratedXML .= $GeneratedXML .= "<FILE>" . $subPath . $fileName . "</FILE>";
"<FILE>"
. "<FILE_NAME>" . $subPath . $fileName . "</FILE_NAME>"
. "</FILE>";
} }
} }