# Cord Cutting

# Deluge Auto Extract Torrents Settings

1. Create a Deluge directory structure as follows:

**deluge**

**--&gt; incoming** (for in-progress downloads)

**--&gt; complete** (for completed downloads)

**--&gt; torrent** (for manual torrents)

1. Under **Deluge --&gt; Preferences --&gt; Downloads --&gt; Download to** set it to your "incoming" directory from directory structure above
2. Under **Deluge --&gt; Preferences --&gt; Downloads --&gt; Move completed** to set it to your "complete" directory from directory structure above
3. Under **Deluge --&gt; Preferences --&gt; Downloads --&gt; Autoadd .torrent files from** set it to your "torrent" directory from directory structure above (**Figure 1**)

**Figure 1**

[![image-1606852068656.png](https://docs.deeztek.com/uploads/images/gallery/2020-12/scaled-1680-/image-1606852068656.png)](https://docs.deeztek.com/uploads/images/gallery/2020-12/image-1606852068656.png)

1. Under **Deluge --&gt; Preferences --&gt;Plugins** enable the **Execute** plugin
2. Click "**Apply**" and "**Ok**" (**Figure 2**).

**Figure 2**

[![image-1606852086436.png](https://docs.deeztek.com/uploads/images/gallery/2020-12/scaled-1680-/image-1606852086436.png)](https://docs.deeztek.com/uploads/images/gallery/2020-12/image-1606852086436.png)

1. Go back under **Deluge --&gt; Preferences --&gt;Execute** and click the "**Add**" button
2. In the **Add Command** window, select "**Torrent Complete**" in the **Event** dropdown and enter the path to your script in the **Command** input field and then click the **Add** button (**Figure 3**).

**Figure 3**

[![image-1606852103361.png](https://docs.deeztek.com/uploads/images/gallery/2020-12/scaled-1680-/image-1606852103361.png)](https://docs.deeztek.com/uploads/images/gallery/2020-12/image-1606852103361.png)

1. Click the "**Apply**" and then "**Ok**" button (**Figure 4**)

**Figure 4**

[![image-1606852121624.png](https://docs.deeztek.com/uploads/images/gallery/2020-12/scaled-1680-/image-1606852121624.png)](https://docs.deeztek.com/uploads/images/gallery/2020-12/image-1606852121624.png)

1. Create the **extract.sh** script in the path specified on step 9 above above and paste the following the contents of this[<u> script</u>](https://cloud.deeztek.com/index.php/f/1342621).
2. Save the script and make it executable:

```
chmod +x /scripts/extract.sh
```

1. Ensure unrar is installed:

```
sudo apt install unrar
```

# extract.sh

```
#!/bin/bash
formats=(zip rar)
commands=([zip]="unzip -u" [rar]="unrar -o- e")
extraction_subdir=''

torrentid=$1
torrentname=$2
torrentpath=$3

log()
{
    logger -t deluge-extractarchives "$@"
}

log "Torrent complete: $@"
cd "${torrentpath}"
for format in "${formats[@]}"; do
    while read file; do
        log "Extracting \"$file\""
        cd "$(dirname "$file")"
        file=$(basename "$file")
        # if extraction_subdir is not empty, extract to subdirectory
        if [[ ! -z "$extraction_subdir" ]] ; then
            mkdir "$extraction_subdir"
            cd "$extraction_subdir"
            file="../$file"
        fi
        ${commands[$format]} "$file"
    done < <(find "$torrentpath/$torrentname" -iname "*.${format}" )
done

```