auto-add on tracker

This commit is contained in:
Martijn Voncken 2008-08-05 20:11:00 +00:00
parent 4c2ecbd29d
commit b20add89e4
3 changed files with 194 additions and 154 deletions

View file

@ -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 ""

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Mon Aug 4 20:48:19 2008 -->
<!--Generated with glade3 3.4.5 on Tue Aug 5 21:50:51 2008 -->
<glade-interface>
<widget class="GtkDialog" id="dlg_label_options">
<property name="border_width">5</property>
@ -54,41 +54,103 @@
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="label14">
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_connections">
<widget class="GtkSpinButton" id="max_upload_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<widget class="GtkLabel" id="label24">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Connections:</property>
<property name="label" translatable="yes">Kib/s</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_download_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Slots: </property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Speed:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Download Speed:</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
@ -110,105 +172,43 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Download Speed:</property>
<property name="use_markup">True</property>
<property name="label" translatable="yes">Connections:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Speed:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Upload Slots: </property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_download_speed">
<widget class="GtkSpinButton" id="max_connections">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label24">
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="label" translatable="yes">Kib/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="max_upload_speed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">-1 -1 9999 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="y_options">GTK_FILL</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>
@ -269,29 +269,42 @@
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="label13">
<widget class="GtkLabel" id="label16">
<property name="visible">True</property>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="stop_ratio">
<widget class="GtkCheckButton" id="is_auto_managed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">2 1 100 1 10 10</property>
<property name="digits">2</property>
<property name="label" translatable="yes">Auto Managed</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="stop_at_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop seed at ratio:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
@ -311,43 +324,30 @@
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="stop_at_ratio">
<widget class="GtkSpinButton" id="stop_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop seed at ratio:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
<property name="adjustment">2 1 100 1 10 10</property>
<property name="digits">2</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="x_options"></property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="is_auto_managed">
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Auto Managed</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label16">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</widget>
@ -397,13 +397,15 @@
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkLabel" id="label19">
<widget class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="label" translatable="yes">warning : not effective yet</property>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@ -416,15 +418,13 @@
</packing>
</child>
<child>
<widget class="GtkLabel" id="label11">
<widget class="GtkLabel" id="label19">
<property name="visible">True</property>
<property name="label" translatable="yes">warning : not effective yet</property>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options">GTK_FILL</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget>
@ -472,7 +472,7 @@
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<child>
<widget class="GtkTextView" id="trackers">
<widget class="GtkTextView" id="auto_add_trackers">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">tracker1.org
@ -497,9 +497,8 @@ this doesn't do anything yet..
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<widget class="GtkCheckButton" id="auto_add">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Automatically apply label:</property>
<property name="response_id">0</property>

View file

@ -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()