Skip to content

Commit

Permalink
fix: some fixing on file browser, windows drives browsing, and window…
Browse files Browse the repository at this point in the history
…s share (#8719)

* fix: some fixing on file browser and others, placeholder so i can check the diff and keep fixing
fix: use named parameters when posting from javascript, fixes site messages, testEmail, testNaming variations, and isNamingValid
clean up browser.folders_at_path
increase performance of home

Signed-off-by: miigotu <miigotu@gmail.com>

* fix: don't fail to start if on linux or pywin32 is not installed on windows

Signed-off-by: miigotu <miigotu@gmail.com>

* refactor: rename showList to show_list
feat: check if sickchill is trying to stop while running through karge loops and break out so it can stop sooner
feat: pre-sort show_list when loading from the database and after adding a show, so we dont need to do it between a web request and web response
chore: remove unused code for is_anime_in_show_list, update_anime_support, and settings.ANIMESUPPORT.

Signed-off-by: miigotu <miigotu@gmail.com>

* chore: fix tests to reflect code changes

Signed-off-by: miigotu <miigotu@gmail.com>

* fix: add a fixed old method for getting windows drives for a fallback when com isn't available (ex. github actions)

Signed-off-by: miigotu <miigotu@gmail.com>

feat: add os.listdrives from python 3.12

Signed-off-by: miigotu <miigotu@gmail.com>

* fix: episode.refreshSubtitles was renamed to refresh_subtitles

Signed-off-by: miigotu <miigotu@gmail.com>

---------

Signed-off-by: miigotu <miigotu@gmail.com>
  • Loading branch information
miigotu committed Feb 20, 2024
1 parent 51bf631 commit 3024ab2
Show file tree
Hide file tree
Showing 62 changed files with 583 additions and 479 deletions.
15 changes: 12 additions & 3 deletions SickChill.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
import time
import traceback
from operator import attrgetter
from pathlib import Path
from typing import List, Union

Expand Down Expand Up @@ -243,22 +244,30 @@ def start(self):
@staticmethod
def load_shows_from_db():
"""
Populates the showList with shows from the database
Populates the show list with shows from the database
"""
logger.debug("Loading initial show list")

main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT indexer, indexer_id, location FROM tv_shows;")

settings.showList = []
settings.show_list = []
for sql_show in sql_results:
if settings.stopping or settings.restarting:
break

try:
cur_show = TVShow(sql_show["indexer"], sql_show["indexer_id"])
cur_show.next_episode()
settings.showList.append(cur_show)
settings.show_list.append(cur_show)
except Exception as error:
logger.exception("There was an error creating the show in {}: Error {}".format(sql_show["location"], error))
logger.debug(traceback.format_exc())
except KeyboardInterrupt:
break

# Presort show_list, so we don't have to do it every page load
settings.show_list = sorted(settings.show_list, key=attrgetter("sort_name"))

@staticmethod
def restore_db(src_dir, dst_dir):
Expand Down
2 changes: 1 addition & 1 deletion frontend/movies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@blueprint.route("/")
def movies():
logger.info("Loading movies page")
logger.debug(f"movies: {settings.showList}")
logger.debug(f"movies: {settings.show_list}")

return render_template("movies.html", movies=settings.movie_list)
6 changes: 3 additions & 3 deletions frontend/shows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
@blueprint.route("/")
def shows():
logger.info("Loading shows page")
logger.debug(f"Shows: {settings.showList}")
return render_template("shows.html", shows=settings.showList)
logger.debug(f"Shows: {settings.show_list}")
return render_template("shows.html", shows=settings.show_list)


@blueprint.route("/show/")
def show():
logger.info("Loading show details page")
logger.debug(f"Shows: {settings.showList}")
logger.debug(f"Shows: {settings.show_list}")
return render_template("show.html", show=None)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ SQLAlchemy = ">=2.0.0,<3.0.0"
python-slugify = ">=4.0.1,<9.0.0"
guessit = "^3.3.1"
requests = "^2.25.1"
cinemagoer = ">=2023.05.1"
cinemagoer = { git = "https://github.com/cinemagoer/cinemagoer.git" }
babelfish = ">=0.6.0"
kodipydent-alt = ">=2022.9.3"
beekeeper-alt = ">=2022.9.3"
Expand Down
58 changes: 31 additions & 27 deletions sickchill/gui/slick/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,37 @@
fileTypes: fileTypes.join(','),
}, data => {
fileBrowserDialog.empty();
const firstValue = data[0];
let list = null;
let link = null;

const innerData = $.grep(data, (value, index) => index !== 0);

const inputContainer = $('<div class="fileBrowserFieldContainer"></div>');
$('<input type="text" class="form-control input-sm">').val(firstValue.currentPath).on('keypress', event_ => {
if (event_.which === 13) {
browse(event_.target.value, endpoint, includeFiles, fileTypes);

$('<input type="text" class="form-control input-sm">').val(currentBrowserPath).on('keypress', event => {
if (event.key === 'Enter') {
browse(event.target.value, endpoint, includeFiles, fileTypes);
}
}).appendTo(inputContainer.appendTo(fileBrowserDialog)).fileBrowser({
showBrowseButton: false,
}).on('autocompleteselect', (event_, ui) => {
}).on('autocompleteselect', (event, ui) => {
browse(ui.item.value, endpoint, includeFiles, fileTypes);
});

const listContainer = $('<div class="ui-dialog-scrollable-child">');
list = $('<ul>').appendTo(listContainer.appendTo(fileBrowserDialog));
$.each(innerData, (i, entry) => {
if (entry.isFile && fileTypes && (!entry.isAllowed || fileTypes.includes('images') && !entry.isImage)) { // eslint-disable-line no-mixed-operators
return true;
/**
* @param entry
* @param entry.isFile
* @param entry.isImage
* @param entry.isAllowed
*/
// noinspection OverlyComplexBooleanExpressionJS
if (entry.isFile && fileTypes) {
const isAllowed = (entry.isAllowed || (fileTypes.includes('images') && entry.isImage));
if (!isAllowed) {
return true;
}
}

link = $('<a href="javascript:void(0)">').on('click', () => {
Expand Down Expand Up @@ -96,18 +105,19 @@
// The title may change, even if fileBrowserDialog already exists
fileBrowserDialog.dialog('option', 'title', newOptions.title);
} else {
const margin = 80;
// Set up the jquery dialog
fileBrowserDialog = $('<div class="fileBrowserDialog" style="display:none"></div>').appendTo('body').dialog({
fileBrowserDialog = $('<div class="fileBrowserDialog"></div>').appendTo('body').dialog({
dialogClass: 'browserDialog',
classes: {
'ui-dialog': 'ui-dialog-scrollable-by-child',
},
title: newOptions.title,
position: {my: 'center top', at: 'center top+60', of: window},
minWidth: Math.min($(document).width() - 80, 650),
height: Math.min($(document).height() - 80, $(window).height() - 80),
maxHeight: Math.min($(document).height() - 80, $(window).height() - 80),
maxWidth: $(document).width() - 80,
position: {my: 'center top', at: 'center top+' + margin, of: window},
minWidth: Math.min($(document).width() - margin, $(window).width() - margin),
height: Math.min($(document).height() - margin, $(window).height() - margin),
maxHeight: Math.min($(document).height() - margin, $(window).height() - margin),
maxWidth: Math.min($(document).width() - margin, $(window).width() - margin),
modal: true,
autoOpen: false,
});
Expand All @@ -118,7 +128,7 @@
class: 'btn',
click() {
// Store the browsed path to the associated text field
callback(newOptions.includeFiles ? currentBrowserPath : $(this).find('.fileBrowserField').val(), newOptions);
callback(newOptions.includeFiles ? $(this).find('.fileBrowserField').val() : currentBrowserPath, newOptions);
$(this).dialog('close');
},
}, {
Expand All @@ -130,12 +140,7 @@
}]);

// Set up the browser and launch the dialog
let initialDirectory = '';
if (newOptions.initialDirectory) {
initialDirectory = newOptions.initialDirectory;
}

browse(initialDirectory, newOptions.url, newOptions.includeFiles, newOptions.fileTypes);
browse(newOptions.initialDirectory || '', newOptions.url, newOptions.includeFiles, newOptions.fileTypes);
fileBrowserDialog.dialog('open');

return false;
Expand Down Expand Up @@ -183,7 +188,9 @@
// If the text field is empty, and we're given a key then populate it with the last browsed value from localStorage
try {
hasLocalStorage = Boolean(localStorage.getItem);
} catch {}
} catch {
console.log('no local storage permissions');
}

if (hasLocalStorage && newOptions.key) {
path = localStorage['fileBrowser-' + newOptions.key];
Expand All @@ -207,12 +214,9 @@
// Append the browse button and give it a click behaviour
newOptions.field.after(
$('<input type="button" value="Browse&hellip;" class="btn btn-inline fileBrowser">').on('click', function () {
let initialDirectory = newOptions.field.val();
initialDirectory ||= (newOptions.key && path);
initialDirectory ||= '';

const optionsWithInitialDirectory = $.extend({}, newOptions, {initialDirectory});
const optionsWithInitialDirectory = $.extend({}, newOptions, {initialDirectory: newOptions.field.val() || (newOptions.key && path) || ''});
$(this).nFileBrowser(callback, optionsWithInitialDirectory);

return false;
}),
);
Expand Down
36 changes: 17 additions & 19 deletions sickchill/gui/slick/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,26 +380,24 @@ const SICKCHILL = {
});
},
backupRestore() {
$('#Backup').on('click', () => {
$('#Backup').attr('disabled', true);
$('#Backup-result').html(loading);
const backupDirectory = $('#backupDir').val();
$.get(scRoot + '/config/backuprestore/backup', {backupDirectory}).done(data => {
$('#Backup-result').html(data);
$('#Backup').attr('disabled', false);
$('#backup-submit').on('click', () => {
$('#backup-submit').attr('disabled', true);
$('#backup-result').html(loading);
$.post(scRoot + '/config/backuprestore/backup', {backupDirectory: $('#backupDirectory').val()}).done(data => {
$('#backup-result').html(data);
$('#backup-submit').attr('disabled', false);
});
});
$('#Restore').on('click', () => {
$('#Restore').attr('disabled', true);
$('#Restore-result').html(loading);
const backupFile = $('#backupFile').val();
$.post(scRoot + '/config/backuprestore/restore', {backupFile}).done(data => {
$('#Restore-result').html(data);
$('#Restore').attr('disabled', false);
$('#restore-submit').on('click', () => {
$('#restore-submit').attr('disabled', true);
$('#restore-result').html(loading);
$.post(scRoot + '/config/backuprestore/restore', {backupFile: $('#backupFile').val()}).done(data => {
$('#restore-result').html(data);
$('#restore-submit').attr('disabled', false);
});
});

$('#backupDir').fileBrowser({title: _('Select backup folder to save to'), key: 'backupPath'});
$('#backupDirectory').fileBrowser({title: _('Select backup folder to save to'), key: 'backupPath'});
$('#backupFile').fileBrowser({title: _('Select backup files to restore'), key: 'backupFile', includeFiles: 1});
$('#config-components').tabs();
},
Expand Down Expand Up @@ -1387,7 +1385,7 @@ const SICKCHILL = {

$.post(scRoot + '/config/postProcessing/testNaming', {
pattern,
abd: 'True',
abd: true,
}, data => {
if (data) {
$('#naming_abd_example').text(data + '.ext');
Expand All @@ -1399,7 +1397,7 @@ const SICKCHILL = {

$.post(scRoot + '/config/postProcessing/isNamingValid', {
pattern,
abd: 'True',
abd: true,
}, data => {
let info;
if (data === 'invalid') {
Expand Down Expand Up @@ -1437,7 +1435,7 @@ const SICKCHILL = {

$.post(scRoot + '/config/postProcessing/testNaming', {
pattern,
sports: 'True', // @TODO does this actually need to be a string or can it be a boolean?
sports: true,
}, data => {
if (data) {
$('#naming_sports_example').text(data + '.ext');
Expand All @@ -1449,7 +1447,7 @@ const SICKCHILL = {

$.post(scRoot + '/config/postProcessing/isNamingValid', {
pattern,
sports: 'True', // @TODO does this actually need to be a string or can it be a boolean?
sports: true,
}, data => {
let info;
if (data === 'invalid') {
Expand Down
2 changes: 1 addition & 1 deletion sickchill/gui/slick/js/core.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions sickchill/gui/slick/js/rootDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(function () {
let method;
const noop = function () {};

const methods = [
'assert',
'clear',
Expand Down Expand Up @@ -66,10 +67,10 @@ $(document).ready(() => {

function syncOptionIDs() {
// Re-sync option ids
let i = 0;
let index = 0;
$('#rootDirs option').each(function () {
i++;
$(this).attr('id', 'rd-' + i);
index++;
$(this).attr('id', 'rd-' + index);
});
}

Expand Down
12 changes: 6 additions & 6 deletions sickchill/gui/slick/views/config_backuprestore.mako
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
${_('Select the folder you wish to save your backup file to')}:
</div>
<div class="col-md-12">
<input type="text" name="backupDir" id="backupDir" class="form-control input-sm input350" autocapitalize="off" title="Backup directory" />
<input class="btn btn-inline" type="button" value="Backup" id="Backup" />
<input type="text" name="backupDirectory" id="backupDirectory" class="form-control input-sm input350" autocapitalize="off" title="Backup directory"/>
<input class="btn btn-inline" type="button" value="${_('Backup')}" id="backup-submit"/>
</div>
</div>
</div>
</div>
<div class="Backup" id="Backup-result"></div>
<div class="Backup" id="backup-result"></div>
</fieldset>
</div>
</div>
Expand All @@ -57,13 +57,13 @@
${_('Select the backup file you wish to restore')}:
</div>
<div class="col-md-12">
<input type="text" name="backupFile" id="backupFile" class="form-control input-sm input350" autocapitalize="off" title="Backup directory" />
<input class="btn btn-inline" type="button" value="${_('Restore')}" id="Restore" />
<input type="text" name="backupFile" id="backupFile" class="form-control input-sm input350" autocapitalize="off" title="Backup directory"/>
<input class="btn btn-inline" type="button" value="${_('Restore')}" id="restore-submit"/>
</div>
</div>
</div>
</div>
<div class="Restore" id="Restore-result"></div>
<div class="Restore" id="restore-result"></div>
</fieldset>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions sickchill/gui/slick/views/displayShow.mako
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
</div>
<select id="pickShow" class="form-control input-sm" title="Change Show">
% for cur_show_list in sorted_show_lists:
% if len(sorted_show_lists) > 1:
% if settings.ANIME_SPLIT_HOME and len(sorted_show_lists) > 1 and cur_show_list[1]:
<optgroup label="${cur_show_list[0]}">
% endif
% for curShow in cur_show_list[1]:
<option value="${curShow.indexerid}" ${selected(curShow == show)}>${curShow.name}</option>
% endfor
% if len(sorted_show_lists) > 1:
% if settings.ANIME_SPLIT_HOME and len(sorted_show_lists) > 1 and cur_show_list[1]:
</optgroup>
% endif
% endfor
Expand Down
3 changes: 1 addition & 2 deletions sickchill/gui/slick/views/manage.mako
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<%inherit file="/layouts/main.mako" />
<%!
from operator import attrgetter
from sickchill import settings
from sickchill.oldbeard.common import statusStrings
%>
Expand Down Expand Up @@ -80,7 +79,7 @@
</tr>
</thead>
<tbody>
% for curShow in sorted(settings.showList, key=lambda mbr: attrgetter('sort_name')(mbr)):
% for curShow in settings.show_list:
<%
if settings.showQueueScheduler.action.is_in_remove_queue(curShow) or settings.showQueueScheduler.action.is_being_removed(curShow):
continue
Expand Down
6 changes: 3 additions & 3 deletions sickchill/init_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
logger.addHandler(logging.StreamHandler())

# locale_dir = sickchill_dir / "locale"
pid_file: Path = None
pid_file: Union[Path, None] = None


sickchill_dir = Path(__file__).parent
Expand Down Expand Up @@ -139,10 +139,10 @@ def check_installed() -> bool:

def get_current_version() -> str:
fallback_version = "0.0.0"
version_regex = re.compile(r'\s*version\s*=\s*["\']([.0-9a-z-+]+)["\']\s*$')
matcher = re.compile(r'\s*version\s*=\s*["\']([.0-9a-z-+]+)["\']\s*$')
if pyproject_file.is_file():
for line in pyproject_file.open():
match = version_regex.match(line)
match = matcher.match(line)
if match:
return match.group(1)
return fallback_version
Expand Down
Loading

0 comments on commit 3024ab2

Please sign in to comment.