From d5a5b94af885a615fd3d2306d22ef6325d19a024 Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Fri, 23 Sep 2016 11:59:10 +0200 Subject: [PATCH] Change update and use backlogparts when BACKLOG_FREQUENCY setting is changed. --- sickbeard/processTV.py | 10 +++++----- sickbeard/search_backlog.py | 28 ++++++++++++++++++++++++++-- sickbeard/webserve.py | 2 ++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/sickbeard/processTV.py b/sickbeard/processTV.py index d85477af..90885a45 100644 --- a/sickbeard/processTV.py +++ b/sickbeard/processTV.py @@ -265,7 +265,7 @@ class ProcessTVShow(object): (ex(e), e.filename and (' (file %s)' % e.filename) or ''), logger.WARNING) # Process video files in TV subdirectories - for directory in [x for x in dirs if self._validate_dir(path, x, nzb_name_original, failed)]: + for directory in [x for x in dirs if self._validate_dir(path, x, nzb_name_original, failed, showObj=showObj)]: # self._set_process_success(reset=True) @@ -386,7 +386,7 @@ class ProcessTVShow(object): return archives, archive_history - def _validate_dir(self, path, dir_name, nzb_name_original, failed): + def _validate_dir(self, path, dir_name, nzb_name_original, failed, showObj=None): self._log_helper(u'Processing sub dir: ' + dir_name) @@ -434,14 +434,14 @@ class ProcessTVShow(object): # check if the directory have at least one tv video file for video in video_files: try: - NameParser().parse(video, cache_result=False) + NameParser(showObj=showObj).parse(video, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass for directory in all_dirs: try: - NameParser().parse(directory, cache_result=False) + NameParser(showObj=showObj).parse(directory, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass @@ -452,7 +452,7 @@ class ProcessTVShow(object): for packed in packed_files: try: - NameParser().parse(packed, cache_result=False) + NameParser(showObj=showObj).parse(packed, cache_result=False) return True except (InvalidNameException, InvalidShowException): pass diff --git a/sickbeard/search_backlog.py b/sickbeard/search_backlog.py index 5b1ef890..615db1ef 100644 --- a/sickbeard/search_backlog.py +++ b/sickbeard/search_backlog.py @@ -16,10 +16,11 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . -from __future__ import with_statement +from __future__ import with_statement, division import datetime import threading +from math import ceil import sickbeard @@ -119,6 +120,29 @@ class BacklogSearcher: forced=forced, torrent_only=torrent_only) sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) + @staticmethod + def change_backlog_parts(old_count, new_count): + try: + my_db = db.DBConnection('cache.db') + sql_result = my_db.select('SELECT * FROM backlogparts') + if sql_result: + current_parts = len(set(s['part'] for s in sql_result)) + parts_count = len(sql_result) + new_part_count = int(ceil(new_count / old_count * current_parts)) + parts = int(ceil(parts_count / new_part_count)) + cl = ([], [['DELETE FROM backlogparts']])[parts_count > 1] + p = new_count - new_part_count + for i, s in enumerate(sql_result): + if i % parts == 0: + p += 1 + cl.append(['INSERT INTO backlogparts (part, indexerid, indexer) VALUES (?,?,?)', + [p, s['indexerid'], s['indexer']]]) + + if 0 < len(cl): + my_db.mass_action(cl) + except: + pass + def search_backlog(self, which_shows=None, force_type=NORMAL_BACKLOG, force=False): if self.amActive: @@ -188,7 +212,7 @@ class BacklogSearcher: parts = [] if standard_backlog and not torrent_only and not continued_backlog: - fullbacklogparts = sum([len(w) for w in wanted_list if w]) / sickbeard.BACKLOG_FREQUENCY + fullbacklogparts = sum([len(w) for w in wanted_list if w]) // sickbeard.BACKLOG_FREQUENCY h_part = [] counter = 0 for w in wanted_list: diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 669b9e38..51a17475 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -4494,7 +4494,9 @@ class ConfigSearch(Config): config.change_RECENTSEARCH_FREQUENCY(recentsearch_frequency) + old_backlog_frequency = sickbeard.BACKLOG_FREQUENCY config.change_BACKLOG_FREQUENCY(backlog_frequency) + sickbeard.search_backlog.BacklogSearcher.change_backlog_parts(old_backlog_frequency, sickbeard.BACKLOG_FREQUENCY) sickbeard.BACKLOG_DAYS = config.to_int(backlog_days, default=7) sickbeard.USE_NZBS = config.checkbox_to_value(use_nzbs)