Plugin Creation - DevanWolf/YTPPlusPlus GitHub Wiki

YTP++ v2.0 and above support plugins, which are in the form of *.bat files. Plugins can be used as extra effects within the software without the need to rebuild the software, and they are easily shareable too. One creative use of plugins would be to use them to execute external applications to generate video or audio effects.

Getting started

Plugins must always define the variables beforehand, especially since there are more than 9 variables rendering the calling of %10 and above useless. The usual way to start off a plugin batch file would be as follows:

@ECHO OFF
SET VIDEO=%1
SET WIDTH=%2
SET HEIGHT=%3
SET TEMP=%4
SET FFMPEG=%5
SET FFPROBE=%6
SET MAGICK=%7
SET RESOURCES=%8
SET SOUNDS=%9
SHIFT
SET SOURCES=%9
SHIFT
SET MUSIC=%9

As you can see, every variable is set as what it is supposed to be defined as by YTP++. The batch is required to SHIFT the 10th and 11th variable in order to save the variable, however. You are not required to use every variable but they are all provided to give more functionality to plugins.

A good mannerism to be used in making plugins is to avoid the execution of them outside of YTP++. This can be done with the following statement:

IF "%MUSIC%"=="" (
	EHCO This is a YTP++ plugin, it may not be executed outside of the application.
	PAUSE
	EXIT /B
)

This statement will check the last variable to see if it's defined, and if it's not defined it will output the message warning a possible end user. This makes it more accessible, especially to those that come across the plugin without prior knowledge of the use for it.

Creating a temporary video

A plugin should replace the video given to it (%VIDEO%) with an edited version of it. You cannot directly edit a video and subsequently replace it with most use cases, so a workaround is needed: IF EXIST %TEMP%temp.mp4 DEL /F %TEMP%temp.mp4 REN %VIDEO% temp.mp4 This code block will delete the last temporary video that exists in the defined YTP++ temporary file directory and replace it with the video then subsequently delete the original video. It is necessary to re-create the video file in any manner as long as it is the same file as %VIDEO%.

Example plugin An example plugin is provided with version 2 and above of the software, however it is also provided here for ease of use.

::YTP++ Example Plugin v1.1
::Written by LimeQuartz, improved by Devan Wolf
@ECHO OFF

::Set variables
SET VIDEO=%1
::SET WIDTH=%2
::SET HEIGHT=%3
SET TEMP=%4
SET FFMPEG=%5
::SET FFPROBE=%6
::SET MAGICK=%7
::SET RESOURCES=%8
SET SOUNDS=%9
SHIFT
::SET SOURCES=%9
SHIFT
SET MUSIC=%9

::Error message
IF "%MUSIC%"=="" (
	ECHO This is a YTP++ plugin, it may not be executed outside of the application.
	PAUSE
	EXIT /B
)

::Rename video to a temporary file
IF EXIST %TEMP%temp.mp4 DEL /F %TEMP%temp.mp4
REN %VIDEO% temp.mp4

::Get random SFX
PUSHD %SOUNDS%
FOR /F "Delims=" %%A IN ('powershell -Nop -C "(Get-ChildItem * -R -File -Incl *.mp3|Get-Random).FullName"') DO SET SFX=%%A
POPD

::Execute FFMPEG
%FFMPEG% -i "%TEMP%temp.mp4" -i "%SFX%" -c:v copy -filter_complex "[1:a]apad[A];[0:a][A]amerge[out]" -ar 44100 -ac 2 -map 0:v -map [out] -y "%VIDEO%"

IF EXIST %TEMP%temp.mp4 DEL /F %TEMP%temp.mp4

This example plugin will grab a random sound effect and merge it with the video's audio, similar to the "Random Sound > Keep OG Sound" effect.

Distribution of plugins

A plugin must be added to the plugins/ directory in YTP++, and this cannot be changed as the folder is checked every time the settings are reset (done on load as well). You may distribute plugins however and where ever you'd like, but verified plugins may be found only on the YTP+ Hub Discord.

A warning call

Please be aware that YTP++ has no mind in what is a real plugin batch and what isn't. Any non-verified plugins have the potential to be malicious, be on the look out for the malicious use of plugins as there is a possibility that a plugin can be harmful. Remember to NEVER start YTP++ as an administrator.