Contents

A podcast from a YouTube channel

Ytrss – how to turn a YouTube channel into a podcast

They say the best projects are the ones you use yourself. For years I’ve been using my own tool that turns YouTube channels into podcasts, and I keep improving it. Today I’d like to say a few words about it.

Warning
This article was translated with Claude from polish language. I have made every effort to make it correct. However, if you found any errors or inaccuracies, please let me know.

tl;dr

  • The article contains a short history of the project
    • The idea behind the app was to fetch information about new YouTube videos
    • The project was written in bash and rewritten in Python
    • A container image was created
  • Some information on where to get the project and how to run it

How did the idea come about?

When I was a student and travelled home for the weekends, I ended up with quite a lot of time on my hands and nothing to do. The hour-long journeys were hard to use for resting, and they didn’t leave much room for work either.

At first I listened to music during that time, but I quickly got bored of it. In theory, I could have spent the time reading a book or study materials, but it wasn’t very comfortable in a shaking vehicle. I couldn’t really use the internet either, because the route went through towns with poor coverage, and back then internet access wasn’t available everywhere.

So the best solution was to find some radio show, download the file to my phone and listen to it on the way. That’s how I discovered podcasts. They weren’t as popular and accessible as they are today, so finding and handling them took a bit more effort.

Shows on YouTube

At first I had a few favourite shows that I could download to my smartphone before the trip, but most shows were simply uploaded to YouTube. That added an extra step to the whole process. If I wanted to listen to something offline, without internet access, I had to download it and convert it to mp3 so my phone could play it.

Back then there were ready-made websites that did exactly that. All you had to do was paste the URL, and a moment later you could download a fresh file to your device. Thanks to that, I always had a few shows downloaded, so I could enjoy the latest news while travelling the roads of the Lublin region.

Real podcasts

I should mention here that when I talk about podcasts, I don’t just mean shows to listen to. The term also comes with a certain technology that today’s listeners aren’t really aware of.

Apart from the audio file, the podcast author also provided a file that told the listener’s device which episodes were available. This file was available on the internet, and a suitable app checked whether anything new had appeared in it. It could then display information about the new episode and, if needed, download it to the device. If you know what RSS feeds are, podcasts were practically the same thing, with additional information about where the recording is located.

Today, services such as Spotify offer many shows while hiding the implementation details from users. On the one hand, this improves accessibility; on the other, it makes listeners dependent on specific platforms and takes away the possibility of publishing content independently.

So what did I want to achieve?

My idea was to automatically download videos from YouTube in such a way that I could play them in my podcast player.

Unravelling the thread

Once the goals were clear, I slowly got down to work. The Podcast Addict app let you create a “virtual podcast” from files in a chosen folder on your phone. Every file that appeared there became a new episode in the app. It quickly turned out that the “virtual podcasts” feature would make the job much easier. I didn’t need to build the whole podcast mechanism. All I had to do was copy the files to the right folder on the phone.

Since I had already worked out file synchronisation between my computer and my phone, all that was left was to write a script that would prepare those files.

A simple script

The task was easy, so to keep things simple, I decided to write a simple bash script. The program consisted of two modules. The first one read a list of URLs from a file and downloaded the videos to the right folder. The second one, based on YouTube’s RSS feed, picked up newly added videos and put them on the list described above.

This solution was not only dead simple, but it also allowed me to add videos to the list that weren’t in my RSS feeds but that, for some reason, I wanted to add manually.

I moved the script to a Raspberry Pi, so it could download new videos as they appeared, and after connecting to the local network, my phone could download those files in the background for the next day.

This way I could enjoy up-to-date shows not only when travelling home, but also on my way to work or university.

Switching to Python

While the script worked fine in typical cases, problems appeared, for example, when a video failed to download or when for some reason I had to unplug the Raspberry Pi in the middle of downloading files. I also wanted the script, apart from downloading audio, to generate files describing the episodes, from which an RSS file (the podcast feed) would be built. These things were possible in bash, but they made the code very complicated.

