Releasing Episodes on a Media Server

command-terminal-graphic

Back in the day before streaming movies and TV shows was ever possible, we had to wait for a new episode to air each week. Not to mention the summers were full of reruns. I find that streaming allows my family to binge shows easily and lose time to sitting on the couch. So I created a script for our media server which will “release” new episodes each week (or any frequency you desire).

While I had initial pushback from my family the build-up of anticipation and excitement for the next episode each week has been great for us.

The Concept

Essentially to start you will need a series of videos in a directory on your media server. This can be any series. Even a bunch of YouTube videos you have previously downloaded. You will need to hide the files by renaming them with a period at the beginning of the name. Linux recognizes file names starting with a period to be hidden from view.

The script below will facilitate the release of a file in the directories you specify. The timeframe for release is determined by a cronjob.

The Script

This is script template. Like any bash script, lines that start with a # are commented out and will not be read/executed by the computer.
The script has two primary sections. The list of the shows and their relevant paths, and the actual execution part. The list of shows allows you to add as many directories to your shows as you would like. Each line starts with a show number. This acts as a varible which will be called later in the script. After the = type in the exact path to the directory that contains the show files.

The bottom portion the script renames the next file (in alphabetical order) by removing the period at the beginning of the next file name. This makes the file visible to the media server software (Plex, Jellyfin, etc.) which will then see it as a new file and pull the metadata accordingly.

#!/bin/bash

# Paths to video files for each series
show1=/path-to-files/[showname]/[season]
show2=/path-to-files/[showname]/[season]
show3=/path-to-files/[showname]/[season]
show4=/path-to-files/[showname]/[season]
#show5=/path-to-files/[showname]/[season]
#show6=/path-to-files/[showname]/[season]

# A template of the lines below.
#file="$(find [/path] -type f -iname ".*" | sort | head -n1)"
#mv "$file" "/path/${file##*/.}"

# The shows to be executed
file="$(find $show1 -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show1/${file##*/.}"

file="$(find $show2 -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show2/${file##*/.}"

file="$(find $show3 -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show3/${file##*/.}"

file="$(find $show4/ -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show4/${file##*/.}"

file="$(find $show5/ -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show5/${file##*/.}"

file="$(find $show6/ -type f -iname ".*" | sort | head -n1)"
mv "$file" "$show6/${file##*/.}"

Scheduling

By leveraging a cronjob (scheduled task) we can execute this script once a week. If all goes well each week the script will run and each executable entry will rename a single file in the specified directories. Once it is set it will continue to execute. Once all of the files are renamed, the job will still execute, except nothing will change as there are no more hidden files to rename. Below is the cronjob line:

# Release New Episodes
0 7 * * 4 /home/[username]/bin/release2.sh

This is an explanation of what each asterisk means in the cronjob line. My job runs every Thursday at 07:00.

Conclusion

This script has been very helpful to keep me from binging on countless hours of video. It reminds me of the old days and it gives me something to look forward to.