listTitles.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Manga Cafe scan mangas
  3. This script will scan all vroots with Picture/Manga/ directories
  4. */
  5. //Require filelib
  6. requirelib("filelib");
  7. //Make Manga folder if not exists
  8. if (!filelib.fileExists("user:/Photo/Manga")){
  9. filelib.mkdir("user:/Photo/Manga")
  10. }
  11. //Scan all roots for other manga
  12. var rootList = filelib.glob("/")
  13. var scannedTitles = [];
  14. for (var i =0; i < rootList.length; i++){
  15. var thisRoot = rootList[i];
  16. if (filelib.fileExists(thisRoot + "Photo/Manga")){
  17. var titleList = filelib.aglob(thisRoot + "Photo/Manga/*");
  18. for (var k =0; k < titleList.length; k++){
  19. var thisFileObject = titleList[k];
  20. //Only scan this if this is a directory and it is not start with "."
  21. if (filelib.isDir(thisFileObject) && thisFileObject.split("/").pop().substr(0, 1) != "."){
  22. //This should be manga title. Get its chapter count
  23. var chaptersInThisTitle = filelib.aglob(thisFileObject + "/*");
  24. var foldersInTitle = [];
  25. var chapterCount = 0;
  26. for (var j = 0; j < chaptersInThisTitle.length; j++){
  27. var basename = chaptersInThisTitle[j].split("/").pop();
  28. if (filelib.isDir(chaptersInThisTitle[j]) && basename.substring(0,1) != "."){
  29. chapterCount++;
  30. foldersInTitle.push(chaptersInThisTitle[j]);
  31. }
  32. }
  33. //Check if title image exists. If not, use ch1 image 1
  34. var titleImagePath = ""
  35. if (filelib.fileExists(thisFileObject + "/title.png")){
  36. titleImagePath = thisFileObject + "/title.png"
  37. }else{
  38. //Get the first image from the first chapter
  39. var firstChapterFolder = foldersInTitle[0];
  40. var firstChapterImagaes = filelib.aglob(firstChapterFolder + "/*.jpg");
  41. titleImagePath = firstChapterImagaes[0];
  42. }
  43. //Get the starting chapter
  44. var startChapter = foldersInTitle[0];
  45. //Prase the return output, src folder, chapter count and title image path
  46. scannedTitles.push([thisFileObject, chapterCount, titleImagePath, startChapter]);
  47. }
  48. }
  49. }
  50. }
  51. sendJSONResp(JSON.stringify(scannedTitles));