Skip to content

Commit

Permalink
feat: add seed time, ratio, incomplete dir and additional trackers to…
Browse files Browse the repository at this point in the history
… qBitTorrent client and fix torrent save path (#8628)

clean up some logging
---------

Co-authored-by: miigotu <[email protected]>
  • Loading branch information
BKSteve and miigotu authored Nov 24, 2023
1 parent f646f34 commit 50d590b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 5 additions & 1 deletion sickchill/gui/slick/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,11 @@ const SICKCHILL = {
$('#torrent_auth_type_option').show();
} else if (selectedProvider.toLowerCase() === 'qbittorrent') {
client = 'qBittorrent';
$('#torrent_path_option').hide();
$('#torrent_path_option').show();
$('#torrent_path_option').find('.fileBrowser').show();
$('#torrent_path_incomplete_option').show();
$('#torrent_seed_time_label').text(_('Stop seeding after'));
$('#torrent_seed_time_option').show();
$('#label_warning_qbittorrent').show();
$('#label_anime_warning_qbittorrent').show();
$('#torrent_verify_cert_option').show();
Expand Down
8 changes: 4 additions & 4 deletions sickchill/oldbeard/clients/download_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def _check_response(self, data=None):
api_method = (data or {}).get("method", "login")
log_string = self.error_map.get(api_method).get(error_code, None)
if not log_string:
logger.info(jdata)
logger.debug(jdata)
else:
logger.info("{0}".format(log_string))
logger.debug(f"{log_string}")

return jdata.get("success")

Expand Down Expand Up @@ -187,7 +187,7 @@ def _add_torrent_uri(self, result: "SearchResult"):
data["create_list"] = "false"
data["destination"] = self._get_destination(result)

logger.info('Posted as url with {} destination "{}"'.format(data["api"], data["destination"]))
logger.debug(f"Posted as file with {data['api']} destination {data['destination']}")
self._request(method="post", data=data)
return self._check_response(data)

Expand All @@ -208,7 +208,7 @@ def _add_torrent_file(self, result: "SearchResult"):
data["create_list"] = "false"
data["destination"] = f'"{self._get_destination(result)}"'

logger.info("Posted as file with {} destination {}".format(data["api"], data["destination"]))
logger.debug(f"Posted as file with {data['api']} destination {data['destination']}")
self._request(method="post", data=data, files=files)
return self._check_response(data)

Expand Down
29 changes: 23 additions & 6 deletions sickchill/oldbeard/clients/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import qbittorrentapi

from sickchill import settings
from sickchill import logger, settings
from sickchill.oldbeard.clients.generic import GenericClient

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -41,20 +41,37 @@ def test_client_connection(self):
return True, "Success: Connected and Authenticated"

@staticmethod
def __torrent_args(result: "TorrentSearchResult"):
def __torrent_args(result: "TorrentSearchResult") -> dict:
return dict(
save_path=settings.TORRENT_DIR or None,
save_path=settings.TORRENT_PATH or None,
download_path=settings.TORRENT_PATH_INCOMPLETE or None,
category=(settings.TORRENT_LABEL, settings.TORRENT_LABEL_ANIME)[result.show.is_anime] or settings.TORRENT_LABEL,
is_paused=settings.TORRENT_PAUSED,
ratio_limit=(None, float(result.ratio))[float(result.ratio) > 0],
seeding_time_limit=(None, 60 * int(settings.TORRENT_SEED_TIME))[int(settings.TORRENT_SEED_TIME) > 0],
tags=("sickchill", "sickchill-anime")[result.show.is_anime],
)

def __add_trackers(self, result: "TorrentSearchResult"):
if settings.TRACKERS_LIST and result.provider.public:
trackers = list({x.strip() for x in settings.TRACKERS_LIST.split(",") if x.strip()})
if trackers:
logger.debug(f"Adding trackers to public torrent")
return self.api.torrents_add_trackers(torrent_hash=result.hash.lower(), urls=trackers)

def _add_torrent_uri(self, result: "TorrentSearchResult"):
return self.api.torrents_add(urls=[result.url], **self.__torrent_args(result))
logger.debug(f"Posting as url with {self.__torrent_args(result)}")
action = self.api.torrents_add(urls=[result.url], **self.__torrent_args(result))
self.__add_trackers(result)
return action

def _add_torrent_file(self, result: "TorrentSearchResult"):
return self.api.torrents_add(torrent_files=[result.content], **self.__torrent_args(result))
logger.debug(f"Posting as file with {self.__torrent_args(result)}")
action = self.api.torrents_add(torrent_files=[result.content], **self.__torrent_args(result))
self.__add_trackers(result)
return action

def _set_torrent_priority(self, result: "TorrentSearchResult"):
if not self.api.app_preferences().get("queueing_enabled"):
return True
return (self.api.torrents_decrease_priority, self.api.torrents_increase_priority)[result.priority == 1](result.hash.lower)
return (self.api.torrents_decrease_priority, self.api.torrents_increase_priority)[result.priority == 1](result.hash.lower())
2 changes: 1 addition & 1 deletion sickchill/views/config/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def saveProviders(self):
provider.check_set_option(self, "sorting", "seeders")
provider.check_set_option(self, "search_mode", "episode")

provider.check_set_option(self, "ratio", 0, cast=lambda x: max(try_int(x), -1))
provider.check_set_option(self, "ratio", 0, cast=float)

settings.NEWZNAB_DATA = "!!!".join([x.config_string() for x in settings.newznab_provider_list])
settings.PROVIDER_ORDER = enabled_provider_list + disabled_provider_list
Expand Down

0 comments on commit 50d590b

Please sign in to comment.