Setting up Movie Nights with a PowerShell Script

I love watching movies, but miss the theater experience — and by that I mean trailers and concession commercials, not gum on the floor, people talking, and kids kicking the back of my seat. I decided to write a script using PowerShell to try and enhance my home movie experience. The result, which I’ve named MovieNight.ps1, is pretty neat!

I’m splitting today’s blog post into two parts. The first half will be the fun half where I talk about what the script does. The first half won’t be technical at all. In the second half I’ll get into the technical details. If you’re not interested in all the nerdy behind-the-scenes stuff, that’ll be a good place to drop off.

Part One: What’s It Do?

I love all the little clips theaters show before the movie starts. I like the commercials, the trailers, and what theaters call their “policy” trailers (the clips that ask you not to smoke, talk, litter, or use your cell phone). My goal was to write a script that would randomly pick files from each of those categories and add them to a playlist. A playlist is a plain text file that simply tells whatever video player you use on your computer to show videos (or play music) in a specific order. The way I wanted the script to work was for me to tell it what movie I wanted to watch, and then have it quickly generate a playlist. One of the most important parts of the script was its ability to randomly pick the files. I want to be surprised by which trailers and commercials it adds to the playlist, otherwise it’s no fun!

Doing this required obtaining hundreds and hundreds of video clips off the internet, and sorting them into separate folders. A friend of mine sent me approximately 800 video clips to get me started; since then, I’ve acquired another 500. Most of the movie trailers and theater commercials were downloaded from YouTube. Once I had all of those files, I had to sort and resort them into folders that made sense so that the script could pull filenames from the different folders.

After all that sorting, I settled on the following folders: audio format promos, commercials, feature presentation, policy trailers, trailers, and welcome. Under commercials there are three additional folders: food and drink, intermission, and misc.

Lots of the commercials came from old drive-in clips. Here’s an example of one of the clips under the “food and drink” commercial folder.

And here’s one from the “Policy Trailers” folder. If you went to a Regal Cinema in the 90s, you might remember this roller coaster. Watch out for those giant Reese’s!

https://www.youtube.com/watch?v=H6o6ZlefvOo

Between those two videos, you can probably envision what I wanted to create. Based on the parameters you feed it, the script randomly plucks a few commercials, a few trailers, and whatever else you tell it to add. When it’s done, it creates a playlist that you only need to click on to sit back and enjoy the program! One other feature I added is that the movie trailers it selects are close to the same year as the movie I’m going to watch. I programmed in a tiny bit of leeway, but in general the trailers it picks will be from a year or two before or a year or two after the year the film was released.

It may seem odd to actually want to watch commercials and movie trailers, but having them presented in a random order really makes the home viewing experience much more theater-like. Plus, sometimes I find myself as nostalgic for the old commercials as I am for the old movies!

Part Two: How Does it Work?

Here we go.

Accompanying the script is a small text file (think of it like an old ini file) that contains the paths to all of my videos by category. It contains one additional variable (“YearVariance”) which tells the trailer portion how wide a bracket to pick trailers from. I currently have mine set on “2”, so if I pick a movie from 1984, it’ll randomly pick trailers for movies between 1982 and 1986.

The second half of the text file is the structure of the generated playlist. You can use commands like “add-commercial,” “add-trailer,” and “add-policy” to add those types of videos to the playlist. You can put them in any order you wish, and list them multiple times to get multiple videos added. Here’s the default setting:

Add-Required1
Add-Commercial
Add-Commercial
Add-Trailer
Add-Trailer
Add-Trailer
Add-Policy
Add-Feature

“Required1” is a hard coded link to a specific video (mine says “O’Hara Cinema”) that I want added to every single playlist. There’s a “Required2” slot as well, but I’m not currently using it.

Because cutting and pasting the entire path to my video files was more cumbersome than I had anticipated, the script also supports wildcards. I can run the script with a partial filename and it will find the first match and use it as the movie. It’s not perfect (I typed TRON and got “The STRONgest Man in the World) but if you put enough of the file name in there, it’ll usually find it.

To get age-appropriate trailers to work, I had to add the year to the filename of every single trailer (the ones I got from my friend already had the year; the ones I got from YouTube did not). I also have the year in my movie filenames, so it was just a matter of splitting filenames by parenthesis to pluck out the years, converting them to integers, and doing the math.

Here’s an example I just ran to generate a playlist for 1984’s Ghostbusters (with the real path edited out).

#EXTM3U
S:\(path)\Trailers\OHara_Cinemas.mp4
S:\(path)\Trailers\Commercials\Food and Drink\Hot Chocolate (1960s).mp4
S:\(path)\Trailers\Commercials\Intermission\Drive In Short Film Intermission Promo 12.mpg
S:\(path)\Trailers\Trailers\1982 – The Toy Trailer.mp4
S:\(path)\Trailers\Trailers\1985 – Rocky IV Trailer.m4v
S:\(path)\Trailers\Trailers\1984 – Gremlins Reissue Trailer.m4v
S:\(path)\Trailers\Policy_Trailers\Marcus Theatres Policy Trailer.m4v
S:\(path)\Trailers\Feature_Presentation\AMC Theatres Feature Presentation (1996 – 2002).mp4
S:\(path)\Ghostbusters 1 (1984).avi

As you can see, the generated playlist matches the format of the command list from before (required video, two commercials, three trailers, one policy, and one feature presentation video). The selected movie is automatically appended to the end of the playlist.

I’m planning on running either Kodi or Plex in my real movie room once construction ends, and I’ll need to change the output of the files to indirect patches instead of hard coded direct paths. This should be an easy change. I know Kodi has a folder for playlists, which I’m assuming this can be slipped directly into.

If anybody wants to play with it now, shoot me an email and I will send you the files, although unless your files and folders are set up like mine, it may take considerable modification to work in your environment.

2 comments to Setting up Movie Nights with a PowerShell Script

.xX[ MY INFO/LINKS ]Xx.

My EMAIL
My RSS FEED
My SUBSCRIPTION (Blog)
My Twitter
My YouTube

My Books
My Portfolio
My Podcasts
Review-O-Matic (Reviews)

.xX[ SUB-PAGES ]Xx.

My ARCADE GAMES
My SOFTWARE
My PHOTO GALLERY
My WRITING ADVICE
Every CAR I'VE OWNED
Every STATE I'VE VISITED