Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
levic92 authored and levic92 committed Sep 27, 2017
1 parent 60968f9 commit c25b4a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ In place extraction code from: https://github.com/cvarta/deluge-extractor/
```
#!/bin/bash
curl -c cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "auth.login", "params": [""], "id": 1}' http://127.0.0.1:8112/json
json=$(curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "web.update_ui", "params": [["name", "is_finished"], {"label": "test"}], "id": 1}' http://127.0.0.1:8112/json)
json=$(curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "web.update_ui", "params": [["name", "is_finished", "save_path"], {"label": "tv"}], "id": 1}' http://127.0.0.1:8112/json)
rm cookies.txt
echo $json
```
27 changes: 17 additions & 10 deletions lcextractor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ def _on_torrent_finished(self, torrent_id):
tid_status = tid.get_status(["save_path", "name"])

if self.config["sonarr_radarr_support"]:
log.info("EXTRACTOR: Setting is_finished to false: %s", tid_status["name"])
# set is_finished to False so Sonarr and Radarr won't process download
tid.is_finished = False

# keep track of total extraction jobs for torrent... store in list so it is mutable. index 0 = total, index 1 = complete
# keep track of total extraction jobs for torrent... store in list so it is mutable. index 0 = total, index 1 = complete count
extraction_count = [0, 0]

files = tid.get_files()
Expand All @@ -165,14 +166,18 @@ def _on_torrent_finished(self, torrent_id):

# Get the destination path
dest = os.path.normpath(self.config["extract_path"])
if self.config["use_name_folder"]:
dest = os.path.join(dest, tid_status["name"])
# need to make sure torrent has a parent directory that matches name.... occasionally name is actually just the file
name_dest = os.path.join(dest, tid_status["name"])
if self.config["use_name_folder"] and os.path.isdir(name_dest):
dest = name_dest

# Override destination if in_place_extraction is set
if self.config["in_place_extraction"]:
dest = tid_status["save_path"]
if self.config["use_name_folder"]:
dest = os.path.join(dest, tid_status["name"])
name_dest = os.path.join(dest, tid_status["name"])
# need to make sure torrent has a parent directory that matches name.... occasionally name is actually just the file
if self.config["use_name_folder"] and os.path.isdir(name_dest):
dest = name_dest

try:
os.makedirs(dest)
Expand All @@ -185,10 +190,11 @@ def on_extract(result, torrent_id, fpath, sonarr_radarr_support, extraction_coun
# increment extraction_count complete
extraction_count[1] += 1
# tmp logging
log.info("EXTRACTOR: 1: extraction count total %d, complete %d", extraction_count[0], extraction_count[1])
log.debug("EXTRACTOR: 1: extraction count total %d, complete %d", extraction_count[0], extraction_count[1])

# if sonarr_radarr_support is enabled and we have extracted all files
if sonarr_radarr_support and extraction_count[0] == extraction_count[1]:
log.info("EXTRACTOR: Setting is_finished to true: %s", tid_status["name"])
tid = component.get("TorrentManager").torrents[torrent_id]
# set is_finished back to True
tid.is_finished = True
Expand All @@ -202,16 +208,17 @@ def on_extract(result, torrent_id, fpath, sonarr_radarr_support, extraction_coun
# increment extraction_count
extraction_count[0] += 1
# tmp logging
log.info("EXTRACTOR: 0: extraction count total %d, complete %d", extraction_count[0], extraction_count[1])
log.debug("EXTRACTOR: 0: extraction count total %d, complete %d", extraction_count[0], extraction_count[1])

# Run the command and add callback.
log.debug("EXTRACTOR: Extracting %s from %s with %s %s to %s", fpath, torrent_id, cmd[0], cmd[1], dest)
d = getProcessOutputAndValue(cmd[0], cmd[1].split() + [str(fpath)], os.environ, str(dest))
d.addCallback(on_extract, torrent_id, fpath, self.config["sonarr_radarr_support"], extraction_count)

# can't do this here because extraction uses callbacks
# set back to True
# tid.is_finished = True
if extraction_count[0] == 0:
log.info("EXTRACTOR: Setting is_finished to true: %s", tid_status["name"])
# set back to true since there are no files to extract
tid.is_finished = True

@export
def set_config(self, config):
Expand Down
2 changes: 1 addition & 1 deletion lcextractor/data/lcextractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Deluge.ux.preferences.LCExtractorPage = Ext.extend(Ext.Panel, {
name: 'sonarr_radarr_support',
height: 22,
hideLabel: true,
boxLabel: _('Enable support for Sonarr/Radarr Completed Download Handling (toggle is_finished)')
boxLabel: _('Enable support for Sonarr and Radarr')
});

this.on('show', this.updateConfig, this);
Expand Down
2 changes: 1 addition & 1 deletion lcextractor/data/lcextractor_prefs.glade
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</child>
<child>
<widget class="GtkCheckButton" id="chk_sonarr_radarr_support">
<property name="label" translatable="yes">Enable support for Sonarr/Radarr</property>
<property name="label" translatable="yes">Enable support for Sonarr and Radarr</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
Expand Down

0 comments on commit c25b4a3

Please sign in to comment.