Side Project: YouTube Live Stream Scheduler – Part 1

One great thing about computers is that they can be programmed to do things that are repetitive and boring. I try to look around in my life to see what things I can get a computer to do for me, so that I don’t have to do it myself.

Today’s case is scheduling weekly YouTube live streams for my church. Every week someone’s got to schedule the live streams for the upcoming weekend. They look like this:

So you might be thinking, this seems pretty trivial, like it’s just a few clicks to schedule this in YouTube. It can’t take more than 10 minutes. And that’s true, but it’s still straightforward and repetitive. Having to figure out which Sunday is coming up, copying and pasting and ensuring the correct dates and times are replaced in the live stream text, and making sure the scheduled dates and times are correct can become tedious work. And it’s the same procedure week after week: the type of processing that computers love to do.

Sure there are other ways to optimize this process, like batching it to create maybe two or more weeks at a time. However, from a viewer’s perspective it can also be confusing when there are a bunch of upcoming live streams that need to be scrolled through. For the purposes of this project, the optimal frequency is to have one set of upcoming live streams visible at any time, and that means having the computer schedule the next set of live streams once every week.

So let’s get the computer to do this. I’m going to split up this blog post into two parts:

Part 1 – Parsing the Canadian Catholic liturgical calendar

I’m not going to explain the entire details of how the Catholic liturgical calendar works here (there are other much better resources for explaining this such as on the USCCB and other church documents), but in essence, each Sunday has a “name” of the celebration that week, according to a yearly cycle. For example, we are currently in the liturgical season of Ordinary Time and tomorrow is the “Third Sunday in Ordinary Time”. Two Sundays ago, the special celebration was “The Baptism of the Lord”. Although most of these special celebrations are universally celebrated on the same day, there are others such as “The Epiphany of the Lord”, which we in Canada celebrated three Sundays ago, that change according to local custom. Some countries, such as Argentina, Italy, Poland and others, celebrate the Epiphany on the actual day, January 6th (this year, on a Thursday), whereas other countries move the celebration to the nearest Sunday.

So because of these local customs, it becomes necessary to find a localized liturgical calendar. The Canadian Conference of Bishops publishes the liturgical calendar on its website, however, it’s a PDF in a calendar visual format. Great for humans, but not so great for computers.

So searching for other resources, I come across the liturgical calendar on Universalis. At the bottom there are links to the .ics (iCalendar format) files (for those of you not in Canada, you can also see if Universalis has the calendar of your country or diocese). Great, this file format is perfect to be read by computer programs.

I’m aiming for simplicity here especially for the examples, so the following code is going to be some pretty plain ugly Python.

In order to read the .ics file format, I decided to use a Python library called icalevents. This library wraps the entire process of downloading an .ics file, and parsing it to retrieve the events on a specified date: the exact use case I was looking for, no need to re-invent the wheel. You can install this into your project using pip install icalevents.

from icalevents.icalevents import events

def get_name(date):
    day_events = events(
        url="http://universalis.com/Canada/vcalendar.ics",
        start=date,
        end=date
    )
    try:
        event = day_events[0]
    except IndexError as ex:
        raise Exception("No event") from ex
    return event.summary

Pretty simple. The events method documentation can be found here. The icalevents library documentation is pretty terse in general, but it gets the job done so can’t complain.

Then testing this function through a Python shell:

>>> import datetime
>>> get_name(datetime.date(2022, 1, 30))
'4th Sunday in Ordinary Time'

Perfect. Part 1 complete! We can get the proper name of the date we want to schedule the live stream for.

In the next part, I’ll go through the process of automating the creation of a YouTube live stream.

Related

One thought on “Side Project: YouTube Live Stream Scheduler – Part 1

Leave a Reply

Your email address will not be published.