Run External Program on Torrent Completion

Windows specific questions, problems.
Post Reply
yaoj

Run External Program on Torrent Completion

Post by yaoj »

Hello everyone,

I have been using qbittorrent for a while now and it has been working great. Good job!
The only thing Im missing is a popup that tells you that your torrent finished downloading.
Being a programmer myself I decided to create a small app that takes arguments and displays a tooltip in the notification area.
However.. I can not get the "Run an external program on torrent completion" feature to work.

What is the correct syntax for this?
Lets say I want to start "C:/temp/file.exe"

If I wanted to add an argument to that, is that possible?
Best case scenario is "C:/temp/file.exe" - %f %n


Grateful for any help

regards,
yaoj
loki

Re: Run External Program on Torrent Completion

Post by loki »

Maybe this? http://qbforums.shiki.hu/index.php?topi ... 69#msg4769

It might be a better option to request added feature or if you have code to contribute.
https://github.com/qbittorrent/qBittorr ... state=open
(I think that's the page)
yaoj

Re: Run External Program on Torrent Completion

Post by yaoj »

aye, that works but only with .bat files. I guess using that batch file to start another program is good enough of a solution.

thanks for the the reply.

If anyone is interested I could upload the source of my .bat file and the very small java app it starts? It's just to display a tooltip when a download finishes
grimacester

Re: Run External Program on Torrent Completion

Post by grimacester »

I am interested.

I have expanded on my earlier .bat file and wanted to get it out there [below].

It first checks to see if a torrent is coming from a specific site.  Qbit RSS is setup to download from this site.  Qbit RSS adds a label to the torrent.  Qbit adds directory structure to the torrent when complete, but feeds the DIR path to the bat file without that added folder structure.  The bat file checks and makes sure the file is in the proper place, thus confirming it is from that site.  It then looks at the filetype and determines what to do.  If need be it re-encodes it.  In the end it sends and email to a drupal server i have setup.  that server posts the email to a blog.  Thus i have a little site where i can watch my stuff from anywhere.

My most recent problem is that it does not launch the FFMPEG calls seen below, it does not even log an error off the first FFMPEG run like it is supposed to.  I have had enough problems with using bat files called from Qbit i am considering giving it up and am curious what you have done.





@echo off

set logloc="C:\location\of\log\testing.log"

echo ***** >> %logloc%
echo Run on %date% at %time% >> %logloc%


:: BASIC VAR SETUP SECTION

echo %1 >> %logloc%
echo %2 >> %logloc%

:: this will rip the path out of the path&file input
set newsave=%~dp1
:: this will reverse the slashes for windows use.
set newsave=%newsave:/=\%
:: my labels coming from Qbittorrent are tvt so here we have to write them in because qbit sends the data without it.  but this is good for me so i can tell if it is from somewhere specific or not.
set newsave=%newsave:TV=tvt\TV%
echo "this is the newsave: %newsave%" >> %logloc%

set torname=%~2
echo "this is the torname: %torname%" >> %logloc%

::recording the time for reporting in email
set findowntime="Download Completed @%time% on %date%."

::make a pretty title for the emails/website
set emailtitlevar=%torname%
::censored the rest

:: CHECKING SECTION

::this will check if the file is from RSS APPLIES A LABEL THIS CHECKS THAT, if not exit
::QBittorrent is setup to download from RSS, RSS automatically applies a label and then that label is added to the folder extension.  Thus i just have to see if the file exists to know if it is from that RSS.  the folder extension was added to %newsave% earlier.
echo %newsave%%torname% >> %logloc%
IF EXIST "%newsave%%torname%" GOTO ContinueA
echo **this file is not from RSS SITE, going to exit** >> %logloc%
GOTO exit
:ContinueA

::this checks that the file is an mp4 file, if so it does not run ffmpeg on it.
set torextension=%torname:~-3%
echo "this is the torextension: %torextension%" >> %logloc%
IF mp4==%torextension% GOTO alreadymp4
echo **this file does not have an mp4 extension, checking next** >> %logloc%

::this checks that the file is an mkv file, if so that it runs ffmpeg on it.
IF mkv==%torextension% GOTO ffmpeg
echo **this file does not have an mkv extension, going to exit** >> %logloc%
GOTO exit

::HANDLING SECTION

:alreadymp4

echo "entering alreadymp4 section" >> %logloc%

:: I am just setting the same variables used in ffmpeg for consistency sake.
set encodepath=%newsave%
echo "encode path is: %encodepath%" >> %logloc%
set encodename=%torname%
echo "encode name is: %encodename%" >> %logloc%

:: this will set the href path
set hreffullpath=%encodepath:REWRITE FOLDER TO WEBSITE FORMAT%
set hreffullpath=%hreffullpath%%encodename%
set hreffullpath=%hreffullpath:\=/%
echo "the hreffullpath is: %hreffullpath%" >> %logloc%

GOTO sendemailalreadymp4


:ffmpeg

echo "entering ffmpeg section" >> %logloc%

:: this will set the save-path for ffmpeg
set encodepath=%newsave:\TV\=\Encoded\%
echo "the encodepath is: %encodepath%" >> %logloc%
:: this will change the mkv in the torrent name to the mp4 for the encode save name
set encodename=%torname:mkv=mp4%
echo "the encodename is: %encodename%" >> %logloc%
:: this adds a .small for the second encode
set encode2name=%torname:mkv=small.mp4%
echo "the encode2name is: %encode2name%" >> %logloc%

:: this will set the href for files after they have encoded
set hreffullpath=%encodepath:SEE ABOVE%
set hreffullpath=%hreffullpath%%encodename%
set hreffullpath=%hreffullpath:\=/%
echo "the hreffullpath is: %hreffullpath%" >> %logloc%
set href2fullpath=%hreffullpath:mp4=small.mp4%
echo "the href2fullpath is: %href2fullpath%" >> %logloc%

::HIGH SETTINGS FFMPEG
:: first pass ffmpeg high settings
ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile high -preset slow -b:v 2000k -maxrate 2500k -bufsize 4000k -vf scale=iw:-1 -threads 2 -pass 1 -an -f mp4 NUL >> %logloc%
echo "first videocommand high: ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile high -preset slow -b:v 2000k -maxrate 2500k -bufsize 4000k -vf scale=iw:-1 -threads 2 -pass 1 -an -f mp4 NUL" >> %logloc%
set finenc1time="Encode 1 Completed @%time% on %date%."

:: second pass ffmpeg high settings
ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile high -preset slow -me_method umh -b:v 2000k -maxrate 2500k -bufsize 4000k -vf scale=iw:-1 -threads 2 -pass 2 -acodec libvo_aacenc -ac 2 -b:a 196k -f mp4 "%encodepath%%encodename%"
echo "second videocommand high: ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile high -preset slow -me_method umh -b:v 2000k -maxrate 2500k -bufsize 4000k -vf scale=iw:-1 -threads 2 -pass 2 -acodec libvo_aacenc -ac 2 -b:a 196k -f mp4 "%encodepath%%encodename%"" >> %logloc%
set finenc2time="Encode 2 Completed @%time% on %date%."

::LOW SETTINGS FFMPEG
:: first pass ffmpeg low settings
ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile baseline -preset slow -b:v 1400k -maxrate 1700k -bufsize 1000k -vf scale=iw*.75:-1 -threads 2 -pass 1 -an -f mp4 NUL
echo "first videocommand low: ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile baseline -preset slow -b:v 1400k -maxrate 1600k -bufsize 1000k -vf scale=iw*.75:-1 -threads 2 -pass 1 -an -f mp4 NUL" >> %logloc%
set finenc3time="Encode 3 Completed @%time% on %date%."

:: second pass ffmpeg low settings
ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile baseline -preset slow -me_method umh -b:v 1400k -maxrate 1700k -bufsize 1000k -vf scale=iw*.75:-1 -threads 2 -pass 2 -acodec libvo_aacenc -ac 2 -b:a 128k -f mp4 "%encodepath%%encode2name%"
echo "second videocommand low: ffmpeg -i "%newsave%%torname%" -y -vcodec libx264 -vprofile baseline -preset slow -me_method umh -b:v 1400k -maxrate 1600k -bufsize 1000k -vf scale=iw*.75:-1 -threads 2 -pass 2 -acodec libvo_aacenc -ac 2 -b:a 128k -f mp4 "%encodepath%%encode2name%"" >> %logloc%
set finenc4time="Encode 4 Completed @%time% on %date%."

GOTO sendmailencode


::MAIL SECTION
:sendemailalreadymp4

echo "entering sendmailalreadymp4 section" >> %logloc%

:: SENDING EMAIL
:: -u is the subject -m is the body
set mailcommand=sendemail -s FULL DOMAIN NAME OF STMP SERVER:25 -f ANY FROM ADDRESS -t ANY TO ADDRESS -u "Added: %emailtitlevar%." -m "%torname% is saved\n@: %newsave%\n%findowntime%\n<a href="%hreffullpath%">Watch Here</a>"
%mailcommand% >> %logloc%
echo this is the email command text:%mailcommand% >> %logloc%

GOTO exit

:sendmailencode

echo "entering sendmailencode section" >> %logloc%

:: SENDING EMAIL
:: -u is the subject -m is the body
set mailcommand=sendemail -s REFER ABOVE:25 -f REFER ABOVE -t REFER ABOVE -u "Added: %emailtitlevar%." -m "%torname% is saved\n@: %newsave%\n%findowntime%\n%finenc1time%\n%finenc2time%\n%finenc3time%\n%finenc4time%\nWatch Here: <a href="%hreffullpath%">High Quality</a> <a href="%href2fullpath%">Low (&Mobile) Quality</a>"
%mailcommand% >> %logloc%
echo this is the email command text:%mailcommand% >> %logloc%

GOTO exit

:exit

echo ***** >> %logloc%

exit
grimacester

Re: Run External Program on Torrent Completion

Post by grimacester »

if i run the batch file manually it works fine.  i even added a hosts command to be sure.  still nothing, qbittorrent will not launch ffmpeg, though it launches send mail which is in the same folder... why?
yaoj

Re: Run External Program on Torrent Completion

Post by yaoj »

Hey grim,

The bat file and the application themselves are pretty simple but you should be able to build upon that concept. The reason I chose to do a java app is just because I had netbeans installed on that computer at that time and it is very easy to display a notification message with little code.

My guess is that if you use the bat to start an executable, that executable can then do the other things you want to do in your bat file.

my batch:

@echo off
start c:\temp\np.jar qBittorrent "A download has finished downloading"

np being the name of the executable.
Post Reply