I Built A Seinfeld Streaming Box With A Old Raspberry Pi

I love Seinfeld. Something about it comforts me and still makes me laugh to this day, even after re-watching it many, many times. So, as a tribute to the show, I got the idea of making a Raspberry Pi project that would stream the classic TV show, plug and play with no internet connection necessary 🔌📺

Blog image

So, there were a couple of reasons why I decided to try this out. I had an old Raspberry Pi laying around in a drawer, and I thought I'd put it to use. I had also wanted to try coding something in Python for a while but hadn't found a suitable project yet.

I own the full series digitally, but I sometimes have a hard time choosing which episode to watch. It reminded me of the good ol' days when you just turned on the TV and watched what ever was on. I realized that the lack of control of choosing an episode was part of that comforting feeling for me. There are options for this available, watchseinfeld.net, for example, but that requires a stable internet connection, and you need to plug your laptop into the TV. On top of that, it's technically illegal 👮 I thought it would be cool to be able to bring this little box with you anywhere and know it would work without an internet connection. My solution was "The Seinfeld Box." A small computer with a HDMI output that connects to any TV or monitor, comes loaded with all 9 seasons, doesn't require a internet connection and is 100% plug and play!

Hardware used

  • Raspberry Pi 3 Model B
  • 64GB SD-Card
  • HDMI Cable
  • Power adapter

Software used

  • Headless Raspberry Pi OS (command line only)
  • Pyton
  • VLC

I started off by installing the Raspberry Pi OS on an SD-card and transferring all my video files to it. After booting up a fresh installation, I updated the system:

sudo apt update
sudo apt upgrade

Then I installed the latest version of VLC:

sudo apt install -y vlc

Then PIP (Package Installer for Python):

sudo apt install python3-pip

And lastly, the Python VLC package to control VLC with my script:

pip install python-vlc

Since I didn't know much Python, I had to do some research. I wanted "The Seinfeld Box" to start streaming a random episode automatically when plugged into a TV or monitor. I also wanted to automatically select the English subtitle option and queue up more episodes after the first one ends. This was much easier than expected, especially using the Python VLC package. I decided to go with a headless Raspberry Pi OS since I wanted all resources to focus on playing the video.

I started off by creating a intro screen to give the user some feedback on the TV:

import time
import vlc
import os
import random

COUNTDOWN_DURATION = 3

def print_bold_yellow(text):
    bold_yellow_text = "\x1b[1;33m" + text + "\x1b[0m"
    print(bold_yellow_text)

print(r"""

__        __   _                            _          _   _
\ \      / /__| | ___ ___  _ __ ___   ___  | |_ ___   | |_| |__   ___
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \  | __| '_ \ / _ \
  \ V  V /  __/ | (_| (_) | | | | | |  __/ | || (_) | | |_| | | |  __/
  \_/\_/ \___|_|\___\___/|_| |_| |_|\___|  \__\___/   \__|_| |_|\___|
____       _        __      _     _   _               _
/ ___|  ___(_)_ __  / _| ___| | __| | | |__   _____  _| |
\___ \ / _ \ | '_ \| |_ / _ \ |/ _` | | '_ \ / _ \ \/ / |
___) |  __/ | | | |  _|  __/ | (_| | | |_) | (_) >  <|_|
|____/ \___|_|_| |_|_|  \___|_|\__,_| |_.__/ \___/_/\_(_)

- That's gold Jerry, gold!


                """)

print_bold_yellow("Preparing random episode. Please wait..")

time.sleep(COUNTDOWN_DURATION)

This will print bold yellow text in the terminal that lets the user know that a random episode is being loaded. I added a short delay of three seconds to give the user time to read what is going on before the episode starts playing. I created an ASCII-style welcome message using an online tool to add graphics. I also made sure to import all the packages I needed at the top of the file.

Now I had to create a playlist containing all the episodes in random order. First, I added the file path to where my files are stored. Then, I created a player instance that loads the player in full-screen mode with the first subtitle track selected (in my case, that is the English subtitle). I then looped over all the files within my folder and added every file with the file ending .mkv. I did this to exclude any other files present in the folder to make sure only the video files are added to the playlist. Lastly, I randomized the playlist so that you can't know which episode will play and what episode comes next.

FOLDER_PATH = "/home/admin/seinfeld"

instance = vlc.Instance("--no-xlib --fullscreen --sub-track=0")

player = instance.media_player_new()

media_list = instance.media_list_new()

video_files = [os.path.join(FOLDER_PATH, file) for file in os.listdir(FOLDER_PATH) if file.endswith(".mkv")]

random.shuffle(video_files)

I continued by adding all the video files to a VLC playlist and then loaded the VLC player with that playlist. I also added playback mode: loop so that this stream will just loop forever. Lastly, we hit play!

for video_file in video_files:
    media = instance.media_new(video_file)
    media_list.add_media(media)

list_player = instance.media_list_player_new()
list_player.set_media_list(media_list)

list_player.set_media_player(player)

list_player.set_playback_mode(vlc.PlaybackMode.loop)

list_player.play()

try:
    while True:
        pass
except KeyboardInterrupt:
    pass

list_player.release()

And that's it! I set up the script to run automatically on boot so that whenever you plug it into a TV or monitor and power it on, the script will be executed. I also removed the standard boot screen for Raspberry Pi OS to give everything a bit of a cleaner feel. I posted all the resources I used below.

Resources:

How to Set Up a Headless Raspberry Pi, Without Ever Attaching a Monitor How to run a Python script on start up Removing boot logo on Raspberry Pi