Last active
August 27, 2020 19:27
-
-
Save ReenigneArcher/4192dcf36a520fcf58c858b8b800b44e to your computer and use it in GitHub Desktop.
Batch script to update Plex Pre Rolls to include all videos in specified locations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Echo off | |
SetLocal EnableExtensions DisableDelayedExpansion | |
GoTo :BEGIN | |
================================================================================================= | |
Update_Plex_PreRolls.bat | |
Description: This script will include all video files in specified directories and update the | |
registry value for Plex. | |
Run by scheduled task. This needs to be executed by the user Plex Media Server is installed | |
for. Arguments should be path locations of directories that include your Pre Roll videos. | |
Must have atleast one argument. | |
You can import the "Update_Plex_PreRolls.xml" file to Task Scheduler and modify as necessary. | |
At a minimum you need to modify the command location (full path and file name of this file), | |
arguments (full paths of pre roll directories), and working directory (full path excluding | |
file name of this file). | |
Example for single location: | |
Update_Plex_PreRolls.bat "C:\Plex Media\Pre Rolls" | |
Example for multiple locations: | |
Update_Plex_PreRolls.bat "C:\Plex Media\Pre Rolls 01" "E:\Plex Media\Pre Rolls 02" | |
Known Issues: | |
-Network paths have not been tested. | |
------------------------------------------------------------------------------------------------- | |
Arguments: | |
x. PreRoll Directories | |
------------------------------------------------------------------------------------------------- | |
Modification History | |
Date By Description | |
------ ---------- ------------------------------------------------------------------------------- | |
082620 Archer Initial Version | |
082720 Archer Support for ! in filenames added | |
082720 Archer Removed txt file extension | |
================================================================================================= | |
:BEGIN | |
:--------------------------------------------------------------------------- | |
:variables | |
:--------------------------------------------------------------------------- | |
set "reg_data=" | |
set extensions=3g2:3gp:avi:flv:h264:m4v:mkv:mov:mp4:mpg:mpeg:rm:swf:vob:wmv | |
:--------------------------------------------------------------------------- | |
:arg_loop | |
:--------------------------------------------------------------------------- | |
FOR %%a IN (%*) do ( | |
set "my_dir=%%a" | |
for %%x in (%extensions::= %) do ( | |
set "my_ext=%%x" | |
call :add_files_to_list | |
) | |
) | |
call :update_reg | |
goto eof | |
:--------------------------------------------------------------------------- | |
:functions!!! | |
:--------------------------------------------------------------------------- | |
:--------------------------------------------------------------------------- | |
:add_files_to_list | |
:--------------------------------------------------------------------------- | |
cd /d %my_dir% | |
for %%G in ("*.%my_ext%") do (Echo "%%~fG"^|%%~xG | |
if not defined reg_data (Set "reg_data=%%~fG") else ( | |
for /F "Tokens=1*Delims==" %%H in ('set reg_data' | |
) do set "reg_data=%%I;%%~fG")) | |
goto end_function | |
:--------------------------------------------------------------------------- | |
:update_reg | |
:--------------------------------------------------------------------------- | |
SetLocal EnableDelayedExpansion | |
set reg_path=HKEY_CURRENT_USER\Software\Plex, Inc.\Plex Media Server | |
set reg_key=CinemaTrailersPrerollID | |
set reg_type=REG_SZ | |
REG ADD "!reg_path!" /v "!reg_key!" /t !reg_type! /d "!reg_data!" /f | |
EndLocal | |
goto end_function | |
:--------------------------------------------------------------------------- | |
:eof | |
:--------------------------------------------------------------------------- | |
endlocal | |
exit /b 0 | |
:--------------------------------------------------------------------------- | |
:end_function | |
:--------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<RegistrationInfo> | |
<Date>2020-08-26T17:51:00.8955428</Date> | |
<Author>ReenigneArcher</Author> | |
<URI>\ReenigneArcher\Update_Plex_PreRolls</URI> | |
</RegistrationInfo> | |
<Triggers> | |
<CalendarTrigger> | |
<Repetition> | |
<Interval>PT1H</Interval> | |
<Duration>P1D</Duration> | |
<StopAtDurationEnd>true</StopAtDurationEnd> | |
</Repetition> | |
<StartBoundary>2020-08-26T00:00:00</StartBoundary> | |
<ExecutionTimeLimit>PT30M</ExecutionTimeLimit> | |
<Enabled>true</Enabled> | |
<ScheduleByDay> | |
<DaysInterval>1</DaysInterval> | |
</ScheduleByDay> | |
</CalendarTrigger> | |
</Triggers> | |
<Principals> | |
<Principal id="Author"> | |
<UserId>S-1-5-21-416373151-1271962822-2142307910-93376</UserId> | |
<LogonType>InteractiveToken</LogonType> | |
<RunLevel>LeastPrivilege</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>true</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>true</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>true</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession> | |
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit> | |
<Priority>7</Priority> | |
<RestartOnFailure> | |
<Interval>PT1M</Interval> | |
<Count>3</Count> | |
</RestartOnFailure> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>E:\Scripts\Update_Plex_PreRolls.bat</Command> | |
<Arguments>"E:\Pre Roll"</Arguments> | |
<WorkingDirectory>E:\Scripts</WorkingDirectory> | |
</Exec> | |
</Actions> | |
</Task> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment