auto label on add

This commit is contained in:
Martijn Voncken 2008-08-06 15:39:02 +00:00
parent cba7b00f70
commit b4ee52cbdd

View File

@ -108,28 +108,35 @@ class Core(CorePluginBase):
self.clean_initial_config() self.clean_initial_config()
#todo: register to torrent_added event. #todo: register to torrent_added event.
self.plugin.register_hook("post_torrent_add", self.post_torrent_add)
self.plugin.register_hook("post_torrent_remove", self.post_torrent_remove)
log.debug("Label plugin enabled..") log.debug("Label plugin enabled..")
def disable(self): def disable(self):
self.plugin.deregister_status_field("label") self.plugin.deregister_status_field("label")
#todo: unregister to torrent_added event. self.plugin.deregister_hook("post_torrent_add", self.post_torrent_add)
self.plugin.deregister_hook("post_torrent_remove", self.post_torrent_remove)
def update(self): def update(self):
pass pass
## Core Event handlers ## ## Plugin hooks ##
def on_torrent_added(self, alert): def post_torrent_add(self, torrent_id):
log.debug("on_torrent_added") log.debug("post_torrent_add")
# Get the torrent_id
torrent_id = str(alert.handle.info_hash())
torrent = self.torrents[torrent_id] torrent = self.torrents[torrent_id]
for label_id,options in self.labels.iteritems(): for label_id, options in self.labels.iteritems():
if options[auto_add]: if options["auto_add"]:
if self._match_auto_add(torrent, options): if self._has_auto_match(torrent, options):
self.export_set_torrent(torrent_id, label_id) self.export_set_torrent(torrent_id, label_id)
return return
def post_torrent_remove(self, torrent_id):
log.debug("post_torrent_remove")
if torrent_id in self.torrent_labels:
del self.torrent_labels[torrent_id]
## Utils ## ## Utils ##
def clean_config(self): def clean_config(self):
"remove invalid data from config-file" "remove invalid data from config-file"
@ -325,19 +332,14 @@ class Core(CorePluginBase):
#todo... #todo...
pass pass
def _has_auto_match(self, torrent ,label_options): def _has_auto_match(self, torrent ,label_options):
"match for auto_add fields" "match for auto_add fields"
log.debug(111)
for tracker_match in label_options["auto_add_trackers"]: for tracker_match in label_options["auto_add_trackers"]:
log.debug(torrent.trackers)
for tracker in torrent.trackers: for tracker in torrent.trackers:
log.debug((tracker_match , tracker["url"],tracker_match in tracker["url"]))
if tracker_match in tracker["url"]: if tracker_match in tracker["url"]:
return True return True
return False return False
def export_set_options(self, label_id, options_dict , apply = False): def export_set_options(self, label_id, options_dict , apply = False):
"""update the label options """update the label options