Local Timings Application

In my day job working at a local television station I spend time in Master Control monitoring our five stations that we broadcast. Two of these are sub-channels that play out old movies and tv shows from a network feed. The network sends a pulse when its time for our local break to air and for the most part it works without problem.

But occasionally a break is missed.

We can get a PDF of that days log and find the exact time our break should roll from the affiliate portal. Then we have to search the log to find the line that is for the local break. Some people prefer to do this ahead of time and leave notes in the playlist so we know when a break is approaching and when it’s been missed.

To do so they would print out a ~30 page PDF and go through manually finding all the local times.

I knew this repetitive task was asking for some automation.

Basic Structure

Since the application was going to be so small I decided to start from scratch and not use any framework. I would use a simple form to upload the PDF file and then use PHP to work with the uploaded file.

I knew I needed to parse the PDF so I found pdfparser by Sebastien Malot. This takes the PDF file and converts it into one giant string.

Now I needed to search through that text and pull out all of the local break times.

The Regex

$regex = "/([0-9]{1,2}:[0-9]{2}:[0-9]{2})\s(AM|PM|XM)\s{0,1}\*{3}\s{0,3}\ *{1,2}LOCAL.*?([0-9]{1,2}:[0-9]{2})/";

The text that I would need to search for is:

8:18:03 AM *** *LOCAL AFFILIATE BREAK 2:00 ***

First I need to grab the time that break occurs, allowing for the first digit to be one or two numbers in length. Then I need to collect the AM, PM, or XM (side note: our logs begin at 4am so the hours from midnight until 4am are referred to as XM).

The stars and spaces after the time are not consistent across different days so I needed to allow for some variance in their number. I only search for the work LOCAL because some breaks are LOCAL/CABLE breaks which we also get, so I include the .*? regex to find everything until the next time.

Then I collect the length of the break similarly to the collecting of the first time.

Here is my final regex:

Some of the problems were found after a couple days of testing so I had to update it when the results were no longer consistent. I used preg_match_all to find all the matches and assign it to a new array that I could loop through to print to the screen.

Loading Spinner

At first I used a simple css spinner for the loading process. Because the PDF file is large it can take 5-10 seconds before the final results are printed. Since there was so much time I wanted to make a fancier loader and made this little guy:

See the Pen TV Color Bars Loading Screen by Anthony Skelton (@ajskelton) on CodePen.

I use a simple onClick javascript event that adds a full screen div with the above svg. It’s not vital to the project but it does make it fun.

The Code

If you want to see the project or use it for your own purpose check it out on github. Be warned I did a lot of it quickly and didn’t spend a lot of time cleaning up things. It works great so I don’t really need to go back to it unless I want to practice some refactoring.


in

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *