Skip to content

Instantly share code, notes, and snippets.

@b-
Last active August 29, 2015 14:22
Show Gist options
  • Save b-/4c8461112e1c4db7c1a9 to your computer and use it in GitHub Desktop.
Save b-/4c8461112e1c4db7c1a9 to your computer and use it in GitHub Desktop.
deluge execute script
: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%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment