Initial commit: self-hosted personal radio station
Flask + React web UI with audio player, podcast queue, feed management, episode browser, music library, schedule viewer, and log tail. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Initialize the SQLite database for the local radio station."""
|
||||
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
DEFAULT_DB_PATH = Path("/opt/localradio/state/radio.db")
|
||||
|
||||
|
||||
def init_db(db_path: Path = DEFAULT_DB_PATH) -> None:
|
||||
db_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.executescript("""
|
||||
CREATE TABLE IF NOT EXISTS episodes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
feed_name TEXT NOT NULL,
|
||||
guid TEXT NOT NULL,
|
||||
title TEXT,
|
||||
url TEXT NOT NULL,
|
||||
pub_date TEXT,
|
||||
discovered TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
downloaded INTEGER NOT NULL DEFAULT 0,
|
||||
file_path TEXT,
|
||||
queued INTEGER NOT NULL DEFAULT 0,
|
||||
played INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE(feed_name, guid)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_episodes_feed
|
||||
ON episodes(feed_name);
|
||||
CREATE INDEX IF NOT EXISTS idx_episodes_queued
|
||||
ON episodes(queued);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS queue (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
episode_id INTEGER NOT NULL REFERENCES episodes(id),
|
||||
position INTEGER NOT NULL,
|
||||
enqueued TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
played INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE(episode_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS feed_state (
|
||||
feed_name TEXT PRIMARY KEY,
|
||||
last_poll TEXT,
|
||||
last_etag TEXT,
|
||||
last_modified TEXT
|
||||
);
|
||||
""")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"Database initialized at {db_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
path = Path(sys.argv[1]) if len(sys.argv) > 1 else DEFAULT_DB_PATH
|
||||
init_db(path)
|
||||
Reference in New Issue
Block a user