Distributed Encoding across Multiple Machines

distributedencoding
tweaking
documentation

(Administrator) #1

###Thanks to JoshDi for putting this together:

I created a BAT file script to help coordinate distributed MCEBuddy conversions across my two machines: HTPC and HTPC-Bedroom (Bedroom)

I run the following script every 5 minutes on both machines via task manager. No schedule is set (start stop) in MCEBuddy - the script handles the starting and stopping of MCEBuddy Conversions.

Essentially the script does the following:

  • Checks to see if Media Center or Kodi is running locally. If so, stop running MCEBuddy on the local machine
  • If Media Center or Kodi are NOT running locally on HTPC, run MCEBuddy conversions on HTPC and stop conversions on Bedroom if MCEBuddy is converting files.
  • If Media Center or Kodi are NOT Running locally on Bedroom and MCEBuddy is not already running conversions on HTPC, start MCEBuddy conversions on Bedroom

In summary, if Kodi or Media Center are running the script assumes that the machine is being used and to not run conversions on that machine. The script will then try to run conversions first on HTPC and then Bedroom - ensuring that MCEBuddy conversions are not running on both machines.

You will need to change the following in the script below:

  • 192.168.1.50 is the IP of my HTPC
  • 192.168.1.60 is the IP of my Bedroom
  • The two IF “%SERVER%” lines need to be changed to the respective hostnames of the two machines
  • Please also ensure that C:\temp\ is writable, if not please change the paths below.
@echo off&setlocal
SETLOCAL EnableExtensions

REM ***************************************
REM ***************************************
REM ***************************************
REM START VARIABLES

del /Q /F C:\Temp\MCEBuddyControlLastRun.txt
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo %mydate%_%mytime% > C:\Temp\MCEBuddyControlLastRun.txt

set SERVER=%computername%
set EXE1=Kodi.exe
set EXE2=ehshell.exe
set LOGFILE=C:\Temp\mcestatus.log
SET statusFileHTPC=C:\Temp\HTPC.mcestatus
SET statusFileBEDROOM=C:\Temp\BEDROOM.mcestatus

REM END VARIABLES
REM ***************************************
REM ***************************************
REM ***************************************
REM echo %SERVER%

IF "%SERVER%"=="HTPC-PC" GOTO HTPC
IF "%SERVER%"=="HTPC-BEDROOM" GOTO BEDROOM

:HTPC
echo Initalizing variables for HTPC  > %LOGFILE%
set IP="192.168.1.50"
REM set CHECK=Z:\Recorded TV\HTPC.mcerunning
REM echo %IP%
REM pause
GOTO STEP1

:BEDROOM
echo Initalizing variables for Bedroom  > %LOGFILE%
set IP="192.168.1.60"
REM set CHECK=Z:\Recorded TV\HTPC.mcerunning
REM echo %IP%
REM pause
GOTO STEP1

:STEP1
REM echo "STEP 1"
REM pause

REM CHECK if BEDROOM is up
ping -n 1 192.168.1.50 > NUL
IF ERRORLEVEL 0 (echo HTPC is up, continue >> %LOGFILE%) ELSE (echo HTPC is NOT up, ENDING >> %LOGFILE% && goto END)

REM CHECK MCEBuddy Run Status
"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=query --action=enginestate --server=192.168.1.50 --port=23332 --quiet > %statusFileHTPC%
"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=query --action=enginestate --server=192.168.1.60 --port=23332 --quiet > %statusFileBEDROOM%

SET /P statusHTPC= < %statusFileHTPC%
SET /P statusBEDROOM= < %statusFileBEDROOM%

del /Q /F %statusFileHTPC%
del /Q /F %statusFileBEDROOM%

echo MCEBuddy HTPC: %statusHTPC% >> %LOGFILE%
echo MCEBuddy Bedroom: %statusBEDROOM% >> %LOGFILE%

REM echo %statusHTPC%
REM echo %statusBEDROOM%
REM if %statusHTPC% == started (echo "HTPC STARTED")
REM if %statusHTPC% == stopped (echo "HTPC STOPPED")
REM if %statusBEDROOM% == started (echo "BEDROOM STARTED")
REM if %statusBEDROOM% == stopped (echo "BEDROOM STOPPED")
REM pause
GOTO STEP2


