Movie Pre Roll Video - Revisited

Server Version#: 1.41.8.9834
Player Version#: 1.109.0.329-ea562b95

I grew up in the 70s and 80s. I love classical music because of Warner Bros., and I owe a lot of grammar education to Schoolhouse Rock. In my library, I’ve collected just shy of 1,000 Warner cartoons, about 200 Disney shorts, and most of the Schoolhouse Rock shorts.

With pre-rolls, as in every post I’ve read, the challenge is how to take a random sample of files and populate the extras field for pre-roll videos, and automate that process. Most of the answers I found indicated that I should be modifying the preferences.xml file for the server. However (nothing good ever follows “however”), even after searching for several hours on my server, I couldn’t locate the preference file that the server was using, only remnants from old installations.

So, I asked myself, how do I bypass the preferences file altogether?

I created a pre-roll folder on my NAS. The files in that folder are all mkv files, and I’ve converted all of my pre-roll videos to mkv format (which didn’t take as long as I anticipated.) because the static file directs to the temporary folder all have to have the same file extension.
That folder has 10 files - N1.mkv, N2.mkv, N3.mkv, etc.
The extras - pre rolls field in Plex Server is set permanently to read the N1-N10 files (separated by semicolons for more randomness).

The script I wrote works as follows:

  • It goes to the pre-roll folder and deletes the existing 10 files.

  • Pulls 10 random files from the cartoons folder (where the 1600 mkv files live).

  • Copies those files, and renames them N1, N2, N3 and so on.

  • Pastes those files into my pre roll folder.

The script is scheduled as a task to run every night at 2 am.

WORKS LIKE A CHARM.

Here’s my script - adjust yours to your environment:

PowerShell Script to Refresh Plex Pre-Roll Videos

Define source and target directories

$sourceDir = “\MajesticAnnex\MajesticVault\Cartoons”
$targetDir = “\MajesticAnnex\MajesticVault\PlexPreRolls”

Delete existing files in the target directory

Get-ChildItem -Path $targetDir -File | Remove-Item -Force

Recursively get all .mkv files from the source directory

$videoFiles = Get-ChildItem -Path $sourceDir -Include *.mkv -Recurse -ErrorAction SilentlyContinue | Where-Object { -not $_.PSIsContainer }

Select 10 random files

$selectedFiles = $videoFiles | Get-Random -Count 10

Copy and rename them to N1, N2, …, N10

$i = 1
foreach ($file in $selectedFiles) {
$ext = $file.Extension
$newName = “N$i$ext”
Copy-Item -Path $file.FullName -Destination (Join-Path $targetDir $newName)
Write-Output “Copied: $($file.FullName)”
$i++
}

Write-Output “:white_check_mark: 10 random pre-roll videos copied to $targetDir.”

RECOMMEND the temp folder should be on the same drive as the source files - otherwise the copy function will take a while for the file data to actually move across drives or the network..

And yes, my Plex server is named after The Majestic - the movie theater in the 2001 movie of the same name starring Jim Carrey.

Those settings are in the registry on Windows. Linux and Mac have preference files.

https://support.plex.tv/articles/201105343-advanced-hidden-server-settings/

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