Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Pod Service

Podservice turns media URLs supported by yt-dlp into audio episodes and serves them through a podcast feed compatible with Apple Podcasts and other players.

Features

  • Flask web interface and REST API
  • Durable RabbitMQ-backed download jobs with confirmed publishing
  • Delayed retries and a dead-letter queue for failed downloads
  • Kafka download lifecycle events with a persistent dashboard projection
  • RabbitMQ, Kafka, and SQLite data-status dashboard at /status
  • Audio extraction through yt-dlp and ffmpeg
  • RSS 2.0 feed with iTunes extensions
  • Direct audio upload and episode management
  • Swagger API documentation at /apidocs/
  • Nix package plus NixOS and nix-darwin service modules

Requirements

  • Python 3.9 or newer
  • RabbitMQ
  • Kafka when lifecycle events are enabled
  • ffmpeg
  • yt-dlp

Quick start

Start RabbitMQ, then run the service from its Nix development environment:

make serve

Open http://localhost:8083, submit a media URL, and subscribe to http://localhost:8083/feed.xml.

API

Queue one URL:

curl -X POST http://localhost:8083/api/urls \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com/episode"}'

Queue several URLs:

curl -X POST http://localhost:8083/api/urls \
  -H 'Content-Type: application/json' \
  -d '{"urls":["https://example.com/one","https://example.com/two"]}'

The endpoint returns 202 Accepted after RabbitMQ confirms the persistent messages. Each accepted URL receives a job ID.

Upload an existing audio file:

curl -X POST http://localhost:8083/api/episodes \
  -F 'audio=@episode.mp3' \
  -F 'title=My Episode' \
  -F 'description=Episode description' \
  -F 'source_url=https://example.com/article'

Other endpoints:

  • GET /status — RabbitMQ queues, Kafka health and lag, SQLite, and recent events
  • GET /api/status — JSON form of the data status
  • GET /feed.xml — podcast feed
  • GET /audio/<filename> — audio files
  • GET /thumbnails/<filename> — thumbnails
  • GET /episodes — episode management
  • GET /apidocs/ — Swagger documentation

Configuration

The default configuration path is ~/.config/podservice/config.yaml on Linux and ~/Library/Application Support/podservice/config.yaml on macOS.

server:
  port: 8083
  host: "0.0.0.0"
  base_url: "http://localhost:8083"

podcast:
  title: "My Podcast"
  description: "Audio podcast episodes"
  author: "PodService"

storage:
  data_dir: "./data"
  audio_dir: "./data/audio"

rabbitmq:
  host: "127.0.0.1"
  port: 5672
  management_port: 15672
  username: "guest"
  password_file: null
  virtual_host: "/"
  exchange: "podservice.commands"
  queue: "podservice.downloads"
  routing_key: "download.requested"
  retry_delays: [30, 300, 1800]
  reconnect_delay: 5

kafka:
  enabled: false
  bootstrap_servers: ["127.0.0.1:9092"]
  topic: "podservice.lifecycle"
  consumer_group: "podservice-dashboard"
  client_id: "podservice"
  topic_partitions: 1
  topic_replication_factor: 1
  reconnect_delay: 5

log_level: "INFO"

Public mirror on Cloudflare R2

storage.s3 mirrors feed.xml, audio and thumbnails to an S3-compatible bucket for public-only clients (Overcast, Apple Podcasts). See config.example.yaml for all keys.

The mirror stays inside R2's free tier (10 GB storage, 1M class A and 10M class B operations per month) and never writes past a limit:

  • max_storage_bytes (default 9 GB): the whole bucket is measured on every sync. When new episodes don't fit, the oldest are dropped from the public feed and deleted from the bucket. The local library is untouched. One sync deletes at most max_cleanup_percent (default 10%) of the limit; a bigger cleanup pauses the mirror. Storage is checked at startup, on every feed change and every check_interval (default 3h). Deletes use single DeleteObject, which R2 does not charge.
  • max_class_a_operations (default 500k): every request the service sends is counted in a local ledger over a rolling 31 days before it goes out.
  • cloudflare_account_id + cloudflare_api_token_file (optional, token permission "Account Analytics: Read"): also checks account-wide storage and class A/B counts, the same numbers as the R2 dashboard. Reads by podcast clients are class B; the service only pauses on them, it cannot stop them.

/status and GET /api/status (s3 field) show usage per limit, mirrored and evicted episodes, and why the mirror is paused.

Architecture