Since my other projects relied on object-oriented programming, and I really liked the idea of packages implemented by Python at the time, I decided to write this program in that language.

An additional argument for this language was the fact that the script I used to download files was written in it. Back then I used youtube-dl, which I later replaced with yt-dlp. This made it easier to integrate.

Python allowed me to introduce a few new improvements. Although the program still ran as a separate script that had to be launched every now and then, thanks to system mechanisms this could happen completely automatically.

Time for a container

For a while the project was shelved. During that time I had no way of running the Raspberry Pi with my script. So I focused on listening to videos on YouTube as they came out. When I finally thought about reviving the project, I decided to add a new detail to it.

Installing projects like this shows us how problematic it can be to return to old code after a long break. Installation isn’t just about running the right scripts, but also about preparing the system to handle our application.

I thought it would be nice to have a ready-made container, so the project could be run without thinking about implementation details. It’s also easier to hand such a project over to someone else when they can do it without knowing how to install each component.

I think that a project’s runtime environment, wrapped up in a neat Dockerfile, is an essential element that should be added to every project. How much easier it would be to configure and return to old projects if I had included this kind of configuration in my university projects.

How does it work today?

Today, thanks to these changes, I can go through the deployment process of this project quickly and smoothly. Currently it runs in the background in Docker on my personal laptop and generates new files for videos that people upload to their channels.

The files I’ve generated can then be shared on the local network, and any podcast app has no idea that anything is off.

Warning

Remember that downloading videos from YouTube may violate its terms of service. Always make sure you are allowed to do it, and don’t share materials you don’t hold the copyright to.

YouTube frequently changes the platform’s protections, so the yt-dlp download script often needs updating.

Where can I find the project?

You can download and try the project at github.com/rafyco/ytrss. I recommend starting with the documentation, where you’ll find plenty of information about its features and ways to run it. You’ll find more information in the References section.

If you’d like to help develop the software or have ideas for new features, feel free to reach out to me on my social media.

How to run the project?

Installing from PyPI

You can install the project with pip. Just run:

pip install ytrss

Then create a configuration file with information about the channels you want to download. You’ll find a detailed description of the configuration and an example in the documentation.

Once the configuration is ready and in the right place, you can automatically download the files and generate the podcasts with:

ytrss run

It’s worth adding it to cron so it runs automatically.

You can also use the command:

ytrss daemon

This command will check the feeds once an hour and automatically update the podcasts if new videos appear. It can be run in the background or used to create a service, e.g. with systemctl.

Installing with Docker

Perhaps a much more convenient way to try out my software is to use it as a Docker image. You can pull it from the public repository with:

docker pull rafyco/ytrss:latest

The simplest invocation looks like this:

docker run -d \
--name ytrss \
-v $(pwd)/volumes/ytrss/config.yml:/home/ytrss/.config/ytrss/config/config.yml:ro \
-v $(pwd)/volumes/ytrss/podcasts:/home/ytrss/podcasts \
rafyco/ytrss:latest

In the documentation you’ll find more examples as well as a Docker Compose configuration, which greatly extends what the software can do.

Plans for the future

Today my project is fairly advanced, and I can say with confidence that I’ve learned a lot from it. It was created before the AI era, so I wrote almost every line myself, by trial and error.

The experience with DevOps tools that I could test on it also proved invaluable. It really broadens your horizons when it comes to understanding how software is made, and although today I could do it all in about one evening, I know which things to pay attention to when building a project like this.

I tried to build my project in a modular way, so that the core functionality wasn’t tightly coupled to the YouTube platform or even to the idea of podcasts itself, which is why I think the next step was to create a mechanism for external modules that could extend the software’s capabilities.

Support for other services or creative ways of storing and generating content are things I’ll probably work on in the future.

… as long as I can find the time…

References

  1. https://github.com/rafyco/ytrss Source code
  2. https://ytrss.readthedocs.io/ Documentation
  3. https://pypi.org/project/ytrss/ - Project on PyPI
  4. https://hub.docker.com/r/rafyco/ytrss - Docker image to download
  5. yt-dlp - Video download script