Advertisement
Guest User

Radarr Manual Import AutoSelector

a guest
Oct 22nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // By exetico - github.com/exetico
  2. // Manual Import files-selection
  3. // Optinal: Comment out the part with JS-confirm, if you like to run through a bit faster!
  4.  
  5. $('.modal-header:last').css({
  6.     "position": "sticky",
  7.     "z-index": 1000,
  8.     "top": 0,
  9.     "display": "block",
  10.     "height": "70px",
  11.     "background": "#444",
  12.     "color": "white",
  13. });
  14. $('.modal-footer:last').css({
  15.     "position": "sticky",
  16.     "z-index": 1000,
  17.     "bottom": 0,
  18.     "display": "block",
  19.     "height": "70px",
  20.     "background": "#444",
  21.     "color": "white",
  22. });
  23.  
  24. // jQuery.fn.scrollTo = function(elem) {
  25. //     var b = $(elem);
  26. //     this.scrollTop(b.position().top - b.height());
  27. // };
  28.  
  29. var totalAmount = $(".series-title-cell.editable:contains('Click to select movie')").length;
  30. $(".series-title-cell.editable:contains('Click to select movie')").each(function(index) {
  31.     console.log("Looking at no.: " + index + " of " + totalAmount)
  32.     // $("#modal-region").scrollTo($(this));
  33.     var button = $(this);
  34.     var dirRaw = $(this).parent();
  35.     var dir = dirRaw.contents("td.path-cell").contents("div")[0].outerText;
  36.     var dirReplaced = dir.replace(/\./g, " ");
  37.     $('.modal-header:last').html("Last triggered: " + dirReplaced)
  38.     $(this).click()
  39.     if ($('#modal-region2 .modal-body div.x-movie table').length) {
  40.         console.log("Exists!");
  41.         $('.modal-header h3').html(dirReplaced)
  42.         var input, filter, found, table, tr, td, i, j;
  43.         table = $('#modal-region2 .modal-body div.x-movie table');
  44.         tr = table.contents("tbody").contents("tr");
  45.         var matchingValue = dirReplaced.substring(0, 3).toUpperCase()
  46.         var matchingLongValue = dirReplaced.substring(0, 10)
  47.         if (matchingValue === "THE") {
  48.             matchingValue = dirReplaced.replace(/The/, "").substring(0, 4).toUpperCase()
  49.             matchingLongValue = dirReplaced.replace(/The/, "").substring(0, 10)
  50.         }
  51.         console.log("Looking for the following string: ", matchingValue)
  52.         for (i = 0; i < tr.length; i++) {
  53.             td = tr[i].getElementsByTagName("td");
  54.             for (j = 0; j < td.length; j++) {
  55.                 if (td[j].innerHTML.toUpperCase().indexOf(matchingValue) > -1) {
  56.                     found = true;
  57.                 }
  58.             }
  59.             if (found) {
  60.                 tr[i].style.display = "";
  61.                 found = false;
  62.             } else {
  63.                 tr[i].remove(); //tr[i].style.background = "red";
  64.             }
  65.         }
  66.  
  67.         tableCheck = $('#modal-region2 .modal-body div.x-movie table').contents("tbody").html().length;
  68.         if (tableCheck) {
  69.             console.log("Looks like we found something")
  70.             var tr = $('#modal-region2 .modal-body div.x-movie table').contents("tbody").contents("tr")
  71.             if (tr.length > 1) {
  72.                 console.log("More than one found. Trying with a longer title: ", matchingLongValue);
  73.                 // We found more than something... Let's find the best match..
  74.                 matches = $('#modal-region2 td:contains("' + matchingLongValue + '")');
  75.                 matches5 = $('#modal-region2 td:contains("' + matchingLongValue.trim().substring(0, 5) + '")');
  76.                 if (matches.length === 1) {
  77.                     console.log("All good, now that we only find one. Selected: ", matches[0].innerText)
  78.                     matches.click();
  79.                     dirRaw[0].style.background = "LightGreen";
  80.                 } else if (matches5.length === 1) {
  81.                     console.log("All good, now that we only find one. Selected: ", matches5[0].innerText)
  82.                     matches5.click();
  83.                     dirRaw[0].style.background = "LightGreen";
  84.                 } else {
  85.                     console.log("I can't make it better.. Please select one!");
  86.                     // CONFIRM START - Uncomment this part, if you like.
  87.                     // var r = confirm("I can't find the right one - would you like to pick the correct? WARNING: This will stop the script!");
  88.                     // if (r == true) {
  89.                     //     console.log("Please select one - And start me again :)!")
  90.                     //     button.html("INFO: Manual task...!")
  91.                     //     //$('.modal-header:first').append('<button style="float:right;" class="btn btn-default" onclick="">Start script again!</button>')
  92.                     //     dirRaw[0].style.background = "Aquamarine";
  93.  
  94.                     //     return false;
  95.                     // } else {
  96.                     //     console.log("OK! I will now move on, like nothing was happend. Please note that you should look into this title later on.. :-)")
  97.                     //     $('#modal-region2 button.close').click()
  98.                     //     button.html("INFO: Multiple...")
  99.                     //     dirRaw[0].style.background = "LightGoldenRodYellow";
  100.                     // }
  101.                     // CONFIRM END - If uncommented, remove the next four-lines below!
  102.                     console.log("OK! I will now move on, like nothing was happend. Please note that you should look into this title later on.. :-)")
  103.                     $('#modal-region2 button.close').click()
  104.                     button.html("INFO: Multiple...")
  105.                     dirRaw[0].style.background = "LightGoldenRodYellow";
  106.                     // IF COMFINRM IS UNCOMMENTED, YOU SHOULD REMOVE THE FOUR LINE ABOVE THIS...
  107.                 }
  108.             } else {
  109.                 console.log("I only found one - Selecting this one: ", tr[0].innerText)
  110.                 tr.click()
  111.                 dirRaw[0].style.background = "LightGreen";
  112.             }
  113.         } else {
  114.             console.log("Nah, nothing matching... - Skipping this part")
  115.             $('#modal-region2 button.close').click()
  116.             dirRaw[0].style.background = "LightSalmon";
  117.             button.html("INFO: No match!")
  118.         }
  119.     }
  120. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement