This is basically a very simple bash script to dump info upon completion in an html file instead of a log file. The html can then be viewed from anywhere over my LAN
Here is my code:
:addtorrents %torrentid% %torrentname% %torrentpath%
::Copies any MP3 files, any M4A files, and any PDF files (ONLY copies PDFs if MP3 and/or M4A files are found) to the folder D:\autoadd, and adds a line to %userprofile%\Music\deluge-script.log with the date/time of script run
setlocal
set torrentid=%1
set torrentname=%2
set torrentpath=%3
set "log=%userprofile%\Music\deluge-script.log"
set autoadd=D:\autoadd
@echo on
::reset errorlevel
set errorlevel=
cmd /c exit /b 0
echo Download of %torrentname% Completed at %date% %time%: ^<%torrentpath%\%torrentname%^> ^<%torrentid%^> >> "%log%"
pushd %torrentpath%\%torrentname%
call:mktmp filestoadd
call:findmp3 && call:findpdf
call:findm4a && call:findpdf
type %filestoadd%
for /f "tokens=*" %%a in (%filestoadd%) do (copy /b /d /y "%%a" d:\autoadd)
endlocal & del %filestoadd% & exit /b %errorlevel%
:findmp3
2>nul 1>> %filestoadd% dir /b /s *.mp3 && exit /b 0 || exit /b 1
:findm4a
2>nul 1>> %filestoadd% dir /b /s *.m4a && exit /b 0 || exit /b 1
:findpdf
2>nul 1>> %filestoadd% dir /b /s *.pdf && exit /b 0 || exit /b 1
:mktmp (out)tmpfilename
setlocal
pushd %temp%
set tmpfilename=%1
set filename=addtorrents.%tmpfilename%.%random%.tmp
type nul>%filename%
endlocal & set %tmpfilename%=%temp%\%filename%
D:\autoadd is a directory symbolic link* that points to my "Automatically add to iTunes" folder, and Google Music syncs with iTunes. I like to keep the PDFs that come with albums, too.
I didn't work very hard on making the script particularly clean or commenting it very well, but it will get the job done for me
#!/bin/bash
torrentid=$1
torrentname=$2
torrentpath=$3
ssh osmc@osmc_ip_address 'xbmc-send -a "Notification(Deluge: Media ready,' $torrentname , 5000 , "/path/to/image" ')"'
Of course this requires that the machine running deluged have ssh access to the machine running xbmc/kodi without having to enter password. This can be achived by creating key pair using
Note that: 5000 is the time to display the notification in milliseconds. /path/to/image is the icon image to display which should be resolvable by xbmc/kodi (I uploaded mine to the home folder in kodi)
Hi! I'am a newbie to the bash-scripting, but I think that my script is nice. This script I use on complete with Execute plugin. Script will check extentions of downloaded files and move torrent data to other location. So we can sort data by type of. Because deluge-console isn't supported mv command, script do it via two steps: first rm command, then add. After re-adding torrent, deluge will recheck data and start seeding again.
#!/bin/bash
script_name=$(basename $0)
torrent_id=$1
torrent_name=$2
torrent_path=$3
# you can use any paths, but check write access before
videos_directory_path="$torrent_path/Видео"
audios_directory_path="$torrent_path/Аудио"
programs_directory_path="$torrent_path/Программы"
# current torrent file: we need to back it up it before use "deluge-console rm ..."
torrent_file="${HOME}/.config/deluge/state/${torrent_id}.torrent"
# torrent backup path name
tmp_file="/tmp/$torrent_id.torrent"
# current full path to downloaded data
data_full_path="$torrent_path/$torrent_name"
log()
{
logger -t "$script_name" "$@"
#echo "$@"
}
# this func will try to execute command, and, if it failure, write messages to system log
run()
{
local result_output
local result_code
local command_text
local whitespace="[[:space:]]"
for i in "$@"
do
if [[ $i =~ $whitespace ]]; then
i=\"$i\"
fi
if [ -n "$command_text" ]; then
command_text="$command_text $i"
else
command_text="$i"
fi
done
result_output=$(eval "$command_text" 2>&1)
result_code=$?
if [ $result_code -ne 0 ]; then
log "$result_output"
fi
return $result_code;
}
#if [ -e "$data_full_path" ] || {[ "$data_full_path" != "$videos_directory_path" ] && [ "$data_full_path" != "$audios_directory_path" ] && [ "$data_full_path" != "$programs_directory_path" ];}; then
if [ -e "$data_full_path" ]; then
log "Обработка $data_full_path [ID: $torrent_id]"
fi
handle_as="none"
if [ -f "$data_full_path" ]; then
run chmod a+rwx "$data_full_path"
#run chown nobody:nogroup "$data_full_path"
# need to modify for case insensitive checking
if [[ $torrent_name == *.mkv || $torrent_name == *.avi || $torrent_name == *.mpg ]]; then
handle_as="video"
elif [[ $torrent_name == *.mp3 || $torrent_name == *.flac ]]; then
handle_as="audio"
elif [[ $torrent_name == *.exe ]]; then
handle_as="program"
fi
fi
if [ -d "$data_full_path" ] && [ "$data_full_path" != "$videos_directory_path" ] && [ "$data_full_path" != "$audios_directory_path" ] && [ "$data_full_path" != "$programs_directory_path" ]; then
run chmod -R a+rwxX "$data_full_path"
#run chown -R nobody:nogroup "$data_full_path"
if [[ -n $(find "$data_full_path" -iname "*.exe") ]]; then
handle_as="program"
elif [[ -n $(find "$data_full_path" -iname "*.mkv" -or -iname "VIDEO_TS" -or -iname "*.avi" -or -iname "BDMV" -or -iname "*.mpg") ]]; then
handle_as="video"
elif [[ -n $(find "$data_full_path" -iname "*.mp3" -or -iname "*.flac") ]]; then
handle_as="audio"
fi
fi
if [ $handle_as != "none" ]; then
if [ $handle_as == "video" ]; then
destination_directory_path="$videos_directory_path"
elif [ $handle_as == "audio" ]; then
destination_directory_path="$audios_directory_path"
elif [ $handle_as == "program" ]; then
destination_directory_path="$programs_directory_path"
else
exit
fi
if [ ! -d "$destination_directory_path" ]; then
run mkdir "$destination_directory_path"
fi
if [ -d "$destination_directory_path" ] && [ ! -w "$destination_directory_path" ]; then
run chmod a+rwXt "$destination_directory_path"
fi
if [ -f "$torrent_file" ]; then
run cp "$torrent_file" "/tmp"
run deluge-console rm $torrent_id
fi
run mv "$data_full_path" "$destination_directory_path"
if [ $? -eq 0 ]; then
if [ -f "$tmp_file" ] && [ -e "$destination_directory_path" ]; then
run deluge-console add -p "$destination_directory_path" "$tmp_file"
fi
fi
fi
If torrent name is such a "This is the torrent Name", the content of variable $torrentname will be 'This' then $torrentpath/$torrentname will point a non-existent dir and i can't perform any operation on the files contained into the dir "This is the torrent name".
My machine is a Debian Jessie (8.6) and Deluge 1.3.10-3 (installed from apt repo.
Also, something I recently found out, e.g. "$dir/*.mkv" doesn't work in bash scripts, but needs to be like this: "$dir"/*.mkv for content with spaces. ...Wish everyone would just simply follow the nice unix convention of using underscores instead of spaces and lowercase-only - dammit!