Hi Everyone,
Ever since I started running Plex, I have wanted the ability of playing a random cartoon short before a movie begins. Growing up in the 1960’s and 1970’s, a cartoon always played before a main feature.
I’ve seen a few older feature requests for this type of thing, so thought I would post my solution to this challenge here.
I have been collecting various cartoon series over the years, and have all the Looney Tunes, most of the Disney shorts, Pink Panther, Rocky & Bullwinkle, Flintstones, Jetsons and am always adding others. For me, the best way to enjoy these 1000’s of cartoons is to have one randomly play before a movie - that way the user will get to experience a multitude of cartoons with the fun being you never know what’s going to play before the movie.
After some experimentation, I finally decided on a fairly easy way to implement a feature like this. For starters, in the Movie pre-roll video field, I have to set up to play one of 10 cartoon shorts before a movie. The field is set up like this:
/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short1.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short2.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short3.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short4.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short5.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short6.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short7.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short8.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short9.m4v;/share/CACHEDEV1_DATA/Multimedia/Plex/Pre-Rolls/short10.m4v;
Because the Movie pre-roll video field is a configuration field and refers to one or more static files, what I decided to do is:
-
Create a TV Shows Playlist called Animated Shorts, which includes whichever cartoons I want included in the random list which gets generated.
-
Create a python script which deletes the current 10 cartoon shorts, then uses the Animated Shorts Playlist to choose 10 new random shorts. Because the shorts I have are a mix of MKV, MP4 and M4V files, the script uses ffmpeg to convert those selected shorts to M4V if they are not that format already. Each selected cartoon, once in M4V format is placed in the /Pre-Rolls folder. The script is configurable to allow more or less than 10 shorts. I picked 10 as a reasonable number, figuring in any one day no user is going to play more than a couple movies.
-
Create a cron job to run the Python script each morning at 1am.
-
In my TV Library, I had many AVI files, and through experimentation I found that converting these to M4V took much longer than I wanted, so I created an additional script which went through all my Cartoon TV Series and converted any AVI to M4V. This script only had to be run once. I then deleted each AVI version of the cartoon and replaced it with the M4V version in the TV Shows library.
The beauty of this solution is that it’s easy to add or remove cartoons from the Animated Shorts playlist. The very next time the cron job runs it will then use this adjusted set of cartoons from which to choose the 10 for that day.
As I mentioned, if you want more than 10 to choose from, it’s easy enough to change in the script. Also, the cron job can be set up to run as often as desired. It would be easy enough to change it to once an hour, twice a day, once a week, etc. So far, I’m happy having the job run once a day.
For those interested, I have attached the main script which runs daily - “pick_random_pre-roll_shorts” and the other which was only run 1 time to convert all my AVIs to M4Vs - “convert_avi_to_m4v”. Both scripts need to have a “.py” extension and need to be edited to include your specific paths to various folders. I have indicated in each script what needs to be changed using “<>”.
pick_random_pre-roll_shorts for Plex Forum.txt (2.6 KB)
convert_avi_to_m4v for Plex Forum.txt (2.7 KB)