From b499e4b6db20d88b38b11bc548bde376d1ad074c Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 22 May 2014 23:42:11 -0700 Subject: [PATCH] Fixed issues with per-provider torrent ratio settings, now can be left blank to default to client ratio setting. --- .../interfaces/default/config_providers.tmpl | 12 +++++-- sickbeard/__init__.py | 29 +++++++-------- sickbeard/clients/deluge.py | 33 +++++++---------- sickbeard/clients/transmission.py | 20 +++++------ sickbeard/clients/utorrent.py | 36 ++++++++----------- sickbeard/webserve.py | 4 +-- 6 files changed, 63 insertions(+), 71 deletions(-) diff --git a/gui/slick/interfaces/default/config_providers.tmpl b/gui/slick/interfaces/default/config_providers.tmpl index f766aed0..7521c75e 100644 --- a/gui/slick/interfaces/default/config_providers.tmpl +++ b/gui/slick/interfaces/default/config_providers.tmpl @@ -366,7 +366,13 @@ var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#;
+
#end if @@ -375,7 +381,7 @@ var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#;
#end if @@ -384,7 +390,7 @@ var show_nzb_providers = #if $sickbeard.USE_NZBS then "true" else "false"#;
#end if diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 2b13b27f..070fbc58 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -11,7 +11,7 @@ # Sick Beard is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . @@ -944,7 +944,8 @@ def initialize(consoleLogging=True): properFinderScheduler.silent = True autoPostProcesserScheduler = scheduler.Scheduler(autoPostProcesser.PostProcesser(), - cycleTime=datetime.timedelta(minutes=AUTOPOSTPROCESSER_FREQUENCY), + cycleTime=datetime.timedelta( + minutes=AUTOPOSTPROCESSER_FREQUENCY), threadName="POSTPROCESSER", runImmediately=True) if not PROCESS_AUTOMATICALLY: @@ -1018,14 +1019,14 @@ def initialize(consoleLogging=True): curTorrentProvider.options = check_setting_str(CFG, curTorrentProvider.getID().upper(), curTorrentProvider.getID() + '_options', '') if hasattr(curTorrentProvider, 'ratio'): - curTorrentProvider.ratio = float(check_setting_float(CFG, curTorrentProvider.getID().upper(), - curTorrentProvider.getID() + '_ratio', 0)) + curTorrentProvider.ratio = check_setting_str(CFG, curTorrentProvider.getID().upper(), + curTorrentProvider.getID() + '_ratio', '') if hasattr(curTorrentProvider, 'minseed'): curTorrentProvider.minseed = check_setting_int(CFG, curTorrentProvider.getID().upper(), - curTorrentProvider.getID() + '_minseed', 0) + curTorrentProvider.getID() + '_minseed', 0) if hasattr(curTorrentProvider, 'minleech'): curTorrentProvider.minleech = check_setting_int(CFG, curTorrentProvider.getID().upper(), - curTorrentProvider.getID() + '_minleech', 0) + curTorrentProvider.getID() + '_minleech', 0) if hasattr(curTorrentProvider, 'freeleech'): curTorrentProvider.freeleech = bool(check_setting_int(CFG, curTorrentProvider.getID().upper(), curTorrentProvider.getID() + '_freeleech', 0)) @@ -1054,16 +1055,16 @@ def initialize(consoleLogging=True): curNzbProvider.getID() + '_username', '') if hasattr(curNzbProvider, 'search_mode'): curNzbProvider.search_mode = check_setting_str(CFG, curNzbProvider.getID().upper(), - curNzbProvider.getID() + '_search_mode', - 'eponly') + curNzbProvider.getID() + '_search_mode', + 'eponly') if hasattr(curNzbProvider, 'search_fallback'): curNzbProvider.search_fallback = bool(check_setting_int(CFG, curNzbProvider.getID().upper(), - curNzbProvider.getID() + '_search_fallback', - 0)) + curNzbProvider.getID() + '_search_fallback', + 0)) if hasattr(curNzbProvider, 'backlog_only'): curNzbProvider.backlog_only = bool(check_setting_int(CFG, curNzbProvider.getID().upper(), - curNzbProvider.getID() + '_backlog_only', - 0)) + curNzbProvider.getID() + '_backlog_only', + 0)) try: url = 'http://raw.github.com/echel0n/sickrage-init/master/settings.ini' @@ -1436,8 +1437,8 @@ def save_config(): new_config[curTorrentProvider.getID().upper()][curTorrentProvider.getID() + '_confirmed'] = int( curTorrentProvider.confirmed) if hasattr(curTorrentProvider, 'ratio'): - new_config[curTorrentProvider.getID().upper()][curTorrentProvider.getID() + '_ratio'] = float( - curTorrentProvider.ratio) + new_config[curTorrentProvider.getID().upper()][ + curTorrentProvider.getID() + '_ratio'] = curTorrentProvider.ratio if hasattr(curTorrentProvider, 'minseed'): new_config[curTorrentProvider.getID().upper()][curTorrentProvider.getID() + '_minseed'] = int( curTorrentProvider.minseed) diff --git a/sickbeard/clients/deluge.py b/sickbeard/clients/deluge.py index c99a2532..eff93d83 100644 --- a/sickbeard/clients/deluge.py +++ b/sickbeard/clients/deluge.py @@ -164,31 +164,24 @@ class DelugeAPI(GenericClient): def _set_torrent_ratio(self, result): - ratio = '' + ratio = None if result.ratio: ratio = result.ratio - else: - return True - try: - float(ratio) - except ValueError: - logger.log(self.name + u': Invalid Ratio. "' + ratio + u'" is not a number', logger.ERROR) - return False + if ratio: + post_data = json.dumps({"method": "core.set_torrent_stop_at_ratio", + "params": [result.hash, True], + "id": 5 + }) + self._request(method='post', data=post_data) - post_data = json.dumps({"method": "core.set_torrent_stop_at_ratio", - "params": [result.hash, True], - "id": 5 - }) - self._request(method='post', data=post_data) + post_data = json.dumps({"method": "core.set_torrent_stop_ratio", + "params": [result.hash, float(ratio)], + "id": 6 + }) + self._request(method='post', data=post_data) - post_data = json.dumps({"method": "core.set_torrent_stop_ratio", - "params": [result.hash, float(ratio)], - "id": 6 - }) - self._request(method='post', data=post_data) - - return not self.response.json()['error'] + return not self.response.json()['error'] return True diff --git a/sickbeard/clients/transmission.py b/sickbeard/clients/transmission.py index 81aa1b9d..e106ea3b 100644 --- a/sickbeard/clients/transmission.py +++ b/sickbeard/clients/transmission.py @@ -80,7 +80,7 @@ class TransmissionAPI(GenericClient): def _set_torrent_ratio(self, result): - ratio = '' + ratio = None if result.ratio: ratio = result.ratio if ratio: @@ -92,16 +92,14 @@ class TransmissionAPI(GenericClient): torrent_id = self._get_torrent_hash(result) - if ratio == '': - # Use global settings - ratio = None - mode = 0 - elif float(ratio) == 0: - ratio = 0 - mode = 2 - elif float(ratio) > 0: - ratio = float(ratio) - mode = 1 # Stop seeding at seedRatioLimit + mode = 0 + if ratio: + if float(ratio) == 0: + ratio = 0 + mode = 2 + elif float(ratio) > 0: + ratio = float(ratio) + mode = 1 # Stop seeding at seedRatioLimit arguments = {'ids': [torrent_id], 'seedRatioLimit': ratio, diff --git a/sickbeard/clients/utorrent.py b/sickbeard/clients/utorrent.py index 2110dd59..a65742ad 100644 --- a/sickbeard/clients/utorrent.py +++ b/sickbeard/clients/utorrent.py @@ -67,33 +67,27 @@ class uTorrentAPI(GenericClient): def _set_torrent_ratio(self, result): - ratio = '' + ratio = None if result.ratio: ratio = result.ratio - else: - return True - try: - float(ratio) - except ValueError: - logger.log(self.name + u': Invalid Ratio. "' + ratio + u'" is not a number', logger.ERROR) - return False - - ratio = 10 * float(ratio) - params = {'action': 'setprops', - 'hash': result.hash, - 's': 'seed_override', - 'v': '1' - } - if self._request(params=params): + if ratio: params = {'action': 'setprops', 'hash': result.hash, - 's': 'seed_ratio', - 'v': ratio + 's': 'seed_override', + 'v': '1' } - return self._request(params=params) - else: - return False + if self._request(params=params): + params = {'action': 'setprops', + 'hash': result.hash, + 's': 'seed_ratio', + 'v': float(ratio) * 10 + } + return self._request(params=params) + else: + return False + + return True def _set_torrent_seed_time(self, result): diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 3c3047da..14e6e01a 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1593,9 +1593,9 @@ class ConfigProviders: if hasattr(curTorrentProvider, 'ratio'): try: - curTorrentProvider.ratio = float(str(kwargs[curTorrentProvider.getID() + '_ratio']).strip()) + curTorrentProvider.ratio = str(kwargs[curTorrentProvider.getID() + '_ratio']).strip() except: - curTorrentProvider.ratio = 0 + curTorrentProvider.ratio = None if hasattr(curTorrentProvider, 'digest'): try: