mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-14 12:02:21 -05:00
7165df7405
Used regex checks with javascript popup, for checking if valid imdb csv watchlist. Added test/test_tvdb_api.py for testing the tvdb api for retrieving shows by IMDB id. TODO: Help for assisting users in getting the correct IMDB url. maybe, make interval configurable First changes for imdb watchlist checker Thrown the couch code overboard and created my own version of an imdb watchlist scraper Added IMDB thread and test values with an IMDB csv url. These values should be replaced by front end UI settings. - Removed some tracelogs when unable to download watchlist - Added settings for enabling and setting of the watchlist csv url TODO: - create UI for setting from frontend - Implement frontend and backend checks for validating the csv url Default interval is 1 hour.
170 lines
4.7 KiB
JavaScript
170 lines
4.7 KiB
JavaScript
// Avoid `console` errors in browsers that lack a console.
|
|
(function() {
|
|
var method;
|
|
var noop = function noop() {};
|
|
var methods = [
|
|
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
|
|
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
|
|
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
|
|
'timeStamp', 'trace', 'warn'
|
|
];
|
|
var length = methods.length;
|
|
var console = (window.console = window.console || {});
|
|
|
|
while (length--) {
|
|
method = methods[length];
|
|
|
|
// Only stub undefined methods.
|
|
if (!console[method]) {
|
|
console[method] = noop;
|
|
}
|
|
}
|
|
}());
|
|
|
|
$(document).ready(function() {
|
|
|
|
function addImdbWl(path) {
|
|
|
|
if (!path.length)
|
|
return;
|
|
|
|
$('#imdbWl').append('<option value="'+path+'">'+path+'</option>');
|
|
refreshImdbUrls();
|
|
$.get(sbRoot+'/config/general/saveImdbWatchlists', { imdbWatchlistString: $('#ImdbWlText').val() });
|
|
}
|
|
|
|
function editImdbWl(path) {
|
|
|
|
if (!path.length)
|
|
return;
|
|
|
|
// as long as something is selected
|
|
if ($("#imdbWl option:selected").length) {
|
|
|
|
$("#imdbWl option:selected").text(path);
|
|
$("#imdbWl option:selected").val(path);
|
|
}
|
|
|
|
refreshImdbUrls();
|
|
$.get(sbRoot+'/config/general/saveRootDirs', {rootDirString: $('#ImdbWlText').val()});
|
|
}
|
|
|
|
$('#addImdbWl').click(function(){editText()});
|
|
$('#editImdbWl').click(function(){editText({selectedWl: $("#imdbWl option:selected").val()})});
|
|
|
|
$('#deleteImdbWl').click(function() {
|
|
if ($("#imdbWl option:selected").length) {
|
|
|
|
var toDelete = $("#imdbWl option:selected");
|
|
|
|
toDelete.remove();
|
|
syncOptionIDs();
|
|
|
|
};
|
|
|
|
refreshImdbUrls();
|
|
$.get(sbRoot+'/config/general/saveImdbWatchlists', {imdbWatchlistString: $('#ImdbWlText').val()});
|
|
});
|
|
|
|
function syncOptionIDs() {
|
|
// re-sync option ids
|
|
var i = 0;
|
|
$('#imdbWl option').each(function() {
|
|
$(this).attr('id', 'wl-'+(i++));
|
|
});
|
|
}
|
|
|
|
function refreshImdbUrls() {
|
|
// Rebuild the string in #ImdbWlText as url|url|url
|
|
|
|
if (!$("#imdbWl").length)
|
|
return;
|
|
|
|
var do_disable = 'true';
|
|
|
|
// if something's selected then we have some behavior to figure out
|
|
if ($("#imdbWl option:selected").length) {
|
|
do_disable = '';
|
|
}
|
|
|
|
// update the elements
|
|
$('#deleteImdbWl').prop('disabled', do_disable);
|
|
$('#editImdbWl').prop('disabled', do_disable);
|
|
|
|
var log_str = '';
|
|
var dir_text = '';
|
|
|
|
$('#imdbWl option').each(function() {
|
|
log_str += $(this).val();
|
|
//Check if this is a valid IMDB link before adding it
|
|
|
|
if (checkIMDBUrl(log_str)) {
|
|
if (dir_text == '') {
|
|
dir_text = $(this).val()
|
|
}
|
|
else {
|
|
dir_text += '|' + $(this).val();
|
|
}
|
|
}
|
|
});
|
|
|
|
//console.log(log_str);
|
|
|
|
$('#ImdbWlText').val(dir_text);
|
|
$('#ImdbWlText').change();
|
|
//console.log('ImdbWlText: '+$('#ImdbWlText').val());
|
|
}
|
|
|
|
function checkIMDBUrl(url) {
|
|
if (url.match(/http.*:\/\/www\.imdb\.com\/.*/gi) &&
|
|
url.match(/ls[0-9]+/gi) &&
|
|
url.match(/ur[0-9]+/gi)) {
|
|
return true;
|
|
}
|
|
else {
|
|
alert(url + ' is not a valid IMDB csv export!');
|
|
return false;
|
|
};
|
|
};
|
|
|
|
$('#imdbWl').click(refreshImdbUrls);
|
|
|
|
// set up buttons on page load
|
|
refreshImdbUrls();
|
|
|
|
function editText(optionid) {
|
|
var updateVal = "";
|
|
if (optionid) {
|
|
updateVal = 'update-' + optionid.selectedWl;
|
|
$('#editImdbWlText').val(optionid.selectedWl);
|
|
}
|
|
else {
|
|
updateVal = 'add';
|
|
$('#editImdbWlText').val("");
|
|
}
|
|
$('#updateImdbWl').attr('action', updateVal);
|
|
$('#editImdbWlText').attr('style','display: block; width: 100%; margin-top: 4px; margin-bottom: 4px;');
|
|
$('#imdbWl').prop('disabled', 'true');
|
|
$('#updateImdbWl').attr('style','display: block;');
|
|
$('#editImdbWlText').select();
|
|
}
|
|
|
|
$('#updateImdbWl').click(function(){
|
|
// Update the Multiselect after clicking on the Update button
|
|
var updateText = $('#editImdbWlText').val();
|
|
if (checkIMDBUrl(updateText)) {
|
|
if ($('#updateImdbWl').attr('action') == 'add') {
|
|
addImdbWl(updateText);
|
|
}
|
|
else {
|
|
editImdbWl(updateText);
|
|
};
|
|
};
|
|
|
|
|
|
$('#editImdbWlText').attr('style','display: none; width: 100%');
|
|
$('#imdbWl').prop('disabled', '');
|
|
$('#updateImdbWl').attr('style','display: none;');
|
|
});
|
|
|
|
}); |