From 987103b21399ae85dd3d6322f4d3c72b7a0a0874 Mon Sep 17 00:00:00 2001 From: TheAMM Date: Sun, 30 Jul 2017 11:32:17 +0300 Subject: [PATCH] Handle qButtorrent empty url-list/webseeds url-list is supposed to be omitted in case of no webseeds, but qB will instead use an empty bytestring '' as the value. This commit makes the validation more lenient regarding url-list. --- nyaa/backend.py | 3 ++- nyaa/forms.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nyaa/backend.py b/nyaa/backend.py index 2b76c8a..220e954 100644 --- a/nyaa/backend.py +++ b/nyaa/backend.py @@ -140,7 +140,8 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False): trackers.add(announce[0].decode('ascii')) # Store webseeds - webseed_list = torrent_data.torrent_dict.get('url-list', []) + # qBittorrent doesn't omit url-list but sets it as '' even when there are no webseeds + webseed_list = torrent_data.torrent_dict.get('url-list') or [] webseeds = OrderedSet(webseed.decode('utf-8') for webseed in webseed_list) # Remove our trackers, maybe? TODO ? diff --git a/nyaa/forms.py b/nyaa/forms.py index 1f62fcb..125f0d0 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -346,7 +346,8 @@ def _validate_trackers(torrent_dict, tracker_to_check_for=None): # http://www.bittorrent.org/beps/bep_0019.html def _validate_webseeds(torrent_dict): webseed_list = torrent_dict.get('url-list') - if webseed_list is not None: + # qBittorrent has an empty field instead of omitting the key, so just check for truthiness + if webseed_list: _validate_list(webseed_list, 'url-list') for webseed_url in webseed_list: