Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getFolderContents(dir) {
  2.     fs.readdir(dir, function(err, items) {
  3.         for (var i = 0; i < items.length; i++) {
  4.             if ( fs.lstatSync(dir + items[i]).isDirectory() ) {
  5.                 // The item is a dir, so check the contents of it.
  6.                 getFolderContents(dir + items[i] + '/');
  7.             } else {
  8.                 // The item isn't a dir, but a file. We don't want to deal with it here, so send it over to getFileInfo()
  9.                 getFileInfo(dir + items[i], items[i]);
  10.             }
  11.         }
  12.     });
  13. }
  14.  
  15. function getFileInfo(dir, file) {
  16.     if ( (file.indexOf('.srt')) >= 0 || (file.indexOf('.jpg')) >= 0 || (file.indexOf('.xml')) >= 0 || (file.indexOf('.png')) >= 0 || (file.indexOf('.nfo')) >= 0 || (file.indexOf('.sfv')) >= 0 ) {
  17.         // Ignore anything that contains these in the filename (ugly formatting and temporary)
  18.     } else {
  19.         <snipped code>
  20.         setTimeout(Testing, delay, dir, file);
  21.     }
  22. }
  23.  
  24. function Testing(dir, title) {
  25.     metadata.getId(title, null, function(err, id) { // FIXME: Limit how often this is called, as we're probably hitting the API too hard.
  26.         if(err) {
  27.             return console.error(err + ' DEBUG ' + title);
  28.         } else if (!id) {
  29.             return console.error('No movies found.');
  30.         } else {
  31.             // Now that we have the ID for the movie, we can proceed.
  32.             <snipped code>
  33.         }
  34.     });
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement