keyword search enhancements
This commit is contained in:
parent
352427ca20
commit
190b180255
|
@ -37,18 +37,42 @@ from deluge.log import LOG as log
|
||||||
STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"]
|
STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"]
|
||||||
|
|
||||||
#special purpose filters:
|
#special purpose filters:
|
||||||
def filter_keyword(torrent_ids, values):
|
def filter_keywords(torrent_ids, values):
|
||||||
keywords = [v.lower() for v in values] #cleanup.
|
#cleanup.
|
||||||
|
keywords = ",".join([v.lower() for v in values])
|
||||||
|
keywords = keywords.split(",")
|
||||||
|
|
||||||
|
|
||||||
|
for keyword in keywords:
|
||||||
|
torrent_ids = filter_one_keyword(torrent_ids, keyword)
|
||||||
|
return torrent_ids
|
||||||
|
|
||||||
|
def filter_one_keyword(torrent_ids, keyword):
|
||||||
|
"""
|
||||||
|
search torrent on keyword.
|
||||||
|
searches title,state,tracker-status,tracker,files
|
||||||
|
"""
|
||||||
all_torrents = component.get("TorrentManager").torrents
|
all_torrents = component.get("TorrentManager").torrents
|
||||||
#filter:
|
#filter:
|
||||||
for keyword in keywords:
|
found = False
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
torrent = all_torrents[torrent_id]
|
torrent = all_torrents[torrent_id]
|
||||||
if keyword in torrent.filename.lower():
|
if keyword in torrent.filename.lower():
|
||||||
yield torrent_id
|
yield torrent_id
|
||||||
#i want to find broken torrents.
|
elif keyword in torrent.state.lower():
|
||||||
|
yield torrent_id
|
||||||
|
elif torrent.trackers and keyword in torrent.trackers[0]["url"]:
|
||||||
|
yield torrent_id
|
||||||
|
elif keyword in torrent_id:
|
||||||
|
yield torrent_id
|
||||||
|
#i want to find broken torrents (search on "error", or "unregistered")
|
||||||
elif keyword in torrent.tracker_status.lower():
|
elif keyword in torrent.tracker_status.lower():
|
||||||
yield torrent_id
|
yield torrent_id
|
||||||
|
else:
|
||||||
|
for t_file in torrent.get_files():
|
||||||
|
if keyword in t_file["path"].lower():
|
||||||
|
yield torrent_id
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
class FilterManager(component.Component):
|
class FilterManager(component.Component):
|
||||||
|
@ -61,7 +85,7 @@ class FilterManager(component.Component):
|
||||||
self.core = core
|
self.core = core
|
||||||
self.torrents = core.torrents
|
self.torrents = core.torrents
|
||||||
self.registered_filters = {}
|
self.registered_filters = {}
|
||||||
self.register_filter("keyword", filter_keyword)
|
self.register_filter("keyword", filter_keywords)
|
||||||
self.tree_fields = {}
|
self.tree_fields = {}
|
||||||
|
|
||||||
self.register_tree_field("state", self._init_state_tree)
|
self.register_tree_field("state", self._init_state_tree)
|
||||||
|
|
Loading…
Reference in New Issue