diff --git a/deluge/plugins/label/label/core.py b/deluge/plugins/label/label/core.py index 8e50fab6b..b0e36ea46 100644 --- a/deluge/plugins/label/label/core.py +++ b/deluge/plugins/label/label/core.py @@ -61,7 +61,7 @@ CONFIG_DEFAULTS = { "show_labels":True } -CORE_OPTIONS = ["hide_zero_hits", "gtk_alfa", "show_states", "show_trackers", "show_labels"] +CORE_OPTIONS = ["hide_zero_hits", "gtk_alfa", "show_states", "show_trackers", "show_labels","auto_add","auto_add_trackers"] OPTIONS_DEFAULTS = { "max_download_speed":-1, @@ -76,7 +76,9 @@ OPTIONS_DEFAULTS = { "is_auto_managed":False, "stop_at_ratio":False, "stop_ratio":2.0, - "remove_at_ratio":False + "remove_at_ratio":False, + "auto_add":False, + "auto_add_trackers":[], } NO_LABEL = "No Label" @@ -105,8 +107,30 @@ class Core(CorePluginBase): self.torrent_labels = self.config.get("torrent_labels") self.clean_initial_config() + #todo: register to torrent_added event. log.debug("Label plugin enabled..") + def disable(self): + self.plugin.deregister_status_field("label") + #todo: unregister to torrent_added event. + + def update(self): + pass + + ## Core Event handlers ## + def on_torrent_added(self, alert): + log.debug("on_torrent_added") + # Get the torrent_id + torrent_id = str(alert.handle.info_hash()) + torrent = self.torrents[torrent_id] + + for label_id,options in self.labels.iteritems(): + if options[auto_add]: + if self._match_auto_add(torrent, options): + self.export_set_torrent(torrent_id, label_id) + return + + ## Utils ## def clean_config(self): "remove invalid data from config-file" for torrent_id, label_id in list(self.torrent_labels.iteritems()): @@ -122,8 +146,6 @@ class Core(CorePluginBase): options.update(self.labels[key]) self.labels[key] = options - - def save_config(self): self.clean_config() self.config.save() @@ -138,14 +160,6 @@ class Core(CorePluginBase): if changed: self.config.save() - def disable(self): - # De-register the label field - #self.plugin.deregister_status_field("tracker_host") - self.plugin.deregister_status_field("label") - - def update(self): - pass - ## Filters ## def filter_state(self, torrents, value): @@ -311,6 +325,18 @@ class Core(CorePluginBase): #todo... pass + + def _has_auto_match(self, torrent ,label_options): + "match for auto_add fields" + for tracker_match in label_options["auto_add_trackers"]: + for tracker in torrent.trackers: + log.debug(tracker_match in tracker["url"]) + log.debug((tracker_match , tracker["url"])) + if tracker_match in tracker["url"]: + return True + return False + + def export_set_options(self, label_id, options_dict , apply = False): """update the label options @@ -333,10 +359,18 @@ class Core(CorePluginBase): self.labels[label_id].update(options_dict) + #apply for torrent_id,label in self.torrent_labels.iteritems(): if label_id == label: self._set_torrent_options(torrent_id , label_id) + #auto add + options = self.labels[label_id] + if options["auto_add"]: + for torrent in self.torrents.values(): + if self._has_auto_match(torrent, options): + self.export_set_torrent(torrent_id , label_id) + self.config.save() def export_get_options(self, label_id): @@ -360,7 +394,7 @@ class Core(CorePluginBase): self.clean_config() else: self.torrent_labels[torrent_id] = label_id - self._set_torrent_options(torrent_id, label_id) + self.set_torrent_options(torrent_id, label_id) self.config.save() @@ -379,7 +413,6 @@ class Core(CorePluginBase): self.config.set(key, options[key]) self.config.save() - def _status_get_label(self, torrent_id): return self.torrent_labels.get(torrent_id) or "" diff --git a/deluge/plugins/label/label/data/label_options.glade b/deluge/plugins/label/label/data/label_options.glade index 3e86a3e3d..dc31fc7e3 100644 --- a/deluge/plugins/label/label/data/label_options.glade +++ b/deluge/plugins/label/label/data/label_options.glade @@ -1,6 +1,6 @@ - + 5 @@ -54,41 +54,103 @@ - + True - 2 - 4 - 5 - GTK_FILL + 3 + 4 + GTK_FILL - + True True -1 -1 9999 1 10 10 - True 1 2 - 3 - 4 + 1 + 2 - + True - 0 - Connections: + Kib/s - 3 - 4 + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + -1 -1 9999 1 10 10 + + + 1 + 2 + + + + + + + True + 0 + Upload Slots: + + + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + 0 + Upload Speed: + + + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + Download Speed: + True + + + GTK_FILL + GTK_FILL + + + + + True + Kib/s + + + 2 + 3 + 1 + 2 GTK_FILL GTK_FILL @@ -110,105 +172,43 @@ - - True - Kib/s - - - 2 - 3 - 1 - 2 - GTK_FILL - GTK_FILL - - - - + True 0 - Download Speed: - True + Connections: + 3 + 4 GTK_FILL GTK_FILL - - True - 0 - Upload Speed: - - - 1 - 2 - GTK_FILL - GTK_FILL - - - - - True - 0 - Upload Slots: - - - 2 - 3 - GTK_FILL - GTK_FILL - - - - + True True -1 -1 9999 1 10 10 + True 1 2 + 3 + 4 - + True - Kib/s - 2 - 3 - GTK_FILL - GTK_FILL - - - - - True - True - -1 -1 9999 1 10 10 - - - 1 2 - 1 - 2 - - - - - - - True - - - 3 - 4 - GTK_FILL + 4 + 5 + GTK_FILL @@ -269,29 +269,42 @@ - + True - 2 - 3 - 4 - GTK_FILL + 2 + 3 + 1 + 2 + GTK_FILL - + True True - 2 1 100 1 10 10 - 2 + Auto Managed + 0 + True + + + GTK_FILL + + + + + + True + True + Stop seed at ratio: + 0 + True - 1 - 2 1 2 - + GTK_FILL GTK_FILL @@ -311,43 +324,30 @@ - + True True - Stop seed at ratio: - 0 - True + 2 1 100 1 10 10 + 2 + 1 + 2 1 2 - GTK_FILL + GTK_FILL - + True - True - Auto Managed - 0 - True + 2 + 3 + 4 GTK_FILL - - - - - - True - - - 2 - 3 - 1 - 2 - GTK_FILL @@ -397,13 +397,15 @@ 3 2 - + True + warning : not effective yet 2 - 1 - 2 + 2 + 3 + GTK_FILL @@ -416,15 +418,13 @@ - + True - warning : not effective yet 2 - 2 - 3 - GTK_FILL + 1 + 2 @@ -472,7 +472,7 @@ True - + True True tracker1.org @@ -497,9 +497,8 @@ this doesn't do anything yet.. - + True - False True Automatically apply label: 0 diff --git a/deluge/plugins/label/label/gtkui/sidebar.py b/deluge/plugins/label/label/gtkui/sidebar.py index 2383c9aeb..eabfc61f4 100644 --- a/deluge/plugins/label/label/gtkui/sidebar.py +++ b/deluge/plugins/label/label/gtkui/sidebar.py @@ -129,13 +129,14 @@ class AddDialog(object): class OptionsDialog(object): - spin_ids = ["max_download_speed","max_upload_speed","max_upload_slots","max_connections","stop_ratio"] - chk_ids = ["apply_max","apply_queue","stop_at_ratio","apply_queue","remove_at_ratio","move_completed","is_auto_managed"] + spin_ids = ["max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections", "stop_ratio"] + chk_ids = ["apply_max", "apply_queue", "stop_at_ratio", "apply_queue", "remove_at_ratio", "move_completed", "is_auto_managed", "auto_add"] sensitive_groups = { #keys must be checkboxes , value-list is to be enabled on checked. - "apply_max": ["max_download_speed","max_upload_speed","max_upload_slots","max_connections"], - "apply_queue":["is_auto_managed","remove_at_ratio","stop_at_ratio","stop_ratio"], + "apply_max": ["max_download_speed", "max_upload_speed", "max_upload_slots", "max_connections"], + "apply_queue":["is_auto_managed", "remove_at_ratio", "stop_at_ratio", "stop_ratio"], #"stop_at_ratio":["stop_at_ratio","remove_at_ratio"], #nested from apply_queue, will probably cause bugs. - "move_completed":["move_completed_path"] + "move_completed":["move_completed_path"], + "auto_add":["auto_add_trackers"] } def __init__(self): @@ -166,8 +167,11 @@ class OptionsDialog(object): self.glade.get_widget(id).set_value(options[id]) for id in self.chk_ids: self.glade.get_widget(id).set_active(bool(options[id])) + self.glade.get_widget("move_completed_path").set_filename(options["move_completed_path"]) + self.glade.get_widget("auto_add_trackers").get_buffer().set_text("\n".join(options["auto_add_trackers"])) + self.apply_sensitivity() def on_ok(self, event=None): @@ -178,9 +182,13 @@ class OptionsDialog(object): options[id] = self.glade.get_widget(id).get_value() for id in self.chk_ids: options[id] = self.glade.get_widget(id).get_active() + options["move_completed_path"] = self.glade.get_widget("move_completed_path").get_filename() + buff = self.glade.get_widget("auto_add_trackers").get_buffer() #sometimes I hate gtk... + tracker_lst = buff.get_text(buff.get_start_iter(), buff.get_end_iter()).strip().split("\n") + options["auto_add_trackers"] = [x for x in tracker_lst if x] #filter out empty lines. - + log.debug(options) aclient.label_set_options(None, self.label, options) self.dialog.destroy()