Nov 4, 2024 3 min read

PyTivo: The Ultimate Guide to Self-Hosting

PyTivo: The Ultimate Guide to Self-Hosting
Table of Contents

PyTivo is an open-source, self-hosted application that allows you to stream, share, and transfer media files between your computer and TiVo devices. Designed for tech-savvy users, PyTivo provides extensive customization while ensuring complete data control. With its lightweight architecture and robust feature set, it’s an excellent alternative for managing your media library. This guide will walk you through installing, configuring, and managing PyTivo, including reverse proxy setup, logging, backups, and leveraging its unique capabilities.

Installing PyTivo

πŸ“¦ Docker/Docker Compose Setup

Using Docker is one of the easiest and most reliable ways to deploy PyTivo. Below is a docker-compose.yml configuration tailored for PyTivo.


version: '3.8'

services:

pytivo:

image: wmcbrine/pytivo

container_name: pytivo

ports:

- "9032:9032"  # Expose PyTivo's web interface

volumes:

- ./pytivo/config:/config  # Persistent configuration

- ./pytivo/media:/media    # Media files directory

environment:

- TZ=America/New_York      # Set your timezone

restart: unless-stopped

Run the following commands to deploy PyTivo with Docker Compose:


mkdir -p ~/pytivo/{config,media}

## Navigate to the directory and create the docker-compose file

cd ~/pytivo

nano docker-compose.yml  # Paste the above YAML config

## Deploy the application

docker-compose up -d

## Verify the container is running

docker ps

πŸš€ Manual Installation

For non-Docker setups, install PyTivo manually on a Linux server using these commands:


## Update system packages

sudo apt update && sudo apt upgrade -y

## Install dependencies

sudo apt install python3 python3-pip git ffmpeg -y

## Clone the PyTivo repository

git clone https://github.com/wmcbrine/pytivo.git ~/pytivo

## Install Python dependencies

cd ~/pytivo

pip3 install -r requirements.txt

## Run PyTivo

python3 pytivo.py

After running the above commands, access the PyTivo interface at http://<your-server-ip>:9032.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve PyTivo behind Nginx, create an Nginx server block with the following configuration:


server {

listen 80;

server_name your-domain.com;

location / {

proxy_pass http://127.0.0.1:9032;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Activate the configuration:


## Save the configuration to /etc/nginx/sites-available/pytivo

sudo nano /etc/nginx/sites-available/pytivo

## Link the configuration and test

sudo ln -s /etc/nginx/sites-available/pytivo /etc/nginx/sites-enabled/

sudo nginx -t

## Reload Nginx

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your PyTivo instance with Let's Encrypt:


## Install Certbot

sudo apt install certbot python3-certbot-nginx -y

## Obtain and configure an SSL certificate

sudo certbot --nginx -d your-domain.com

## Test automatic renewal

sudo certbot renew --dry-run

πŸ› οΈ Testing and Reloading Nginx

Ensure Nginx is properly configured and reload it as needed:


## Check Nginx status

sudo systemctl status nginx

## Apply configuration changes

sudo nginx -t && sudo systemctl reload nginx

Logging and Debugging PyTivo

πŸ—ƒοΈ Enabling Debug Logs

Enable debug-level logging for PyTivo by adding the following to pytivo.conf:


[Server]

debug = true

Restart PyTivo to apply changes:


## For Docker-based setups

docker restart pytivo

## For manual setups

killall -9 python3 && python3 pytivo.py

πŸ“„ Viewing Logs

View PyTivo logs depending on your setup:


## For Docker-based setups

docker logs pytivo

## For manual setups

tail -f ~/pytivo/pytivo.log

πŸ› οΈ Troubleshooting Common Issues

Analyze log output to resolve errors. For example:

  • Error: Port already in use: Check running processes on port 9032 with sudo lsof -i :9032.

  • Media not loading: Verify media paths in pytivo.conf.

πŸ“€ Exporting Logs

Export logs to an external system for deeper analysis with ELK Stack:


docker logs pytivo > pytivo_logs.txt

scp pytivo_logs.txt user@elk-server:/path/to/logs/

Backup and Restore

πŸ—‚οΈ File-Based Backups

Back up PyTivo configuration and media directories:


tar -czvf pytivo_backup_$(date +%F).tar.gz ~/pytivo/config ~/pytivo/media

πŸ”„ Database Backups

If PyTivo integrates with a database, export its data (replace <db_name> with your database name):


mysqldump -u root -p <db_name> > pytivo_db_backup.sql

πŸ“… Automated Backup Scripts

Set up a cron job for daily backups:


## Create a backup script

echo '#!/bin/bash

tar -czvf ~/pytivo_backups/pytivo_backup_$(date +%F).tar.gz ~/pytivo/config ~/pytivo/media' > ~/backup_pytivo.sh

## Make it executable

chmod +x ~/backup_pytivo.sh

## Add to crontab

crontab -e

## Add the following line:

0 2 * * * ~/backup_pytivo.sh

Updating and Upgrading PyTivo

⬆️ Updating Docker Images

Pull the latest Docker image and redeploy:


docker-compose down

docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual setups, update PyTivo with Git:


cd ~/pytivo

git pull

python3 pytivo.py

πŸ” Checking for Updates

Monitor updates via PyTivo’s GitHub repository:


git fetch

git status

Leveraging PyTivo’s Unique Features

πŸ”§ Enabling APIs

PyTivo provides an API for advanced integrations. Enable it in pytivo.conf:


[API]

enabled = true

Access the API with tools like curl:


curl http://<your-server-ip>:9032/api/mediaserver/status

🌟 Advanced Configurations

Customize PyTivo to suit your needs. For example, specify media directories in pytivo.conf:


[MyMovies]

type = video

path = /media/movies

Restart the service to apply changes.

Wrapping Up

In this guide, you’ve learned how to install, configure, and manage PyTivo, from setting up Docker to configuring Nginx and enabling advanced features. Self-hosting PyTivo gives you unparalleled control over your media streaming experience while maintaining privacy and customizability. Start implementing these steps today to unlock PyTivo’s full potential!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.