:STEP2
REM echo "STEP 2"
REM pause
REM CHECK IF KODI or MediaCenter is Running

FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE1%"') DO IF %%x == %EXE1% goto ProcessFound
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE2%"') DO IF %%x == %EXE2% goto ProcessFound

goto ProcessNotFound

:ProcessFound
echo Kodi or MediaCenter is Running  >> %LOGFILE%
REM pause
REM echo %EXE% is running
"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=127.0.0.1 --port=23332 --quiet
"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=127.0.0.1 --port=23332 --quiet
goto END

:ProcessNotFound
echo Kodi or MediaCenter NOT Running  >> %LOGFILE%
REM pause
REM echo %EXE% is not running
IF "%SERVER%"=="HTPC-PC" GOTO CHECKHTPC
IF "%SERVER%"=="HTPC-BEDROOM" GOTO CHECKBEDROOM
goto END

:CHECKHTPC
echo Running MCEBuddy Check for HTPC  >> %LOGFILE%
REM pause
SetLocal EnableDelayedExpansion
if %statusHTPC% == started (
	echo MCEBuddy: HTPC Running  >> %LOGFILE%
	echo MCEBuddy Already Running on HTPC  >> %LOGFILE%
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.50 --port=23332 --quiet
	REM pause
)
EndLocal
SetLocal EnableDelayedExpansion
if %statusHTPC% == conversion_in_progress (
	echo MCEBuddy: HTPC Running  >> %LOGFILE%
	echo MCEBuddy Already Running on HTPC  >> %LOGFILE%
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.50 --port=23332 --quiet
	REM pause
)
EndLocal
SetLocal EnableDelayedExpansion
if %statusHTPC% == stopped (
	echo MCEBuddy: HTPC Stopped  >> %LOGFILE%
	echo Starting MCEBuddy on HTPC  >> %LOGFILE%
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.50 --port=23332 --quiet
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=start --server=192.168.1.50 --port=23332 --quiet
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=start --server=192.168.1.50 --port=23332 --quiet
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.50 --port=23332 --quiet
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.50 --port=23332 --quiet
	REM schtasks /Run /TN "\HTPC\UnlockScreen"
	REM pause
)
EndLocal
REM Stop Bedroom if started
if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
goto END

:CHECKBEDROOM
echo Running MCEBuddy Check for BEDROOM  >> %LOGFILE%
REM pause
SetLocal EnableDelayedExpansion
if %statusHTPC% == started (
	echo MCEBuddy: HTPC Running  >> %LOGFILE%
	echo MCEBuddy Already Running on HTPC  >> %LOGFILE%
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
	if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	REM pause
)
EndLocal
SetLocal EnableDelayedExpansion
if %statusHTPC% == conversion_in_progress (
	echo MCEBuddy: HTPC Running  >> %LOGFILE%
	echo MCEBuddy Already Running on HTPC  >> %LOGFILE%
	"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
	if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == started ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	if %statusBEDROOM% == conversion_in_progress ("C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=stop --server=192.168.1.60 --port=23332 --quiet)
	REM pause
)
EndLocal
SetLocal EnableDelayedExpansion
if %statusHTPC% == stopped (
	if %statusBEDROOM% == started (
		echo MCEBuddy: Bedroom Running  >> %LOGFILE%
		echo MCEBuddy Already Running on Bedroom  >> %LOGFILE%
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		REM pause
	) ELSE IF %statusBEDROOM% == conversion_in_progress (
		echo MCEBuddy: Bedroom Running  >> %LOGFILE%
		echo MCEBuddy Already Running on Bedroom  >> %LOGFILE%
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		REM pause
	) else (
		echo MCEBuddy: Bedroom Stopped  >> %LOGFILE%
		echo Starting MCEBuddy on Bedroom >> %LOGFILE%
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=start --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=start --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		"C:\PROGRA~1\MCEBuddy2x\MCEBuddy.UserCLI.exe" --command=engine --action=rescan --server=192.168.1.60 --port=23332 --quiet
		REM schtasks /Run /TN "\HTPC\UnlockScreen"
		REM pause
	)
)
EndLocal
goto END

:END
:: Exit code 0
Ver > nul
REM pause
EXIT

(Administrator) #2