listTitles.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. //Require imagelib
  8. requirelib("imagelib");
  9. //Make Manga folder if not exists
  10. if (!filelib.fileExists("user:/Photo/Manga")){
  11. filelib.mkdir("user:/Photo/Manga")
  12. }
  13. //Scan all roots for other manga
  14. var rootList = filelib.glob("/")
  15. var scannedTitles = [];
  16. for (var i =0; i < rootList.length; i++){
  17. var thisRoot = rootList[i];
  18. if (filelib.fileExists(thisRoot + "Photo/Manga")){
  19. var titleList = filelib.aglob(thisRoot + "Photo/Manga/*", "smart");
  20. for (var k =0; k < titleList.length; k++){
  21. var thisFileObject = titleList[k];
  22. //Only scan this if this is a directory and it is not start with "."
  23. if (filelib.isDir(thisFileObject) && thisFileObject.split("/").pop().substr(0, 1) != "."){
  24. //This should be manga title. Get its chapter count
  25. var chaptersInThisTitle = filelib.aglob(thisFileObject + "/*", "smart");
  26. var foldersInTitle = [];
  27. var chapterCount = 0;
  28. for (var j = 0; j < chaptersInThisTitle.length; j++){
  29. var basename = chaptersInThisTitle[j].split("/").pop();
  30. if (filelib.isDir(chaptersInThisTitle[j]) && basename.substring(0,1) != "."){
  31. chapterCount++;
  32. foldersInTitle.push(chaptersInThisTitle[j]);
  33. }
  34. }
  35. //Check if title image exists. If not, use ch1 image 1
  36. var titleImagePath = ""
  37. if (filelib.fileExists(thisFileObject + "/title.png")){
  38. titleImagePath = thisFileObject + "/title.png"
  39. }else{
  40. //Get the first image from the first chapter
  41. var firstChapterFolder = foldersInTitle[0];
  42. var firstChapterImagaes = filelib.aglob(firstChapterFolder + "/*.jpg", "smart");
  43. //Get the first image that is not horizontal
  44. titleImagePath = firstChapterImagaes[0];
  45. var index = 0;
  46. var size = imagelib.getImageDimension(titleImagePath);
  47. while(size[0] > size[1] && index < firstChapterImagaes.length - 1){
  48. //Not this one. Next image
  49. index++;
  50. titleImagePath = firstChapterImagaes[index];
  51. size = imagelib.getImageDimension(titleImagePath);
  52. }
  53. }
  54. //Get the starting chapter
  55. var startChapter = foldersInTitle[0];
  56. //Prase the return output, src folder, chapter count and title image path
  57. scannedTitles.push([thisFileObject, chapterCount, titleImagePath, startChapter]);
  58. }
  59. }
  60. }
  61. }
  62. sendJSONResp(JSON.stringify(scannedTitles));