Add option to create torrent name sub-folders in extract folder
Fix issue where the plugin would not stop extracting files after being disabled
This commit is contained in:
parent
bdc173cf4b
commit
9c491c13cc
|
@ -48,7 +48,8 @@ import deluge.configmanager
|
|||
from deluge.core.rpcserver import export
|
||||
|
||||
DEFAULT_PREFS = {
|
||||
"extract_path": ""
|
||||
"extract_path": "",
|
||||
"use_name_folder": True
|
||||
}
|
||||
|
||||
# The first format is the source file, the second is the dest path
|
||||
|
@ -69,7 +70,7 @@ class Core(CorePluginBase):
|
|||
component.get("EventManager").register_event_handler("TorrentFinishedEvent", self._on_torrent_finished)
|
||||
|
||||
def disable(self):
|
||||
pass
|
||||
component.get("EventManager").deregister_event_handler("TorrentFinishedEvent", self._on_torrent_finished)
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
@ -97,11 +98,22 @@ class Core(CorePluginBase):
|
|||
|
||||
# Now that we have the cmd, lets run it to extract the files
|
||||
fp = os.path.join(save_path, f["path"])
|
||||
if os.path.exists(self.config["extract_path"]):
|
||||
dest = self.config["extract_path"]
|
||||
else:
|
||||
dest = None
|
||||
|
||||
# Get the destination path
|
||||
dest = self.config["extract_path"]
|
||||
if self.config["use_name_folder"]:
|
||||
name = component.get("TorrentManager")[torrent_id].get_status(["name"])["name"]
|
||||
dest = os.path.join(dest, name)
|
||||
|
||||
# Create the destination folder if it doesn't exist
|
||||
if not os.path.exists(dest):
|
||||
try:
|
||||
os.makedirs(dest)
|
||||
except Exception, e:
|
||||
log.error("Error creating destination folder: %s", e)
|
||||
return
|
||||
|
||||
log.debug("Extracting to %s", dest)
|
||||
def on_extract_success(result, torrent_id):
|
||||
# XXX: Emit an event
|
||||
log.debug("Extract was successful for %s", torrent_id)
|
||||
|
@ -115,14 +127,14 @@ class Core(CorePluginBase):
|
|||
d.addCallback(on_extract_success, torrent_id)
|
||||
d.addErrback(on_extract_failed, torrent_id)
|
||||
|
||||
@export()
|
||||
@export
|
||||
def set_config(self, config):
|
||||
"sets the config dictionary"
|
||||
for key in config.keys():
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
@export()
|
||||
@export
|
||||
def get_config(self):
|
||||
"returns the config dictionary"
|
||||
return self.config.config
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.4.5 on Wed May 6 12:45:11 2009 -->
|
||||
<?xml version="1.0"?>
|
||||
<glade-interface>
|
||||
<!-- interface-requires gtk+ 2.6 -->
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<widget class="GtkWindow" id="window1">
|
||||
<child>
|
||||
<widget class="GtkVBox" id="extractor_prefs_box">
|
||||
|
@ -11,7 +11,7 @@
|
|||
<widget class="GtkFrame" id="frame1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">GTK_SHADOW_NONE</property>
|
||||
<property name="shadow_type">none</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
|
@ -29,6 +29,7 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -36,9 +37,12 @@
|
|||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkFileChooserButton" id="folderchooser_path">
|
||||
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
|
||||
<property name="action">select-folder</property>
|
||||
<property name="title" translatable="yes">Select A Folder</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="entry_path">
|
||||
|
@ -57,6 +61,22 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_use_name">
|
||||
<property name="label" translatable="yes">Create torrent name sub-folder</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="tooltip" translatable="yes">This option will create a sub-folder using the torrent's name within the selected extract folder and put the extracted files there.</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
@ -72,6 +92,9 @@
|
|||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
|
|
|
@ -70,7 +70,8 @@ class GtkUI(GtkPluginBase):
|
|||
path = self.glade.get_widget("entry_path").get_text()
|
||||
|
||||
config = {
|
||||
"extract_path": path
|
||||
"extract_path": path,
|
||||
"use_name_folder": self.glade.get_widget("chk_use_name").get_active()
|
||||
}
|
||||
|
||||
client.extractor.set_config(config)
|
||||
|
@ -88,5 +89,7 @@ class GtkUI(GtkPluginBase):
|
|||
self.glade.get_widget("folderchooser_path").set_current_folder(config["extract_path"])
|
||||
else:
|
||||
self.glade.get_widget("entry_path").set_text(config["extract_path"])
|
||||
|
||||
self.glade.get_widget("chk_use_name").set_active(config["use_name_folder"])
|
||||
|
||||
client.extractor.get_config().addCallback(on_get_config)
|
||||
|
|
Loading…
Reference in New Issue