Custom Post Processing via a batch file

I have read https://github.com/Sonarr/Sonarr/wiki/Custom-Post-Processing-Scripts but can’t seem to get it to fire correctly for me, I am having Sonarr import some of my shows recorded via my DVR that is working fine, once they are imported by Sonar I would like to run my comskip program on them via a batch file. The batch file is firing according to my log files, but the EpisodeFile_Path parameter doesn’t seem to be passing correctly. Is there a way to just have that appended to the end of the script path or do I need to look into re-doing this in Python?

Are you getting it from the environment variable? It will be set as sonarr_episodefile_path. You could also try setting the executable as cmd.exe and the arguments to /c C:\Path\To\batch.bat, though I’m not sure thats required.

I am trying to, but I guess I don’t understand how to pass them as a parameter into a batch file. The file that I created currently works when called like

C:\Scripts\ComSkip.bat “C:\Recordings\MyShow.ts”

It then makes sure the file is the correct format and hasn’t already been checked for commercials before sending it to the comskip program.

My attempts so far have resulted in no parameter(the file location in this case) being passed to the bat file.

No parameters are passed directly to the batch file, the parameters are set as environment variables, which means we can send them without having to escape them and add as many as we want without changing the number of parameters that are sent.

https://support.microsoft.com/en-us/kb/121170

I’m having a real hard time too. Does Sonarr need to Run as a service for this to work?

Maybe you could provide an example batch file?

I don’t know if you need to be running as a service, in my installation I am though.
As @markus101 said in the first reply I needed to set the Executable as cmd.exe and the arguments to /c C:\Path\To\batch.bat

Here is my bat file, it is probably overly complicated, but it does work.

@ECHO OFF
@setlocal EnableDelayedExpansion

SET logfile=C:\Logs\Sonarr.log
SET apppath=C:\ComSkip\comskip.exe
SET hidepath=C:\ComSkip\HideRun.exe

CALL :CheckPath "%sonarr_episodefile_path%"
REM ****check if the file exists
Call :CheckExist	
REM ****the file exists, make sure it is a .ts file
CALL :CheckExtension "%sonarr_episodefile_path%"
REM ****it is, launch comskip on it
ECHO ** Comskip is running >> %logfile%
%hidepath% %apppath% "%sonarr_episodefile_path%"
ECHO *** Comskip has finished running >> %logfile%
GOTO End1

:No1
REM ****oops the path parameter doesnt exist
ECHO %date%,%time% No file was specified >> %logfile%
GOTO End1

:CheckPath
	IF %1 == "" (
		GOTO NoPath
	) ELSE (
		ECHO ******************** %DATE%,%TIME% ComSkip.bat is starting on file %1 >> %logfile%
		EXIT /b
	)

:CheckExist
	IF EXIST "%sonarr_episodefile_path%" (
		EXIT /b
	) ELSE (
		GOTO NoExist
	)

:CheckExtension
	SET Extension=%~x1
	ECHO "%Extension%" >> %logfile%
	IF "%~x1"==".ts" (
		EXIT /b
	) ELSE (
		GOTO WrongExtension
	)

:NoPath
REM **** sonarr_episodefile_path is blank
	ECHO ********** sonarr_episodefile_path is blank >> %logfile%
	GOTO End1	

:NoExist
REM **** the file doesnt exist
	ECHO ********** file doesnt exist for %sonarr_episodefile_path% >> %logfile%
	GOTO End1

:WrongExtension
REM ****it isnt a ts file so ignore it 
	ECHO *********** %sonarr_episodefile_path% isnt a .ts file >> %logfile%
	GOTO End1

:End1
echo ********************** %date%,%time% Comskip.bat is complete. >> %logfile%
GOTO :EOF

Awesome, thanks!

I’ll study your batch file and I’m sure I’ll come up with a good one of my own.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.