flowchart TB
    subgraph Access
        direction LR
        Clients["Browser · API client · podcast app"] --> Caddy["Caddy"]
        Caddy --> Web["Podservice web · API · feed · media"]
    end

    subgraph Processing["Downloads and uploads"]
        direction LR
        Rabbit["RabbitMQ<br/>commands · retries · dead letters"] --> Consumer["Download consumer"]
        Consumer --> Worker["Download worker"]
        Worker --> Tools["yt-dlp + ffmpeg"]
        Tools --> Files["Audio · metadata · thumbnails"]
        Worker --> Feed["RSS feed"]
    end

    Web -->|"confirmed URL jobs"| Rabbit
    Web -->|"manual uploads"| Files
    Web -->|"uploaded episodes"| Feed

    subgraph Eventing["Lifecycle events"]
        direction LR
        SQLite["SQLite<br/>event store · outbox · dashboard model"] --> Outbox["Kafka outbox publisher"]
        Outbox --> Kafka["Kafka lifecycle topic"]
        Kafka --> Projection["Projection consumer"]
    end

    Web -. "download.requested" .-> SQLite
    Consumer -. "lifecycle events" .-> SQLite

    subgraph Observability
        direction LR
        Status["Data Status"]
        Kuma["Uptime Kuma"]
    end

    Rabbit -->|"queue health"| Status
    SQLite -->|"analytics"| Status
    Kafka -->|"topic and lag"| Status
    Caddy -. "HTTP" .-> Kuma
    Rabbit -. "TCP 5672" .-> Kuma
    Kafka -. "TCP 9092" .-> Kuma
Loading

RabbitMQ owns durable download commands and retry delivery. Kafka keeps the replayable lifecycle stream, while SQLite provides the persistent outbox and read model used by the Data Status page. The brokers and management endpoints can remain loopback-only when Podservice and monitoring run on the same host.

Processing flow

  1. The web interface or API publishes a DownloadJob to RabbitMQ.
  2. The consumer reserves one job at a time and downloads its URL with yt-dlp.
  3. Episode metadata is saved as JSON and the audio is stored under audio/.
  4. The episode is added to the in-memory feed and the message is acknowledged.
  5. Failed jobs wait 30 seconds, 5 minutes, and 30 minutes between attempts, then move to podservice.downloads.dead.
  6. When Kafka is enabled, requested, started, succeeded, failed, retry, and dead-letter lifecycle events are published to podservice.lifecycle.
  7. A consumer projects events into db/podservice.sqlite3 for the status dashboard; Kafka remains the replayable source of the event history.

Lifecycle events enter a SQLite outbox before Kafka publication. Broker outages leave events pending locally, and a background publisher retries them until Kafka acknowledges delivery. The status dashboard shows the pending outbox count.

Messages are persistent and publisher confirms are required before the API reports acceptance. Consumers use manual acknowledgements so an interrupted download remains available for another attempt.

Episode metadata uses source_url and remains compatible with legacy youtube_url records:

{
  "title": "Episode Title",
  "description": "...",
  "audio_file": "/path/to/audio.mp3",
  "audio_url": "http://localhost:8083/audio/file.mp3",
  "pub_date": "2025-12-21T10:00:00",
  "duration": 3600,
  "file_size": 12345678,
  "source_url": "https://original-source-url",
  "image_url": "http://localhost:8083/thumbnails/thumb.jpg"
}

Project structure

podservice/
├── cli.py          # Click CLI
├── config.py       # YAML configuration
├── daemon.py       # Process lifecycle
├── downloader.py   # yt-dlp integration
├── episodes.py     # Download/feed coordination
├── events.py       # Kafka lifecycle events and SQLite projection
├── feed.py         # RSS feed and episode model
├── messaging.py    # RabbitMQ jobs, topology, publisher, and consumer
├── server.py       # Flask web interface and API
├── status.py       # Read-only RabbitMQ status probe
└── utils.py        # Shared utilities

The main classes are PodService, PodcastServer, EpisodeService, MediaDownloader, PodcastFeed, RabbitMQPublisher, and RabbitMQConsumer.

Development

make serve   # Run with config.example.yaml
make info    # Show resolved configuration
make test    # Run the test suite
make format  # Format and lint Python files
make architecture       # Generate architecture SVG, PNG, and HTML under /tmp
make architecture-open  # Generate and open the full-screen viewer
make dev     # Enter the Nix development shell

Direct CLI equivalents:

podservice serve --config config.example.yaml
podservice init
podservice info --config config.example.yaml

Deployment

The flake exports the podservice package through packages, the NixOS module through nixosModules.default, and the nix-darwin module through darwinModules.default. See DEPLOYMENT.md for configuration and service-management examples.

Troubleshooting

  • Check the /status dashboard and podservice, RabbitMQ, and Kafka logs when jobs or lifecycle events are not being processed.
  • Inspect podservice.downloads.dead for jobs that exhausted their retries.
  • Check the audio/ and metadata/ directories when the feed is missing an episode.
  • Run ffmpeg -version and yt-dlp <url> from the development shell when a source cannot be downloaded.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages