mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-10-31 23:35:55 +00:00
Completely handle qBittorrent webseeds
Fixes #319 Zero webseeds: empty bytestring One webseed: bytestring More than one: a list of bytestrings (as the spec asks for!)
This commit is contained in:
parent
987103b213
commit
1dae331156
|
@ -142,6 +142,8 @@ def handle_torrent_upload(upload_form, uploading_user=None, fromAPI=False):
|
||||||
# Store webseeds
|
# Store webseeds
|
||||||
# qBittorrent doesn't omit url-list but sets it as '' even when there are no webseeds
|
# 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 []
|
webseed_list = torrent_data.torrent_dict.get('url-list') or []
|
||||||
|
if isinstance(webseed_list, bytes):
|
||||||
|
webseed_list = [webseed_list] # qB doesn't contain a sole url in a list
|
||||||
webseeds = OrderedSet(webseed.decode('utf-8') for webseed in webseed_list)
|
webseeds = OrderedSet(webseed.decode('utf-8') for webseed in webseed_list)
|
||||||
|
|
||||||
# Remove our trackers, maybe? TODO ?
|
# Remove our trackers, maybe? TODO ?
|
||||||
|
|
|
@ -346,7 +346,15 @@ def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
||||||
# http://www.bittorrent.org/beps/bep_0019.html
|
# http://www.bittorrent.org/beps/bep_0019.html
|
||||||
def _validate_webseeds(torrent_dict):
|
def _validate_webseeds(torrent_dict):
|
||||||
webseed_list = torrent_dict.get('url-list')
|
webseed_list = torrent_dict.get('url-list')
|
||||||
# qBittorrent has an empty field instead of omitting the key, so just check for truthiness
|
if isinstance(webseed_list, bytes):
|
||||||
|
# url-list should be omitted in case of no webseeds. However.
|
||||||
|
# qBittorrent has an empty bytestring for no webseeds,
|
||||||
|
# a bytestring for one and a list for multiple, so:
|
||||||
|
# In case of a empty, keep as-is for next if.
|
||||||
|
# In case of one, wrap it in a list.
|
||||||
|
webseed_list = webseed_list and [webseed_list]
|
||||||
|
|
||||||
|
# Merely check for truthiness ([], '' or a list with items)
|
||||||
if webseed_list:
|
if webseed_list:
|
||||||
_validate_list(webseed_list, 'url-list')
|
_validate_list(webseed_list, 'url-list')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue