Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error added by qbittorrent 5.0 pymedusa/Medusa#11844 #11857

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ def initialize(self, console_logging=True):
app.TORRENT_PATH = check_setting_str(app.CFG, 'TORRENT', 'torrent_path', '')
app.TORRENT_SEED_TIME = check_setting_int(app.CFG, 'TORRENT', 'torrent_seed_time', 0)
app.TORRENT_PAUSED = bool(check_setting_int(app.CFG, 'TORRENT', 'torrent_paused', 0))
app.TORRENT_STOPPED = bool(check_setting_int(app.CFG, 'TORRENT', 'torrent_stopped', 0))
app.TORRENT_HIGH_BANDWIDTH = bool(check_setting_int(app.CFG, 'TORRENT', 'torrent_high_bandwidth', 0))
app.TORRENT_LABEL = check_setting_str(app.CFG, 'TORRENT', 'torrent_label', '')
app.TORRENT_LABEL_ANIME = check_setting_str(app.CFG, 'TORRENT', 'torrent_label_anime', '')
Expand Down Expand Up @@ -1854,6 +1855,7 @@ def save_config():
new_config['TORRENT']['torrent_path'] = app.TORRENT_PATH
new_config['TORRENT']['torrent_seed_time'] = int(app.TORRENT_SEED_TIME)
new_config['TORRENT']['torrent_paused'] = int(app.TORRENT_PAUSED)
new_config['TORRENT']['torrent_stopped'] = int(app.TORRENT_STOPPED)
new_config['TORRENT']['torrent_high_bandwidth'] = int(app.TORRENT_HIGH_BANDWIDTH)
new_config['TORRENT']['torrent_label'] = app.TORRENT_LABEL
new_config['TORRENT']['torrent_label_anime'] = app.TORRENT_LABEL_ANIME
Expand Down
1 change: 1 addition & 0 deletions medusa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def __init__(self):
self.TORRENT_PATH = ''
self.TORRENT_SEED_TIME = None
self.TORRENT_PAUSED = False
self.TORRENT_STOPPED = False
self.TORRENT_HIGH_BANDWIDTH = False
self.TORRENT_LABEL = ''
self.TORRENT_LABEL_ANIME = ''
Expand Down
16 changes: 14 additions & 2 deletions medusa/clients/torrent/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ def _set_torrent_pause(self, result):
"""
return True

def _set_torrent_stop(self, result):
"""Return the True/False from the client when a torrent is set with stop.

:param result:
:type result: medusa.classes.SearchResult
:return:
:rtype: bool
"""
return True

@staticmethod
def _get_info_hash(result):
if result.url.startswith('magnet:'):
Expand Down Expand Up @@ -238,8 +248,10 @@ def send_torrent(self, result):
log.warning('{name}: Unable to send Torrent', {'name': self.name})
return False

if not self._set_torrent_pause(result):
log.error('{name}: Unable to set the pause for Torrent', {'name': self.name})
if self._set_torrent_pause(result) or self._set_torrent_stop(result):
log.info('{name}: Able to set the pause/stop for Torrent', {'name': self.name})
else:
log.error('{name}: Unable to set the pause/stop for Torrent', {'name': self.name})

if not self._set_torrent_label(result):
log.error('{name}: Unable to set the label for Torrent', {'name': self.name})
Expand Down
18 changes: 17 additions & 1 deletion medusa/clients/torrent/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ def _set_torrent_priority(self, result):
def _set_torrent_pause(self, result):
return self.pause_torrent(result.hash, state='pause' if app.TORRENT_PAUSED else 'resume')

def _set_torrent_stop(self, result):
return self.stop_torrent(result.hash, state='stop' if app.TORRENT_STOPPED else 'start')

def pause_torrent(self, info_hash, state='pause'):
"""Pause torrent."""
command = 'api/v2/torrents' if self.api >= (2, 0, 0) else 'command'
Expand All @@ -248,6 +251,16 @@ def pause_torrent(self, info_hash, state='pause'):
hashes_key: info_hash.lower()
}
return self._request(method='post', data=data, cookies=self.session.cookies)

def stop_torrent(self, info_hash, state='stop'):
"""Stop torrent."""
command = 'api/v2/torrents' if self.api >= (2, 0, 0) else 'command'
hashes_key = 'hashes' if self.api >= (1, 18, 0) else 'hash'
self.url = urljoin(self.host, '{command}/{state}'.format(command=command, state=state))
data = {
hashes_key: info_hash.lower()
}
return self._request(method='post', data=data, cookies=self.session.cookies)

def _remove(self, info_hash, from_disk=False):
"""Remove torrent from client using given info_hash.
Expand Down Expand Up @@ -398,10 +411,13 @@ def get_status(self, info_hash):
if torrent['state'] in ('pausedDL', 'stalledDL'):
client_status.set_status_string('Paused')

if torrent['state'] in ('stoppdDL'):
client_status.set_status_string('Stopped')

if torrent['state'] == 'error':
client_status.set_status_string('Failed')

if torrent['state'] in ('uploading', 'queuedUP', 'checkingUP', 'forcedUP', 'stalledUP', 'pausedUP'):
if torrent['state'] in ('uploading', 'queuedUP', 'checkingUP', 'forcedUP', 'stalledUP', 'pausedUP', 'stoppedUP'):
client_status.set_status_string('Completed')

# if torrent['ratio'] >= torrent['max_ratio']:
Expand Down
2 changes: 2 additions & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class ConfigHandler(BaseRequestHandler):
'clients.torrents.password': StringField(app, 'TORRENT_PASSWORD'),
'clients.torrents.path': StringField(app, 'TORRENT_PATH'),
'clients.torrents.paused': BooleanField(app, 'TORRENT_PAUSED'),
'clients.torrents.stopped': BooleanField(app, 'TORRENT_STOPPED'),
'clients.torrents.rpcUrl': StringField(app, 'TORRENT_RPCURL'),
'clients.torrents.seedLocation': StringField(app, 'TORRENT_SEED_LOCATION'),
'clients.torrents.seedTime': IntegerField(app, 'TORRENT_SEED_TIME'),
Expand Down Expand Up @@ -1186,6 +1187,7 @@ def data_clients():
section_data['torrents']['saveMagnetFile'] = bool(app.SAVE_MAGNET_FILE)
section_data['torrents']['path'] = app.TORRENT_PATH
section_data['torrents']['paused'] = bool(app.TORRENT_PAUSED)
section_data['torrents']['stopped'] = bool(app.TORRENT_STOPPED)
section_data['torrents']['rpcUrl'] = app.TORRENT_RPCURL
section_data['torrents']['seedLocation'] = app.TORRENT_SEED_LOCATION
section_data['torrents']['seedTime'] = app.TORRENT_SEED_TIME
Expand Down
3 changes: 2 additions & 1 deletion medusa/server/web/config/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def saveSearch(self, use_nzbs=None, use_torrents=None, nzb_dir=None, sab_usernam
randomize_providers=None, use_failed_downloads=None, delete_failed=None, propers_search_days=None,
torrent_dir=None, torrent_username=None, torrent_password=None, torrent_host=None,
torrent_label=None, torrent_label_anime=None, torrent_path=None, torrent_verify_cert=None,
torrent_seed_time=None, torrent_paused=None, torrent_high_bandwidth=None,
torrent_seed_time=None, torrent_paused=None, torrent_stopped=None, torrent_high_bandwidth=None,
torrent_rpcurl=None, torrent_auth_type=None, ignore_words=None, download_handler_frequency=None,
preferred_words=None, undesired_words=None, trackers_list=None, require_words=None,
ignored_subs_list=None, ignore_und_subs=None, cache_trimming=None, max_cache_age=None,
Expand Down Expand Up @@ -130,6 +130,7 @@ def saveSearch(self, use_nzbs=None, use_torrents=None, nzb_dir=None, sab_usernam
app.TORRENT_PATH = torrent_path.rstrip('/\\')
app.TORRENT_SEED_TIME = torrent_seed_time
app.TORRENT_PAUSED = config.checkbox_to_value(torrent_paused)
app.TORRENT_STOPPED = config.checkbox_to_value(torrent_stopped)
app.TORRENT_HIGH_BANDWIDTH = config.checkbox_to_value(torrent_high_bandwidth)
app.TORRENT_HOST = config.clean_url(torrent_host)
app.TORRENT_RPCURL = torrent_rpcurl
Expand Down
1 change: 1 addition & 0 deletions tests/apiv2/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def config_clients():
section_data['torrents']['method'] = app.TORRENT_METHOD
section_data['torrents']['path'] = app.TORRENT_PATH
section_data['torrents']['paused'] = bool(app.TORRENT_PAUSED)
section_data['torrents']['stopped'] = bool(app.TORRENT_STOPPED)
section_data['torrents']['rpcUrl'] = app.TORRENT_RPCURL
section_data['torrents']['seedLocation'] = app.TORRENT_SEED_LOCATION
section_data['torrents']['seedTime'] = app.TORRENT_SEED_TIME
Expand Down