| 117 | |
| 118 | === Extract archives script === |
| 119 | |
| 120 | This script will search for archives in downloaded content and extract them. Actions are logged as entries in syslog. |
| 121 | This script can be easily extended to support more compression and archive formats. |
| 122 | |
| 123 | {{{ |
| 124 | #!/bin/bash |
| 125 | formats=(zip rar) |
| 126 | commands=([zip]="unzip -u" [rar]="unrar -o- e") |
| 127 | extraction_subdir='exracted' |
| 128 | |
| 129 | torrentid=$1 |
| 130 | torrentname=$2 |
| 131 | torrentpath=$3 |
| 132 | |
| 133 | log() |
| 134 | { |
| 135 | logger -t deluge-extractarchives "$@" |
| 136 | } |
| 137 | |
| 138 | log "Torrent complete: $@" |
| 139 | cd "${torrentpath}" |
| 140 | for format in "${formats[@]}"; do |
| 141 | while read file; do |
| 142 | log "Extracting \"$file\"" |
| 143 | cd $(dirname "$file") |
| 144 | file=$(basename "$file") |
| 145 | # if extraction_subdir is not empty, extract to subdirectory |
| 146 | if [[ ! -z "$extraction_subdir" ]] ; then |
| 147 | mkdir "$extraction_subdir" |
| 148 | cd "$extraction_subdir" |
| 149 | file="../$file" |
| 150 | fi |
| 151 | ${commands[$format]} "$file" |
| 152 | done < <(find "$torrentpath/$torrentname" -iname "*.${format}" ) |
| 153 | done |
| 154 | }}} |