Get notified when a new drop is available on Twitch or Kick https://ttvdrops.lovinator.space/
  • Python 82.5%
  • HTML 17.1%
  • XSLT 0.4%
Find a file
Joakim Hellsén 859e01faf4
All checks were successful
Deploy to Server / deploy (push) Successful in 25s
Optimize sitemap views?
2026-04-12 05:46:05 +02:00
.github Revise copilot-instructions.md 2026-04-07 20:37:03 +02:00
.vscode Add initial chzzk app structure and configuration 2026-03-30 17:00:10 +02:00
chzzk Improve performance and add type hints 2026-04-11 00:44:16 +02:00
config Improve performance and add type hints 2026-04-11 00:44:16 +02:00
core Optimize sitemap views? 2026-04-12 05:46:05 +02:00
kick Improve performance and add type hints 2026-04-11 00:44:16 +02:00
static Update web app manifest; fix type errors 2026-03-19 19:39:27 +01:00
templates Refactor badge list view to use badge_data and optimize badge fetching; add tests for badge list and detail views 2026-04-11 01:12:08 +02:00
tools/systemd Use celery tasks instead of systemd timers for periodic work; and add more tests 2026-04-08 03:23:18 +02:00
twitch Fix typo 2026-04-12 05:31:26 +02:00
youtube Refactor URL handling to use BASE_URL across the application and add base_url context processor 2026-04-03 19:51:01 +02:00
.env.example Use celery tasks instead of systemd timers for periodic work; and add more tests 2026-04-08 03:23:18 +02:00
.git-blame-ignore-revs Add .git-blame-ignore-revs 2026-03-09 04:41:11 +01:00
.gitattributes Add .gitattributes to mark JSON files as linguist-generated 2026-03-31 21:56:39 +02:00
.gitignore Remove uv.lock 2026-02-07 13:58:03 +01:00
.pre-commit-config.yaml Update ruff-pre-commit version to v0.15.9 2026-04-03 19:26:55 +02:00
conftest.py Improve performance and add type hints 2026-04-11 00:44:16 +02:00
manage.py Lower line-length to default and don't add from __future__ import annotations to everything 2026-03-09 04:37:54 +01:00
pyproject.toml Improve performance and add type hints 2026-04-11 00:44:16 +02:00
README.md Use celery tasks instead of systemd timers for periodic work; and add more tests 2026-04-08 03:23:18 +02:00

ttvdrops

Get notified when a new drop is available on Twitch

TL;DR (Arch Linux + PostgreSQL)

Install and initialize Postgres, then start the service:

sudo pacman -S postgresql
sudo -u postgres initdb -D /var/lib/postgres/data
sudo systemctl enable --now postgresql

Create a local role and database:

sudo -u postgres createuser -P ttvdrops
sudo -u postgres createdb -O ttvdrops ttvdrops

Point Django at the unix socket used by Arch (/run/postgresql):

POSTGRES_USER=ttvdrops
POSTGRES_PASSWORD=your_password
POSTGRES_DB=ttvdrops
POSTGRES_HOST=/run/postgresql
POSTGRES_PORT=5432

Linux (Systemd)

sudo useradd --create-home --home-dir /home/ttvdrops --shell /bin/fish ttvdrops
sudo passwd ttvdrops
sudo usermod -aG wheel ttvdrops
su - ttvdrops
git clone https://git.lovinator.space/TheLovinator/ttvdrops.git
cd ttvdrops
uv sync --no-dev

# Modify .env with the correct database credentials and other settings, then run migrations:
uv run python manage.py migrate

Install the systemd service from the repo:

sudo install -m 0644 tools/systemd/ttvdrops.socket /etc/systemd/system/ttvdrops.socket
sudo install -m 0644 tools/systemd/ttvdrops.service /etc/systemd/system/ttvdrops.service

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now ttvdrops.socket
sudo systemctl enable --now ttvdrops.service

curl --unix-socket /run/ttvdrops/ttvdrops.sock https://ttvdrops.lovinator.space

Enable Celery worker and Beat services:

sudo install -m 0644 tools/systemd/ttvdrops-celery-worker.service /etc/systemd/system/
sudo install -m 0644 tools/systemd/ttvdrops-celery-beat.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now ttvdrops-celery-worker.service
sudo systemctl enable --now ttvdrops-celery-beat.service

Set TTVDROPS_PENDING_DIR in .env to the directory where Twitch JSON drop files are dropped:

TTVDROPS_PENDING_DIR=/mnt/fourteen/Data/Responses/pending

Development

uv run python manage.py createsuperuser
uv run python manage.py makemigrations
uv run python manage.py migrate
uv run python manage.py collectstatic
uv run python manage.py runserver
uv run pytest

Celery

Celery powers all periodic and background work. Three services are required:

Service file Queues Purpose
ttvdrops-celery-worker.service imports, api-fetches, default Twitch/Kick/Chzzk imports, backup
ttvdrops-celery-beat.service Periodic task scheduler (Beat)

Start workers manually during development:

# All-in-one worker (development)
uv run celery -A config worker --queues imports,api-fetches,image-downloads,default --loglevel=info

# Beat scheduler (requires database Beat tables — run migrate first)
uv run celery -A config beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --loglevel=info

# Monitor tasks in the browser (optional)
uv run celery -A config flower

Periodic tasks configured via CELERY_BEAT_SCHEDULE:

Task Schedule Queue
twitch.tasks.scan_pending_twitch_files every 10 s imports
kick.tasks.import_kick_drops :01/:16/:31/:46 api-fetches
chzzk.tasks.discover_chzzk_campaigns every 2 h api-fetches
twitch.tasks.backup_database daily 02:15 UTC default
twitch.tasks.download_all_images Sunday 04:00 UTC image-downloads
twitch.tasks.import_chat_badges Sunday 03:00 UTC api-fetches

Image downloads also run immediately on record creation via post_save signals (Game, DropCampaign, DropBenefit, RewardCampaign).

Import Drops

uv run python manage.py better_import_drops <file|dir> [--recursive] [--verbose] [--crash-on-error] [--skip-broken-moves]

Import Chat Badges

Import Twitch's global chat badges for archival and reference:

uv run python manage.py import_chat_badges

Requires TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET environment variables to be set.

Create DB Backup

Create a zstd-compressed SQL dump (only twitch_ tables) in the datasets directory:

uv run python manage.py backup_db

Optional arguments:

uv run python manage.py backup_db --output-dir "<path>" --prefix "ttvdrops"

How the duck does permissions work on Linux?

sudo chown -R ttvdrops:http /home/ttvdrops/.local/share/TTVDrops/media/
sudo find /home/ttvdrops/.local/share/TTVDrops/media -type d -exec chmod 2775 {} \;
sudo find /home/ttvdrops/.local/share/TTVDrops/media -type f -exec chmod 664 {} \;

sudo chown -R ttvdrops:http /home/ttvdrops/.local/share/TTVDrops/datasets/
sudo find /home/ttvdrops/.local/share/TTVDrops/datasets -type d -exec chmod 2775 {} \;
sudo find /home/ttvdrops/.local/share/TTVDrops/datasets -type f -exec chmod 664 {} \;