Archived
Arkivera VideoVault från laptop till SIAX-flottan
Kod från /home/simon/Documents/Default Project/videovault (Python: yt-dlp + ffmpeg + SQLite FTS5 + Meilisearch + FastAPI). Runtime-data (.venv, data/, watch/, *.db, meili-data) exkluderad. Utökad .gitignore (secrets/cookies/media), referenskopior av systemd-user-units i deploy/systemd/, README-sektion Driftsläge: appen saknar auth och får inte exponeras utan auth. Ej deployad. Laptop-tjänsterna vv-web/vv-worker är avaktiverade. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
VV_DATA=./data
|
||||
VV_WATCH=./watch
|
||||
VV_QUALITY=best
|
||||
OPTIMIZE=1
|
||||
MEILI_URL=http://127.0.0.1:7700
|
||||
MEILI_KEY=devkey
|
||||
MEILI_DISABLE=0
|
||||
AUDIO_BITRATE=128K
|
||||
VIDEO_CRF=22
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
# Python / venv
|
||||
.venv/
|
||||
venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Runtime-data (skapas av app/config.py vid start) — ALDRIG i git
|
||||
data/
|
||||
watch/
|
||||
meili-data/
|
||||
*.db
|
||||
*.db-*
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# Hemligheter / lokala inställningar
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
cookies.txt
|
||||
*cookies*.txt
|
||||
*.netrc
|
||||
*.pem
|
||||
*.key
|
||||
|
||||
# yt-dlp-/ffmpeg-artefakter
|
||||
*.info.json
|
||||
*.part
|
||||
*.ytdl
|
||||
*.jpg
|
||||
*.webp
|
||||
*.mp4
|
||||
*.mkv
|
||||
*.webm
|
||||
@@ -0,0 +1,41 @@
|
||||
SHELL := /bin/bash
|
||||
PY := .venv/bin/python
|
||||
PIP := .venv/bin/pip
|
||||
|
||||
.PHONY: setup venv deps db meili web ingest worker daemon watch clean
|
||||
|
||||
setup: venv deps db
|
||||
|
||||
venv:
|
||||
python3 -m venv .venv
|
||||
|
||||
deps:
|
||||
$(PIP) install --upgrade pip
|
||||
$(PIP) install -r requirements.txt
|
||||
|
||||
db:
|
||||
$(PY) -m app.ingest init
|
||||
|
||||
meili:
|
||||
docker compose up -d meilisearch
|
||||
|
||||
web:
|
||||
.venv/bin/uvicorn app.web.main:app --host 0.0.0.0 --port 8080 --reload
|
||||
|
||||
ingest:
|
||||
$(PY) -m app.ingest add "$(URL)"
|
||||
|
||||
watch:
|
||||
$(PY) -m app.ingest watch
|
||||
|
||||
worker:
|
||||
$(PY) -m app.ingest run
|
||||
|
||||
daemon:
|
||||
$(PY) -m app.ingest daemon
|
||||
|
||||
serve:
|
||||
$(PY) -m app.ingest serve
|
||||
|
||||
clean:
|
||||
rm -rf .venv data/media/* data/optimized/* meili
|
||||
@@ -0,0 +1,108 @@
|
||||
# VideoVault
|
||||
|
||||
Lokal kuratering, optimering och sök för ditt videobibliotek (endast laglig
|
||||
adult-innehåll, 18+). Länkar du klistrar in laddas hem reklamfritt, transkoderas
|
||||
till web-vänlig MP4, kategoriseras automatiskt (fokus: Teen 18+, Skinny,
|
||||
Petite, Bondage + sub-nischer), får thumbnails/previews och indexeras för
|
||||
världsklass-sök.
|
||||
|
||||
## Stack
|
||||
- **Python** — pipeline (nedladdning → transkod → kategorisering)
|
||||
- **yt-dlp + ffmpeg** — hämtning & H.264/AAC-optimering (streamad, faststart)
|
||||
- **SQLite (FTS5)** — lokalt index (sök funkar även offline)
|
||||
- **Meilisearch** (Docker) — fuzzysök, typo-tålig, blixtsnabb (valfri, fallback FTS)
|
||||
- **FastAPI + Jinja2** — lokal webb-UI med kort-flöde, hover-previews och kategorier
|
||||
|
||||
## Snabbstart
|
||||
```bash
|
||||
./vv.sh setup # venv + deps + db + meilisearch
|
||||
./vv.sh start # web (port 8080) + worker (autostart via systemd)
|
||||
# eller bara:
|
||||
./vv.sh web # frontend i förgrund
|
||||
./vv.sh worker # consumer i förgrund
|
||||
```
|
||||
|
||||
## Lägga till video
|
||||
- **UI:** plustecknet uppe till höger → klistra in en URL → "Köa och ladda ner"
|
||||
- **watch-mappen:** lägg en `.url`- eller `.txt`-fil i `watch/` med en länk per
|
||||
rad, kör sedan `./vv.sh watch` (worker tar automatisk bort filen när den är läst).
|
||||
- **CLI:** `./vv.sh add https://…`
|
||||
|
||||
## Flöde (per jobb)
|
||||
```
|
||||
new → (watch/UI) → queued → downloading → downloaded → transcoding
|
||||
→ kategorisera & tagga → ready → indexera (FTS + Meilisearch)
|
||||
fel → failed (visas i UI, kan analyseras i DB)
|
||||
```
|
||||
|
||||
Vid nedladdning sparas källfilen (första kvaliteten), sedan görs:
|
||||
- **optimized** — MP4 H.264 CRF22 + AAC 128K, max 1080p, `+faststart`
|
||||
- **poster** (1280) / **thumb** (480) / **preview** (10s, 848px, mute)
|
||||
- **kategorier** — Teen 18+/Skinny/Petite/Bondage + sub-nischer + aktivitet +
|
||||
längd + kanal + upplösning
|
||||
- **tags** — alla träffande etiketter ur regelverket
|
||||
|
||||
## Struktur
|
||||
```
|
||||
app/
|
||||
downloader.py yt-dlp-hämtning
|
||||
transcode.py ffmpeg-optimering + artifacts
|
||||
categorize.py nisch-regler (redigera gärna)
|
||||
pipeline.py orkestrerare
|
||||
worker.py daemon-lopp
|
||||
search.py Meilisearch-klient med fallback
|
||||
db.py SQLite/FTS5-lager
|
||||
web/ FastAPI + Jinja2 + CSS/JS
|
||||
watch/ drop-in-länkar (*.url / *.txt)
|
||||
data/ media/ optimized/ videos.db (+meili i docker)
|
||||
```
|
||||
|
||||
## Konfiguration (`.env`)
|
||||
| Variabel | Default | Betydelse |
|
||||
|---|---|---|
|
||||
| `VV_QUALITY` | `best` | yt-dlp-format |
|
||||
| `OPTIMIZE` | `1` | kör ffmpeg-transkod |
|
||||
| `MEILI_URL/KEY` | `http://127.0.0.1:7700` / `devkey` | sök |
|
||||
| `MEILI_DISABLE` | `0` | av meilisearch (använd FTS) |
|
||||
| `VIDEO_CRF` | `22` | kvalitet H.264 |
|
||||
| `AUDIO_BITRATE` | `128K` | ljudhastighet |
|
||||
|
||||
## Drift
|
||||
- `./vv.sh status` — kolla tjänster + health
|
||||
- Web + worker är systemd-laddade (`vv-web`, `vv-worker`) och startar om vid boot.
|
||||
- Meilisearch-data ligger i `data/meili` (Docker-volym).
|
||||
- Referenskopior av de systemd-user-units som användes på laptopen finns i
|
||||
`deploy/systemd/` (sökvägar pekar på den gamla laptop-katalogen — justera
|
||||
`WorkingDirectory`/`ExecStart` innan de används någon annanstans).
|
||||
|
||||
## Driftsläge
|
||||
|
||||
**Status (2026-09-17): ARKIVERAD — ej deployad, ej i drift.**
|
||||
|
||||
- Koden arkiverades från laptopen till Gitea (`sax3l/videovault`, privat) så att
|
||||
inget är laptop-unikt. Laptop-tjänsterna (`vv-web`, `vv-worker`) är stoppade
|
||||
och avaktiverade; ingen flottdeploy (Coolify/server) finns.
|
||||
- Vid arkiveringstillfället fanns 0 videor, tomt Meilisearch-index och tom
|
||||
`watch/`. Runtime-data (`data/`, `watch/`, `.venv/`, `*.db`, Meilisearch-data)
|
||||
ingår **inte** i repot.
|
||||
|
||||
### Säkerhet — får INTE exponeras utan autentisering
|
||||
|
||||
- Webb-UI:t (FastAPI) har **ingen autentisering och ingen auktorisering**.
|
||||
- `app.ingest serve` binder `0.0.0.0:8080` och Makefile-målet `web` binder
|
||||
`--host 0.0.0.0` — alltså alla nätverksinterface, inte bara localhost.
|
||||
- `POST /add` köar godtyckliga URL:er som workern hämtar med **yt-dlp**
|
||||
(server-side fetch mot valfri URL → SSRF-/missbruksrisk, disk-/bandbredds-DoS).
|
||||
- `POST /video/{id}/delete` raderar media och `GET /reindex` triggar omindexering
|
||||
— utan någon åtkomstkontroll.
|
||||
- Meilisearch körs med `MEILI_ENV: development` och en default-nyckel om
|
||||
`MEILI_KEY` inte sätts.
|
||||
|
||||
Innan appen körs någon annanstans än strikt lokalt (bind `127.0.0.1`) krävs minst:
|
||||
1. Autentisering framför hela UI:t (t.ex. Zitadel/OIDC via reverse proxy
|
||||
eller SSO-forward-auth) — aldrig publik FQDN utan auth.
|
||||
2. URL-allowlist/validering för `/add` (blockera interna/privata adresser).
|
||||
3. CSRF-skydd på POST-rutterna och bind till `127.0.0.1` eller privat nät.
|
||||
4. Riktig `MEILI_KEY` ur hemlighetshanteraren och `MEILI_ENV=production`.
|
||||
|
||||
Hemligheter (`.env`, yt-dlp `cookies.txt`) får aldrig committas — se `.gitignore`.
|
||||
@@ -0,0 +1,209 @@
|
||||
# Kategoriserare fokuserad på primärnischerna:
|
||||
# Teen 18+, Skinny, Petite, Bondage (+ särskilda beteenden).
|
||||
# Allt innehåll hålls strikt till legal adult-18+-kategorier.
|
||||
|
||||
import re
|
||||
|
||||
PRIMARY_KEYS = {
|
||||
"teen18": {"keywords": ["teen", "18", "18yo", "18year", "18+", "schoolgirl",
|
||||
"school", "college", "university", "firstlegal",
|
||||
"brat", "bratty"],
|
||||
"label": "Teen 18+"},
|
||||
"petite": {"keywords": ["petite", "tiny", "slim", "slender"],
|
||||
"label": "Petite"},
|
||||
"skinny": {"keywords": ["skinny", "thin", "bony", "wispy", "flatchested"],
|
||||
"label": "Skinny"},
|
||||
"bondage": {"keywords": ["bondage", "shibari", "kinbaku", "rope", "tie",
|
||||
"tied", "suspension", "shackle", "collar",
|
||||
"leashed", "restrain", "handcuff", "gag",
|
||||
"ballgag", "blindfold", "petplay", "hogtie",
|
||||
"ropeplay", "strapped"],
|
||||
"label": "Bondage"},
|
||||
}
|
||||
|
||||
SUB_RULES = {
|
||||
"teen18": [
|
||||
("uniform", "Uniform"),
|
||||
("school", "Skoluniform"),
|
||||
("sailor", "Sjäuniform"),
|
||||
("maid", "Maid"),
|
||||
("nurse", "Sjuksköterska"),
|
||||
("cute", "Söt"),
|
||||
("spicy", "Piffig"),
|
||||
("firsttime", "Första gången"),
|
||||
("firstanal", "Första anal"),
|
||||
("firstorgasm", "Första orgasm"),
|
||||
("18", "Fyllda 18"),
|
||||
("birthday", "Födelsedag"),
|
||||
("highschool", "HS"),
|
||||
("student", "Student"),
|
||||
("aunt", "Moster"),
|
||||
("teacher", "Lärare"),
|
||||
("american", "Amerikansk"),
|
||||
("european", "Europeisk"),
|
||||
("asian", "Asiatisk"),
|
||||
],
|
||||
"petite": [
|
||||
("stockings", "Strumpbyxor"),
|
||||
("pantyhose", "Pantyhose"),
|
||||
("nylons", "Nylons"),
|
||||
("socks", "Sockar"),
|
||||
("ankles", "Anklar"),
|
||||
("waist", "Smal midja"),
|
||||
("outfit", "Outfit"),
|
||||
("boots", "Boots"),
|
||||
("kneehigh", "Knähöga"),
|
||||
("tinywaist", "Smal midja"),
|
||||
],
|
||||
"skinny": [
|
||||
("flat", "Platt bröstkorg"),
|
||||
("mini", "Mini"),
|
||||
("petite", "Petite"),
|
||||
("narrow", "Smal"),
|
||||
("little", "Liten"),
|
||||
],
|
||||
"bondage": [
|
||||
("shibari", "Shibari"),
|
||||
("kinbaku", "Kinbaku"),
|
||||
("rope", "Rep"),
|
||||
("strapped", "Reger"),
|
||||
("suspension", "Suspension"),
|
||||
("hogtie", "Hogtie"),
|
||||
("spread", "Spret"),
|
||||
("anklecuffs", "Ankelko"),
|
||||
("ballgag", "Ballgag"),
|
||||
("gag", "Gag"),
|
||||
("blindfold", "Blindfold"),
|
||||
("mask", "Mask"),
|
||||
("cotton", "Bomull"),
|
||||
("chain", "Kedja"),
|
||||
("stick", "Stick"),
|
||||
("vacuum", "Vacuum"),
|
||||
("mummifier", "Mummification"),
|
||||
("spanking", "Spanking"),
|
||||
("flog", "Flogger"),
|
||||
("whip", "Whip"),
|
||||
("crops", "Crops"),
|
||||
("predic", "Predicament"),
|
||||
("endurance", "Endurance"),
|
||||
("struggl", "Struggle"),
|
||||
],
|
||||
}
|
||||
|
||||
ACTIVITY_RULES = {
|
||||
"solo": ("Solo", "Solo"),
|
||||
"masturb": ("Solo", "Masturbation"),
|
||||
"nude": ("Nude", "Nude"),
|
||||
"tease": ("Tease", "Tease"),
|
||||
"strip": ("Tease", "Strip"),
|
||||
"dance": ("Tease", "Dance"),
|
||||
"handjob": ("Handjob", "Handjob"),
|
||||
"blowjob": ("Oral", "Blowjob"),
|
||||
"oral": ("Oral", "Oral"),
|
||||
"deepthroat": ("Oral", "Deep throat"),
|
||||
"pov": ("POV", "POV"),
|
||||
"cowgirl": ("Ridning", "Cowgirl"),
|
||||
"reverse": ("Ridning", "Reverse cowgirl"),
|
||||
"doggy": ("Doggy", "Doggy"),
|
||||
"anal": ("Anal", "Anal"),
|
||||
"dp": ("Anal", "DP"),
|
||||
"creampie": ("Creampie", "Creampie"),
|
||||
"threesome": ("Grupp", "Threesome"),
|
||||
"gangbang": ("Grupp", "Gangbang"),
|
||||
"orgy": ("Grupp", "Orgi"),
|
||||
"lesbian": ("Lesbian", "Lesbian"),
|
||||
"cam": ("Webcam", "Webcam"),
|
||||
"public": ("Public", "Public"),
|
||||
"outdoor": ("Public", "Outdoor"),
|
||||
"voyeur": ("Voyeur", "Voyeur"),
|
||||
"hidden": ("Voyeur", "Hidden cam"),
|
||||
"wet": ("Wet", "Wet"),
|
||||
"lingerie": ("Lingerie", "Lingerie"),
|
||||
"bikini": ("Lingerie", "Bikini"),
|
||||
"cosplay": ("Cosplay", "Cosplay"),
|
||||
"anime": ("Cosplay", "Anime"),
|
||||
}
|
||||
|
||||
|
||||
def _norm(s):
|
||||
s = (s or "").lower()
|
||||
s = re.sub(r"[^a-z0-9 ]", "", s)
|
||||
s = re.sub(r"\s+", " ", s).strip()
|
||||
return s
|
||||
|
||||
|
||||
def _has_any(text, kws):
|
||||
t = _norm(text)
|
||||
return any(_norm(k) in t for k in kws)
|
||||
|
||||
|
||||
def duration_bucket(duration):
|
||||
if not duration:
|
||||
return None
|
||||
if duration < 300:
|
||||
return "Längd: kort"
|
||||
if duration < 2100:
|
||||
return "Längd: medel"
|
||||
return "Längd: lång"
|
||||
|
||||
|
||||
def categorize(meta, height=None, duration=None, site=None):
|
||||
title = _norm(meta.get("title") or "")
|
||||
tags = [_norm(t) for t in (meta.get("meta_tags") or [])]
|
||||
hay = f"{title} {' '.join(tags)}"
|
||||
|
||||
# primära nischer
|
||||
primary = []
|
||||
for key, spec in PRIMARY_KEYS.items():
|
||||
if _has_any(hay, spec["keywords"]):
|
||||
primary.append(spec["label"])
|
||||
|
||||
# sub-nischer (max en per primärgrupp)
|
||||
subs = []
|
||||
for key, rules in SUB_RULES.items():
|
||||
p = PRIMARY_KEYS[key]["label"]
|
||||
if p not in primary:
|
||||
continue
|
||||
for kw, label in rules:
|
||||
if _has_any(hay, [kw]):
|
||||
subs.append(f"{p} > {label}")
|
||||
break
|
||||
|
||||
# aktivitet = endast rena akter (utan dubbel mot primärer)
|
||||
acts = []
|
||||
for key, (cat, label) in ACTIVITY_RULES.items():
|
||||
if _has_any(hay, [key]):
|
||||
acts.append(label)
|
||||
# bara akter som INTE redan är en primär/sub-etikett
|
||||
skip = set(primary) | {s.split(" > ")[1] for s in subs}
|
||||
acts = [a for a in dict.fromkeys(acts) if a not in skip]
|
||||
|
||||
cats = list(dict.fromkeys(primary))
|
||||
for sub in subs:
|
||||
if sub not in cats:
|
||||
cats.append(sub)
|
||||
cats.extend(a for a in acts if a not in cats)
|
||||
bucket = duration_bucket(duration)
|
||||
if bucket:
|
||||
cats.append(bucket)
|
||||
if site:
|
||||
cats.append(f"Kanal: {site}")
|
||||
if height:
|
||||
cats.append(f"{height}p")
|
||||
|
||||
# tags = alla matchnande etiketter (sub + aktivitet + primära)
|
||||
t = set()
|
||||
for kws in SUB_RULES.values():
|
||||
for kw, label in kws:
|
||||
if _has_any(hay, [kw]):
|
||||
t.add(label)
|
||||
for key, (cat, label) in ACTIVITY_RULES.items():
|
||||
if _has_any(hay, [key]):
|
||||
t.add(label)
|
||||
for key, spec in PRIMARY_KEYS.items():
|
||||
if _has_any(hay, spec["keywords"]):
|
||||
t.add(spec["label"])
|
||||
if site:
|
||||
t.add(f"kanal:{site}")
|
||||
|
||||
return cats, sorted(t)
|
||||
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
BASE = Path(__file__).resolve().parent.parent
|
||||
|
||||
DATA = Path(os.getenv("VV_DATA", BASE / "data"))
|
||||
WATCH = Path(os.getenv("VV_WATCH", BASE / "watch"))
|
||||
MEDIA = DATA / "media"
|
||||
OPTIMIZED = DATA / "optimized"
|
||||
META = DATA / "meta"
|
||||
DB_PATH = DATA / "videos.db"
|
||||
|
||||
MEILI_URL = os.getenv("MEILI_URL", "http://127.0.0.1:7700")
|
||||
MEILI_KEY = os.getenv("MEILI_KEY", "devkey")
|
||||
MEILI_DISABLE = os.getenv("MEILI_DISABLE", "0") == "1"
|
||||
|
||||
OPTIMIZE = os.getenv("OPTIMIZE", "1") == "1"
|
||||
AUDIO_BITRATE = os.getenv("AUDIO_BITRATE", "128K")
|
||||
VIDEO_CRF = os.getenv("VIDEO_CRF", "22")
|
||||
FFMPEG = os.getenv("FFMPEG", "ffmpeg")
|
||||
FFPROBE = os.getenv("FFPROBE", "ffprobe")
|
||||
MAX_WIDTH = int(os.getenv("MAX_WIDTH", "1920"))
|
||||
|
||||
STATUSES = ("queued", "downloading", "downloaded", "transcoding", "ready", "failed")
|
||||
|
||||
for p in (DATA, WATCH, MEDIA, OPTIMIZED, META):
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
@@ -0,0 +1,228 @@
|
||||
import sqlite3
|
||||
from . import config
|
||||
|
||||
SCHEMA = """
|
||||
CREATE TABLE IF NOT EXISTS videos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
url TEXT UNIQUE NOT NULL,
|
||||
site TEXT,
|
||||
title TEXT,
|
||||
description TEXT,
|
||||
uploader TEXT,
|
||||
tags TEXT DEFAULT '',
|
||||
categories TEXT DEFAULT '',
|
||||
duration INTEGER,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
size_bytes INTEGER,
|
||||
quality TEXT,
|
||||
status TEXT DEFAULT 'queued',
|
||||
error TEXT,
|
||||
download_path TEXT,
|
||||
optimized_path TEXT,
|
||||
poster_path TEXT,
|
||||
thumb_path TEXT,
|
||||
preview_path TEXT,
|
||||
published_at TEXT,
|
||||
added_at TEXT DEFAULT (datetime('now')),
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS videos_fts USING fts5(
|
||||
title, description, uploader, tags, categories,
|
||||
content='videos', content_rowid='id',
|
||||
tokenize='porter unicode61'
|
||||
);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS videos_ai AFTER INSERT ON videos BEGIN
|
||||
INSERT INTO videos_fts(rowid, title, description, uploader, tags, categories)
|
||||
VALUES (new.id, new.title, new.description, new.uploader, new.tags, new.categories);
|
||||
END;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS videos_ad AFTER DELETE ON videos BEGIN
|
||||
INSERT INTO videos_fts(videos_fts, rowid, title, description, uploader, tags, categories)
|
||||
VALUES ('delete', old.id, old.title, old.description, old.uploader, old.tags, old.categories);
|
||||
END;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS videos_au AFTER UPDATE ON videos BEGIN
|
||||
INSERT INTO videos_fts(videos_fts, rowid, title, description, uploader, tags, categories)
|
||||
VALUES ('delete', old.id, old.title, old.description, old.uploader, old.tags, old.categories);
|
||||
INSERT INTO videos_fts(rowid, title, description, uploader, tags, categories)
|
||||
VALUES (new.id, new.title, new.description, new.uploader, new.tags, new.categories);
|
||||
END;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_status ON videos(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_site ON videos(site);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_updated ON videos(updated_at DESC);
|
||||
"""
|
||||
|
||||
|
||||
def connect():
|
||||
conn = sqlite3.connect(config.DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.execute("PRAGMA foreign_keys=ON")
|
||||
conn.execute("PRAGMA journal_mode=WAL")
|
||||
return conn
|
||||
|
||||
|
||||
def init():
|
||||
conn = connect()
|
||||
conn.executescript(SCHEMA)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def add_job(url):
|
||||
conn = connect()
|
||||
conn.execute("INSERT OR IGNORE INTO videos(url) VALUES (?)", (url,))
|
||||
conn.commit()
|
||||
row = conn.execute("SELECT id FROM videos WHERE url=?", (url,)).fetchone()
|
||||
conn.close()
|
||||
return row["id"]
|
||||
|
||||
|
||||
def get(id):
|
||||
conn = connect()
|
||||
row = conn.execute("SELECT * FROM videos WHERE id=?", (id,)).fetchone()
|
||||
conn.close()
|
||||
return dict(row) if row else None
|
||||
|
||||
|
||||
def set_status(id, status, error=None):
|
||||
conn = connect()
|
||||
conn.execute(
|
||||
"UPDATE videos SET status=?, error=?, updated_at=datetime('now') WHERE id=?",
|
||||
(status, error, id),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def update_meta(id, **kw):
|
||||
keys = [k for k in kw if k in SCHEMA_COLUMNS]
|
||||
if not keys:
|
||||
return
|
||||
cols = ", ".join(f"{k}=?" for k in keys)
|
||||
conn = connect()
|
||||
conn.execute(
|
||||
f"UPDATE videos SET {cols}, updated_at=datetime('now') WHERE id=?",
|
||||
[kw[k] for k in keys] + [id],
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
SCHEMA_COLUMNS = set(
|
||||
"""
|
||||
url site title description uploader tags categories duration width height
|
||||
size_bytes quality status error download_path optimized_path poster_path
|
||||
thumb_path preview_path published_at
|
||||
""".split()
|
||||
)
|
||||
|
||||
|
||||
def queued(limit=4):
|
||||
conn = connect()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM videos WHERE status IN ('queued','downloading','downloaded','transcoding') "
|
||||
"ORDER BY id LIMIT ?",
|
||||
(limit,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def list_videos(limit=60, offset=0, status="ready", category=None, tag=None, q=None, order="added_at DESC"):
|
||||
where, params = ["status=?"], [status]
|
||||
if category:
|
||||
like = f"%{category}%"
|
||||
where.append("categories LIKE ?")
|
||||
params.append(like)
|
||||
if tag:
|
||||
like = f"%{tag}%"
|
||||
where.append("(tags LIKE ? OR uploader LIKE ? OR title LIKE ?)")
|
||||
params.extend([like, like, like])
|
||||
if q:
|
||||
ids = search_fts(q, 500)
|
||||
if not ids:
|
||||
return [], 0
|
||||
placeholders = ",".join("?" for _ in ids)
|
||||
where.append(f"id IN ({placeholders})")
|
||||
params.extend(ids)
|
||||
conn = connect()
|
||||
valid_orders = {"added_at DESC", "added_at ASC", "title ASC", "duration DESC", "updated_at DESC"}
|
||||
order = order if order in valid_orders else "added_at DESC"
|
||||
sql = (
|
||||
f"SELECT * FROM videos WHERE {' AND '.join(where)} "
|
||||
f"ORDER BY {order} LIMIT ? OFFSET ?"
|
||||
)
|
||||
cur = conn.execute(sql, params + [limit, offset])
|
||||
rows = cur.fetchall()
|
||||
total = conn.execute(
|
||||
f"SELECT COUNT(*) c FROM videos WHERE {' AND '.join(where)}", params
|
||||
).fetchone()["c"]
|
||||
return [dict(r) for r in rows], total
|
||||
|
||||
|
||||
def search_fts(q, limit=200):
|
||||
conn = connect()
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"SELECT rowid FROM videos_fts WHERE videos_fts MATCH ? ORDER BY rank LIMIT ?",
|
||||
(q, limit),
|
||||
).fetchall()
|
||||
return [r["rowid"] for r in rows]
|
||||
except sqlite3.OperationalError:
|
||||
return []
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def stats(conn):
|
||||
total = conn.execute("SELECT COUNT(*) c FROM videos").fetchone()["c"]
|
||||
ready = conn.execute("SELECT COUNT(*) c FROM videos WHERE status='ready'").fetchone()["c"]
|
||||
failed = conn.execute("SELECT COUNT(*) c FROM videos WHERE status='failed'").fetchone()["c"]
|
||||
q = conn.execute("SELECT COUNT(*) c FROM videos WHERE status!='ready' AND status!='failed'").fetchone()["c"]
|
||||
recent = conn.execute("SELECT published_at FROM videos WHERE status='ready' ORDER BY updated_at DESC LIMIT 1").fetchone()
|
||||
return {"total": total, "ready": ready, "failed": failed, "queued": q,
|
||||
"last": recent["published_at"] if recent else None}
|
||||
|
||||
|
||||
def categories(conn, limit=100):
|
||||
rows = conn.execute(
|
||||
"SELECT categories FROM videos WHERE status='ready' AND categories!=''"
|
||||
).fetchall()
|
||||
counts = {}
|
||||
for r in rows:
|
||||
for c in (r["categories"] or "").split(","):
|
||||
c = c.strip()
|
||||
if c:
|
||||
counts[c] = counts.get(c, 0) + 1
|
||||
items = sorted(counts.items(), key=lambda kv: -kv[1])
|
||||
return [{"name": n, "count": c} for n, c in items[:limit]]
|
||||
|
||||
|
||||
def tags_for(conn, limit=120):
|
||||
rows = conn.execute("SELECT tags FROM videos WHERE status='ready' AND tags!=''").fetchall()
|
||||
counts = {}
|
||||
for r in rows:
|
||||
for t in (r["tags"] or "").split(","):
|
||||
t = t.strip()
|
||||
if t:
|
||||
counts[t] = counts.get(t, 0) + 1
|
||||
items = sorted(counts.items(), key=lambda kv: -kv[1])
|
||||
return [{"name": n, "count": c} for n, c in items[:limit]]
|
||||
|
||||
|
||||
def delete_video(id):
|
||||
conn = connect()
|
||||
row = conn.execute("SELECT * FROM videos WHERE id=?", (id,)).fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
return None
|
||||
files = [row["download_path"], row["optimized_path"], row["poster_path"],
|
||||
row["thumb_path"], row["preview_path"]]
|
||||
conn.execute("DELETE FROM videos WHERE id=?", (id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return files
|
||||
@@ -0,0 +1,55 @@
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
from . import config, db
|
||||
|
||||
import yt_dlp
|
||||
|
||||
|
||||
def domain(url):
|
||||
host = urlparse(url).netloc or ""
|
||||
host = re.sub(r"^www\.", "", host)
|
||||
parts = host.split(".")
|
||||
return parts[-2] if len(parts) >= 2 else host
|
||||
|
||||
|
||||
def download(url, vid_id):
|
||||
outtmpl = str(config.MEDIA / f"{vid_id}.%(ext)s")
|
||||
opts = {
|
||||
"outtmpl": outtmpl,
|
||||
"format": "bestvideo*+bestaudio/best",
|
||||
"merge_output_format": "mp4",
|
||||
"writethumbnail": True,
|
||||
"writeinfojson": False,
|
||||
"noprogress": True,
|
||||
"no_color": True,
|
||||
"retries": 3,
|
||||
"concurrent_fragment_downloads": 4,
|
||||
"noplaylist": True,
|
||||
}
|
||||
with yt_dlp.YoutubeDL(opts) as ydl:
|
||||
info = ydl.extract_info(url, download=True)
|
||||
|
||||
src = info.get("requested_downloads") or []
|
||||
src = src[0].get("filepath") if src else ydl.prepare_filename(info)
|
||||
|
||||
final = config.MEDIA / f"{vid_id}.mp4"
|
||||
if src and str(src) != str(final):
|
||||
import shutil
|
||||
|
||||
shutil.move(src, final)
|
||||
|
||||
duration = info.get("duration")
|
||||
idx = info.get("webpage_url_domain", "")
|
||||
meta = {
|
||||
"url": url,
|
||||
"site": domain(url),
|
||||
"title": info.get("title"),
|
||||
"description": info.get("description"),
|
||||
"uploader": info.get("uploader") or info.get("channel"),
|
||||
"duration": duration,
|
||||
"published_at": info.get("upload_date"),
|
||||
"meta_tags": info.get("tags") or [],
|
||||
"download_path": str(final),
|
||||
"size_bytes": final.stat().st_size if final.exists() else None,
|
||||
}
|
||||
return meta
|
||||
@@ -0,0 +1,85 @@
|
||||
import argparse
|
||||
import sys
|
||||
import time
|
||||
|
||||
from . import config, db
|
||||
from .worker import run_once, daemon
|
||||
|
||||
|
||||
def cmd_init(_args):
|
||||
db.init()
|
||||
print("Databas redo:", config.DB_PATH)
|
||||
|
||||
|
||||
def cmd_add(args):
|
||||
db.init()
|
||||
for url in args.url:
|
||||
vid = db.add_job(url)
|
||||
print(f"Köad {vid}: {url}")
|
||||
|
||||
|
||||
def cmd_watch(args):
|
||||
db.init()
|
||||
n = import_watch()
|
||||
print(f"Importerade {n} länk(er) ur watch-katalogen")
|
||||
|
||||
|
||||
def import_watch():
|
||||
"""Läser watch/*.url och *.txt, köar varje rad, raderar filen efteråt."""
|
||||
db.init()
|
||||
files = sorted(config.WATCH.glob("*.url")) + sorted(config.WATCH.glob("*.txt"))
|
||||
added = 0
|
||||
for f in files:
|
||||
text = f.read_text()
|
||||
try:
|
||||
for line in text.splitlines():
|
||||
url = line.strip()
|
||||
if url and not url.startswith("#"):
|
||||
db.add_job(url)
|
||||
added += 1
|
||||
f.unlink(missing_ok=True)
|
||||
except Exception:
|
||||
pass
|
||||
return added
|
||||
|
||||
|
||||
def cmd_run(args):
|
||||
db.init()
|
||||
n = run_once()
|
||||
if n == 0:
|
||||
print("Inget i kön.")
|
||||
|
||||
|
||||
def cmd_daemon(args):
|
||||
db.init()
|
||||
print("Worker körs (Ctrl-C för att stoppa)")
|
||||
daemon()
|
||||
|
||||
|
||||
def cmd_serve(args):
|
||||
import uvicorn
|
||||
|
||||
db.init()
|
||||
uvicorn.run("app.web.main:app", host="0.0.0.0", port=8080, reload=False)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
p = argparse.ArgumentParser(prog="videovault")
|
||||
sub = p.add_subparsers(dest="cmd", required=True)
|
||||
sub.add_parser("init")
|
||||
a = sub.add_parser("add")
|
||||
a.add_argument("url", nargs="+")
|
||||
sub.add_parser("watch")
|
||||
sub.add_parser("run")
|
||||
sub.add_parser("daemon")
|
||||
sub.add_parser("serve")
|
||||
args = p.parse_args(argv)
|
||||
{"init": cmd_init, "add": cmd_add, "watch": cmd_watch,
|
||||
"run": cmd_run, "daemon": cmd_daemon, "serve": cmd_serve}[args.cmd](args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
sys.exit(0)
|
||||
@@ -0,0 +1,85 @@
|
||||
import traceback
|
||||
|
||||
from . import config, db
|
||||
from . import downloader, transcode, categorize
|
||||
from .search import engine
|
||||
|
||||
|
||||
def process_job(vid_id):
|
||||
try:
|
||||
video = db.get(vid_id)
|
||||
if not video or video["status"] == "ready":
|
||||
return
|
||||
download_path = video.get("download_path")
|
||||
db.set_status(vid_id, "downloading")
|
||||
meta = downloader.download(video["url"], vid_id)
|
||||
db.update_meta(vid_id, **pick(meta))
|
||||
if config.OPTIMIZE:
|
||||
db.set_status(vid_id, "transcoding")
|
||||
opt = transcode.transcode(video["url"], vid_id, meta["download_path"])
|
||||
db.update_meta(vid_id, **pick(opt))
|
||||
video = db.get(vid_id)
|
||||
cats, tags = categorize.categorize(video, height=video.get("height"),
|
||||
duration=video.get("duration"),
|
||||
site=video.get("site"))
|
||||
db.update_meta(vid_id, categories=",".join(cats), tags=",".join(tags))
|
||||
db.set_status(vid_id, "ready")
|
||||
index(vid_id)
|
||||
except Exception as exc:
|
||||
db.set_status(vid_id, "failed", error=_short(traceback.format_exc()))
|
||||
raise
|
||||
|
||||
|
||||
def pick(mapping):
|
||||
allowed = {
|
||||
"site", "title", "description", "uploader", "duration", "published_at",
|
||||
"download_path", "size_bytes", "width", "height", "quality",
|
||||
"optimized_path", "poster_path", "thumb_path", "preview_path",
|
||||
}
|
||||
return {k: v for k, v in mapping.items() if k in allowed and v is not None}
|
||||
|
||||
|
||||
def _short(trace):
|
||||
lines = [l for l in trace.strip().splitlines() if "Error" in l or "rror" in l]
|
||||
return (lines[-1] if lines else trace).strip()[-500:]
|
||||
|
||||
|
||||
def index(vid_id):
|
||||
from . import db
|
||||
|
||||
v = db.get(vid_id)
|
||||
if not v or v["status"] != "ready":
|
||||
return
|
||||
doc = {
|
||||
"id": v["id"],
|
||||
"title": v["title"] or "",
|
||||
"description": v["description"] or "",
|
||||
"uploader": v["uploader"] or "",
|
||||
"tags": (v["tags"] or "").split(","),
|
||||
"categories": (v["categories"] or "").split(","),
|
||||
"site": v["site"] or "",
|
||||
"duration": v["duration"],
|
||||
"poster": v["poster_path"] or "",
|
||||
"quality": v["quality"] or "",
|
||||
"added_at": v["added_at"],
|
||||
}
|
||||
engine.index_video(doc)
|
||||
|
||||
|
||||
def index_all():
|
||||
from . import db
|
||||
|
||||
conn = db.connect()
|
||||
rows = conn.execute("SELECT id FROM videos WHERE status='ready'").fetchall()
|
||||
conn.close()
|
||||
for r in rows:
|
||||
index(r["id"])
|
||||
|
||||
|
||||
def reprocess(vid_id):
|
||||
try:
|
||||
db.set_status(vid_id, "queued", error=None)
|
||||
process_job(vid_id)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
@@ -0,0 +1,73 @@
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
from . import config
|
||||
|
||||
|
||||
class SearchEngine:
|
||||
def __init__(self):
|
||||
self._enable = not config.MEILI_DISABLE
|
||||
self._ready = False
|
||||
self._check()
|
||||
|
||||
def _check(self):
|
||||
if not self._enable:
|
||||
return
|
||||
try:
|
||||
self._req("GET", "/health")
|
||||
self._ready = True
|
||||
except Exception:
|
||||
self._ready = False
|
||||
|
||||
def _req(self, method, path, body=None):
|
||||
url = config.MEILI_URL.rstrip("/") + path
|
||||
data = json.dumps(body).encode() if body is not None else None
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=data,
|
||||
method=method,
|
||||
headers={
|
||||
"Authorization": f"Bearer {config.MEILI_KEY}",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=5) as r:
|
||||
return json.loads(r.read() or b"{}")
|
||||
|
||||
def available(self):
|
||||
self._check()
|
||||
return self._ready
|
||||
|
||||
def index_video(self, doc):
|
||||
if not self.available():
|
||||
return
|
||||
try:
|
||||
self._req("POST", "/indexes/videos/documents", [doc])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def delete_video(self, video_id):
|
||||
if not self.available():
|
||||
return
|
||||
try:
|
||||
self._req("POST", "/indexes/videos/documents/delete-batch",
|
||||
[str(video_id)])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def search(self, q, filters=None, limit=200):
|
||||
if q and self.available():
|
||||
try:
|
||||
payload = {"q": q, "limit": limit, "attributesToRetrieve": ["id"]}
|
||||
if filters:
|
||||
payload["filter"] = filters
|
||||
res = self._req("POST", "/indexes/videos/search", payload)
|
||||
hits = res.get("hits") or []
|
||||
return [int(h["id"]) for h in hits]
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
engine = SearchEngine()
|
||||
@@ -0,0 +1,95 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from . import config
|
||||
|
||||
|
||||
def _probe(path):
|
||||
cmd = [config.FFPROBE, "-v", "error", "-select_streams", "v:0",
|
||||
"-show_entries", "stream=width,height,duration",
|
||||
"-of", "json", str(path)]
|
||||
out = subprocess.run(cmd, capture_output=True, text=True)
|
||||
return json.loads(out.stdout or "{}")
|
||||
|
||||
|
||||
def _run(cmd):
|
||||
return subprocess.run(cmd, capture_output=True, text=True)
|
||||
|
||||
|
||||
def transcode(url, vid_id, src_path):
|
||||
out_dir = config.OPTIMIZED
|
||||
base = out_dir / f"{vid_id}"
|
||||
out_file = Path(f"{base}.mp4")
|
||||
src_path = Path(src_path)
|
||||
|
||||
info = _probe(src_path)
|
||||
streams = info.get("streams") or [{}]
|
||||
s = streams[0] if streams else {}
|
||||
width, height = s.get("width"), s.get("height")
|
||||
duration = s.get("duration")
|
||||
if duration:
|
||||
try:
|
||||
duration = float(duration)
|
||||
except (TypeError, ValueError):
|
||||
duration = None
|
||||
|
||||
vf = []
|
||||
if width and height:
|
||||
if height > 1080:
|
||||
vf.append("scale=-2:1080")
|
||||
vf.append("format=yuv420p")
|
||||
|
||||
cmd = [config.FFMPEG, "-y", "-i", str(src_path),
|
||||
"-map", "0:v:0", "-map", "0:a:0?",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", config.VIDEO_CRF,
|
||||
"-profile:v", "high", "-level", "4.1",
|
||||
"-c:a", "aac", "-b:a", config.AUDIO_BITRATE,
|
||||
"-movflags", "+faststart", "-threads", "0"]
|
||||
if vf:
|
||||
cmd += ["-vf", ",".join(vf)]
|
||||
cmd.append(str(out_file := base.with_suffix(".mp4")))
|
||||
_run(cmd)
|
||||
|
||||
poster = out_dir / f"{vid_id}_poster.jpg"
|
||||
thumb = out_dir / f"{vid_id}_thumb.jpg"
|
||||
preview = out_dir / f"{vid_id}_preview.mp4"
|
||||
|
||||
dur = duration or 0
|
||||
poster_at = max(1.0, dur * 0.08)
|
||||
preview_at = max(1.0, dur * 0.02)
|
||||
preview_len = min(10, max(6, int(dur * 0.015))) if dur else 6
|
||||
|
||||
# Skapa poster/thumb (extrahera en frame)
|
||||
_run([config.FFMPEG, "-y", "-ss", str(poster_at), "-i", str(src_path),
|
||||
"-frames:v", "1", "-vf", "scale=1280:-2,format=yuv420p",
|
||||
str(poster)])
|
||||
_run([config.FFMPEG, "-y", "-ss", str(poster_at), "-i", str(src_path),
|
||||
"-frames:v", "1", "-vf", "scale=480:-2,format=yuv420p",
|
||||
str(thumb)])
|
||||
|
||||
# Preview: short clip, muted webm-liknande mp4 (utan faststart-i-huvud)
|
||||
_run([config.FFMPEG, "-y", "-ss", str(preview_at), "-i", str(src_path),
|
||||
"-t", str(preview_len),
|
||||
"-vf", "scale=848:-2,fps=24,format=yuv420p",
|
||||
"-c:v", "libx264", "-preset", "veryfast", "-crf", "28",
|
||||
"-c:a", "aac", "-b:a", "96K",
|
||||
str(preview)])
|
||||
|
||||
# Verifiera output och rapportera verkliga dims
|
||||
out_info = _probe(out_file)
|
||||
out_s = (out_info.get("streams") or [{}])[0]
|
||||
out_w, out_h = out_s.get("width"), out_s.get("height")
|
||||
|
||||
size = src_path.stat().st_size if src_path.exists() else None
|
||||
return {
|
||||
"width": out_w or width,
|
||||
"height": out_h or height,
|
||||
"duration": round(duration, 1) if duration else None,
|
||||
"quality": f"{out_h or height}p" if (out_h or height) else None,
|
||||
"size_bytes": size,
|
||||
"optimized_path": str(out_file) if out_file.exists() else None,
|
||||
"poster_path": str(poster) if poster.exists() else None,
|
||||
"thumb_path": str(thumb) if thumb.exists() else None,
|
||||
"preview_path": str(preview) if preview.exists() and preview.stat().st_size > 0 else None,
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Request, Form, HTTPException
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse, FileResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from .. import db, config
|
||||
from ..search import engine
|
||||
from . import routing
|
||||
|
||||
app = FastAPI(title="VideoVault")
|
||||
|
||||
BASE = Path(__file__).resolve().parent.parent.parent
|
||||
templates = Jinja2Templates(directory=str(BASE / "app" / "web" / "templates"))
|
||||
app.mount("/static", StaticFiles(directory=str(BASE / "app" / "web" / "static")), name="static")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return {"ok": True, "search": engine.available()}
|
||||
|
||||
|
||||
@app.post("/add")
|
||||
async def add(url: str = Form(...)):
|
||||
url = url.strip()
|
||||
if not url:
|
||||
raise HTTPException(400, "Tom URL")
|
||||
vid = db.add_job(url)
|
||||
return RedirectResponse("/", status_code=303)
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def index(request: Request):
|
||||
return render_home(request)
|
||||
|
||||
|
||||
@app.get("/video/{vid_id}", response_class=HTMLResponse)
|
||||
def video(request: Request, vid_id: int):
|
||||
v = db.get(vid_id)
|
||||
if not v:
|
||||
raise HTTPException(404)
|
||||
return templates.TemplateResponse(request, "video.html", {
|
||||
"v": v,
|
||||
"cats": (v["categories"] or "").split(","),
|
||||
"tags": (v["tags"] or "").split(","),
|
||||
"stats": _stats(),
|
||||
"primaries": ["Teen 18+", "Petite", "Skinny", "Bondage"],
|
||||
"media_url": routing.media_url,
|
||||
})
|
||||
|
||||
|
||||
@app.get("/media/{vid_id}/{kind}")
|
||||
def media(vid_id: int, kind: str):
|
||||
v = db.get(vid_id)
|
||||
if not v:
|
||||
raise HTTPException(404)
|
||||
key = {"video": "optimized_path", "source": "download_path",
|
||||
"poster": "poster_path", "thumb": "thumb_path",
|
||||
"preview": "preview_path"}.get(kind)
|
||||
if not key:
|
||||
raise HTTPException(400)
|
||||
path = v.get(key)
|
||||
if not path or not Path(path).exists():
|
||||
raise HTTPException(404)
|
||||
return FileResponse(path)
|
||||
|
||||
|
||||
@app.post("/video/{vid_id}/delete")
|
||||
def delete(vid_id: int):
|
||||
files = db.delete_video(vid_id)
|
||||
if files is None:
|
||||
raise HTTPException(404)
|
||||
import os
|
||||
for f in files:
|
||||
if f:
|
||||
try:
|
||||
os.remove(f)
|
||||
except OSError:
|
||||
pass
|
||||
engine.delete_video(vid_id)
|
||||
return RedirectResponse("/", status_code=303)
|
||||
|
||||
|
||||
@app.get("/reindex")
|
||||
def reindex():
|
||||
from ..pipeline import index_all
|
||||
|
||||
index_all()
|
||||
return RedirectResponse("/", status_code=303)
|
||||
|
||||
|
||||
def _stats():
|
||||
conn = db.connect()
|
||||
st = db.stats(conn)
|
||||
conn.close()
|
||||
return st
|
||||
|
||||
|
||||
def render_home(request):
|
||||
params = request.query_params
|
||||
q = params.get("q", "").strip()
|
||||
cat = params.get("cat", "").strip()
|
||||
tag = params.get("tag", "").strip()
|
||||
order = params.get("order", "added_at DESC")
|
||||
status = params.get("status", "ready")
|
||||
|
||||
if q and engine.available():
|
||||
ids = engine.search(q)
|
||||
if ids is None:
|
||||
ids = None
|
||||
rows, total = db.list_videos(status=status, category=cat, tag=tag,
|
||||
q=q if ids is None else None)
|
||||
hits = set(ids or [])
|
||||
rows = [r for r in rows if r["id"] in hits] if ids else rows
|
||||
else:
|
||||
rows, total = db.list_videos(status=status, category=cat, tag=tag, q=q,
|
||||
order=order)
|
||||
|
||||
conn = db.connect()
|
||||
cats_list = db.categories(conn)
|
||||
tags_list = db.tags_for(conn)
|
||||
st = db.stats(conn)
|
||||
active = db.queued(limit=12)
|
||||
conn.close()
|
||||
return templates.TemplateResponse(request, "index.html", {
|
||||
"videos": rows, "cats": cats_list, "nisch_tags": tags_list,
|
||||
"stats": st, "active": active, "q": q, "cat": cat, "tag": tag,
|
||||
"order": order, "total": total, "search": engine.available(),
|
||||
"primaries": ["Teen 18+", "Petite", "Skinny", "Bondage"],
|
||||
"media_url": routing.media_url,
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
def media_url(v, kind="thumb"):
|
||||
key = {"video": "optimized_path", "source": "download_path",
|
||||
"poster": "poster_path", "thumb": "thumb_path",
|
||||
"preview": "preview_path"}.get(kind, "thumb_path")
|
||||
if not v or not v.get(key):
|
||||
return None
|
||||
return f"/media/{v['id']}/{kind}"
|
||||
@@ -0,0 +1,44 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Hover-preview i kort: spela preview vid hover, pausa vid leave
|
||||
document.querySelectorAll('.card').forEach(card => {
|
||||
const vid = card.querySelector('.hover-preview');
|
||||
if (!vid) return;
|
||||
card.addEventListener('mouseenter', () => {
|
||||
vid.play().catch(() => {});
|
||||
});
|
||||
card.addEventListener('mouseleave', () => {
|
||||
vid.pause();
|
||||
try { vid.currentTime = 0; } catch (e) {}
|
||||
});
|
||||
});
|
||||
|
||||
// Live-sök debounce
|
||||
const si = document.querySelector('.search input');
|
||||
if (si) {
|
||||
const form = si.closest('form');
|
||||
let t2;
|
||||
si.addEventListener('input', () => {
|
||||
clearTimeout(t2);
|
||||
t2 = setTimeout(() => form.submit(), 450);
|
||||
});
|
||||
}
|
||||
|
||||
// Kortkommandon
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 's' && document.activeElement !== si) {
|
||||
e.preventDefault(); si && si.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Spelare i navigering med piltangenter (filtrera på j/k på spellista)
|
||||
const player = document.getElementById('player');
|
||||
if (player) {
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.target.tagName === 'INPUT') return;
|
||||
const cards = [...document.querySelectorAll('.card[data-id]')];
|
||||
if (e.key === ' ') { e.preventDefault(); player.paused ? player.play() : player.pause(); }
|
||||
if (e.key === 'm') { player.muted = !player.muted; }
|
||||
if (e.key === 'f') { player.requestFullscreen?.(); }
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,125 @@
|
||||
:root {
|
||||
--bg: #0d0d11;
|
||||
--bg2: #14141a;
|
||||
--card: #191920;
|
||||
--line: #26262f;
|
||||
--txt: #e8e8ef;
|
||||
--muted: #9a9aa8;
|
||||
--acc: #e23d7b;
|
||||
--acc2: #7b3de2;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0; background: var(--bg); color: var(--txt);
|
||||
font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
|
||||
}
|
||||
a { color: var(--acc); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
.top {
|
||||
display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
|
||||
padding: 12px 22px; background: var(--bg2); border-bottom: 1px solid var(--line);
|
||||
position: sticky; top: 0; z-index: 20;
|
||||
}
|
||||
.brand { font-weight: 700; font-size: 20px; color: var(--txt); }
|
||||
.search { display: flex; flex: 1; max-width: 560px; gap: 6px; }
|
||||
.search input {
|
||||
flex: 1; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
|
||||
background: var(--card); color: var(--txt); font-size: 15px;
|
||||
}
|
||||
.search button {
|
||||
border: 0; background: var(--acc); color: #fff; border-radius: 10px; padding: 0 14px; cursor: pointer;
|
||||
}
|
||||
.stats { display: flex; gap: 12px; color: var(--muted); font-size: 13px; }
|
||||
|
||||
.primaries {
|
||||
background: #101016; border-bottom: 1px solid var(--line); padding: 8px 22px;
|
||||
}
|
||||
.primaries .wrap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||
.chip {
|
||||
padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
|
||||
background: var(--card); color: var(--txt); font-size: 13px; font-weight: 600;
|
||||
}
|
||||
.chip:hover { border-color: var(--acc); text-decoration: none; }
|
||||
.spacer { flex: 1; }
|
||||
.btn-add {
|
||||
padding: 6px 14px; border-radius: 8px; background: var(--acc2); color: #fff; font-weight: 600;
|
||||
}
|
||||
|
||||
#addform {
|
||||
max-width: 640px; margin: 18px auto; padding: 18px; border: 1px solid var(--line);
|
||||
border-radius: 14px; background: var(--card); display: flex; gap: 10px; flex-wrap: wrap;
|
||||
}
|
||||
#addform label { width: 100%; color: var(--muted); font-size: 13px; }
|
||||
#addform input { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: #0f0f14; color: var(--txt); }
|
||||
#addform button { border: 0; background: var(--acc); color: #fff; padding: 10px 16px; border-radius: 8px; cursor: pointer; }
|
||||
|
||||
.filters-bar { padding: 14px 22px 4px; display: flex; flex-direction: column; gap: 10px; }
|
||||
.filter-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
||||
.f-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
|
||||
.tag {
|
||||
padding: 3px 10px; border-radius: 999px; background: var(--card);
|
||||
border: 1px solid var(--line); font-size: 12px; color: var(--txt);
|
||||
}
|
||||
.tag.on { border-color: var(--acc); color: var(--acc); }
|
||||
.order { margin-left: auto; }
|
||||
.order select { background: var(--card); color: var(--txt); border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px; }
|
||||
|
||||
.grid {
|
||||
display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
|
||||
gap: 16px; padding: 18px 22px;
|
||||
}
|
||||
.card {
|
||||
background: var(--card); border: 1px solid var(--line); border-radius: 14px;
|
||||
overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, border-color .12s;
|
||||
}
|
||||
.card:hover { transform: translateY(-3px); border-color: var(--acc); }
|
||||
.media { position: relative; display: block; aspect-ratio: 16/10; background: #000; }
|
||||
.media img { width: 100%; height: 100%; object-fit: cover; }
|
||||
.media .ph { display: grid; place-items: center; height: 100%; font-size: 34px; color: #555; }
|
||||
.media .badge {
|
||||
position: absolute; top: 8px; left: 8px; z-index: 3; padding: 3px 8px;
|
||||
border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase;
|
||||
background: rgba(0,0,0,.55); color: #ffd166;
|
||||
}
|
||||
.dur, .res {
|
||||
position: absolute; bottom: 8px; padding: 2px 6px; border-radius: 5px;
|
||||
background: rgba(0,0,0,.6); font-size: 11px; color: #fff;
|
||||
}
|
||||
.dur { left: 8px; }
|
||||
.res { right: 8px; }
|
||||
.hover-preview {
|
||||
position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
|
||||
opacity: 0; pointer-events: none; transition: opacity .15s;
|
||||
}
|
||||
.card:hover .hover-preview { opacity: 1; }
|
||||
.card:hover img { opacity: 0; }
|
||||
|
||||
.meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
|
||||
.meta .t { font-weight: 600; font-size: 14px; color: var(--txt); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
|
||||
.cats { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||
.chip-sm { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #23232c; color: var(--muted); border: 1px solid var(--line); }
|
||||
|
||||
.queue { padding: 6px 22px 0; }
|
||||
.queue h2 { font-size: 15px; color: var(--muted); }
|
||||
.count, .empty { padding: 6px 22px; color: var(--muted); }
|
||||
|
||||
.player-wrap { padding: 20px 22px 0; }
|
||||
#player { width: 100%; max-height: calc(100vh - 220px); border-radius: 14px; background: #000; }
|
||||
.vid-title { padding: 14px 22px 0; margin: 0; font-size: 22px; }
|
||||
.cats { padding: 8px 22px; }
|
||||
.meta-list { padding: 4px 22px; list-style: none; color: var(--muted); }
|
||||
.meta-list li { padding: 2px 0; }
|
||||
.meta-list .err { color: #ff6b6b; }
|
||||
.actions { padding: 8px 22px; display: flex; gap: 10px; }
|
||||
.btn {
|
||||
padding: 8px 16px; border-radius: 9px; border: 1px solid var(--acc);
|
||||
background: transparent; color: var(--acc); cursor: pointer; font-weight: 600;
|
||||
}
|
||||
.btn.danger { border-color: #ff6b6b; color: #ff6b6b; }
|
||||
.tags { padding: 12px 22px 30px; display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
|
||||
.foot {
|
||||
padding: 18px 22px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line);
|
||||
display: flex; justify-content: space-between; margin-top: 30px; flex-wrap: wrap; gap: 8px;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<!doctype html>
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex,nofollow">
|
||||
<title>{% block title %}VideoVault{% endblock %}</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<script src="/static/app.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="top">
|
||||
<a class="brand" href="/">📼 VideoVault</a>
|
||||
<form class="search" method="get" action="/">
|
||||
<input type="search" name="q" value="{{ q or '' }}"
|
||||
placeholder="Sök titel, tagg, nisch…" autofocus>
|
||||
<button>🔍</button>
|
||||
</form>
|
||||
<div class="stats">
|
||||
<span>{{ stats['ready'] }} redo</span>
|
||||
<span>{{ stats['queued'] }} kö</span>
|
||||
<span>{{ stats['failed'] }} fel</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="primaries">
|
||||
<div class="wrap">
|
||||
<a href="/">Alla</a>
|
||||
{% for p in primaries %}
|
||||
<a class="chip" href="/?cat={{ p|urlencode }}">{{ p }}</a>
|
||||
{% endfor %}
|
||||
<span class="spacer"></span>
|
||||
<a href="/?status=queued">Kö/aktivt</a>
|
||||
<a href="/?status=failed">Fel</a>
|
||||
<a class="btn-add" href="#" onclick="document.getElementById('addform').classList.toggle('open');return false;">+ Länk</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<form id="addform" action="/add" method="post" hidden>
|
||||
<label>Klistra in en video-länk (t.ex. xvideos.com/…, pornhub.com/…)</label>
|
||||
<input name="url" type="url" placeholder="https://…" required>
|
||||
<button type="submit">Köa och ladda ner</button>
|
||||
</form>
|
||||
|
||||
{% include "filters.html" %}
|
||||
|
||||
<main>
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<footer class="foot">
|
||||
<span>VideoVault — lokal kuratering. Endast laglig adult-innehåll (18+).</span>
|
||||
<a href="/reindex">Re-indexera sök</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
<form class="filters" method="get" action="/" hidden></form>
|
||||
@@ -0,0 +1,86 @@
|
||||
{% block title %}Start — VideoVault{% endblock %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% set kind = 'thumb' %}
|
||||
{% block content %}
|
||||
<section class="filters-bar">
|
||||
{% if primaries %}
|
||||
<div class="filter-group">
|
||||
<span class="f-label">Nisch:</span>
|
||||
{% for c in primaries %}
|
||||
<a class="tag {% if cat == c %}on{% endif %}" href="/?cat={{ c|urlencode }}">{{ c }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if cats %}
|
||||
<div class="filter-group wrap">
|
||||
<span class="f-label">Kanal:</span>
|
||||
{% for c in cats if c.name.startswith('Kanal:') %}
|
||||
<a class="tag {% if cat == c.name %}on{% endif %}" href="/?cat={{ c.name|urlencode }}">{{ c.name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if cats %}
|
||||
<div class="filter-group wrap">
|
||||
<span class="f-label">Övriga:</span>
|
||||
{% for c in cats if not c.name.startswith('Kanal:') and c.name not in primaries %}
|
||||
<a class="tag {% if cat == c.name %}on{% endif %}" href="/?cat={{ c.name|urlencode }}">{{ c.name }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<form class="order" method="get" action="/">
|
||||
{% if q %}<input type="hidden" name="q" value="{{ q }}">{% endif %}
|
||||
{% if cat %}<input type="hidden" name="cat" value="{{ cat }}">{% endif %}
|
||||
{% if status %}<input type="hidden" name="status" value="{{ status }}">{% endif %}
|
||||
<select name="order" onchange="this.form.submit()">
|
||||
<option value="added_at DESC" {% if order=='added_at DESC' %}selected{% endif %}>Senast tillagda</option>
|
||||
<option value="title ASC" {% if order=='title ASC' %}selected{% endif %}>Titel (A-Ö)</option>
|
||||
<option value="duration DESC" {% if order=='duration DESC' %}selected{% endif %}>Längst</option>
|
||||
</select>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{% if active %}
|
||||
<section class="queue">
|
||||
<h2>Kö / aktivt (<a href="/?status=queued">se alla</a>)</h2>
|
||||
<div class="grid">
|
||||
{% for v in active %}
|
||||
<div class="card">
|
||||
<div class="media"><span class="badge status">{{ v.status }}</span></div>
|
||||
<div class="meta"><span class="t">{{ v.title or v.site or v.url }}</span></div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if videos %}
|
||||
<section class="grid">
|
||||
{% for v in videos %}
|
||||
<div class="card" data-id="{{ v.id }}">
|
||||
<a class="media" href="/video/{{ v.id }}">
|
||||
{% if v.thumb_path %}
|
||||
<img loading="lazy" src="{{ media_url(v,'thumb') }}" alt="{{ v.title }}">
|
||||
<video class="hover-preview" muted preload="none" src="{{ media_url(v,'preview') }}" loop></video>
|
||||
{% else %}
|
||||
<div class="ph">🎬</div>
|
||||
{% endif %}
|
||||
<span class="dur">{{ v.duration }}s</span>
|
||||
<span class="res">{{ v.quality }}</span>
|
||||
</a>
|
||||
<div class="meta">
|
||||
<a class="t" href="/video/{{ v.id }}">{{ v.title or v.site }}</a>
|
||||
<div class="cats">{% for c in (v.categories or '').split(',') if c %}<span class="chip-sm">{{ c }}</span>{% endfor %}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</section>
|
||||
<p class="count">{{ total }} träffar</p>
|
||||
{% else %}
|
||||
<p class="empty">Inga träffar — lägg till länkar ovan, eller vänta på att kön är klar.</p>
|
||||
{% endif %}
|
||||
|
||||
{% if videos %}
|
||||
<div style="height:12px"></div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,42 @@
|
||||
{% block title %}{{ v.title or 'Video' }}{% endblock %}
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="player-wrap">
|
||||
{% if v.optimized_path %}
|
||||
<video id="player" controls autoplay
|
||||
poster="{{ media_url(v,'poster') if v.poster_path }}"
|
||||
src="{{ media_url(v,'video') }}"></video>
|
||||
{% else %}
|
||||
<div class="ph big">🎬 {{ v.status }} — inget optimerat flöde ännu</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<h1 class="vid-title">{{ v.title or v.site or 'Namtlös' }}</h1>
|
||||
|
||||
<div class="cats">
|
||||
{% for c in cats if c %}<span class="chip-sm">{{ c }}</span>{% endfor %}
|
||||
</div>
|
||||
|
||||
<ul class="meta-list">
|
||||
{% if v.site %}<li>Kanal: <b>{{ v.site }}</b></li>{% endif %}
|
||||
{% if v.uploader %}<li>Skapare: <b>{{ v.uploader }}</b></li>{% endif %}
|
||||
{% if v.duration %}<li>Längd: <b>{{ v.duration }} s</b></li>{% endif %}
|
||||
{% if v.quality %}<li>Kvalitet: <b>{{ v.quality }}</b></li>{% endif %}
|
||||
{% if v.size_bytes %}<li>Storlek: <b>{{ '%.1f'|format(v.size_bytes / 1e6) }} MB</b></li>{% endif %}
|
||||
{% if v.published_at %}<li>Publicerad: <b>{{ v.published_at }}</b></li>{% endif %}
|
||||
{% if v.added_at %}<li>Tillagd: <b>{{ v.added_at }}</b></li>{% endif %}
|
||||
{% if v.error %}<li class="err">Fel: {{ v.error }}</li>{% endif %}
|
||||
<li><a href="{{ v.url }}" target="_blank" rel="noopener">Originalkälla ↗</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="actions">
|
||||
{% if v.source_url_ok %}<a class="btn" href="{{ media_url(v,'source') if v.download_path }}">Ladda ner källfil</a>{% endif %}
|
||||
<form action="/video/{{ v.id }}/delete" method="post" onsubmit="return confirm('Ta bort media + post?')" style="display:inline">
|
||||
<button class="btn danger" type="submit">Ta bort</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="tags">
|
||||
{% for t in tags if t %}<span class="tag">{{ t }}</span>{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,29 @@
|
||||
import time
|
||||
|
||||
from . import config, db
|
||||
from .pipeline import process_job, index_all
|
||||
|
||||
|
||||
def run_once():
|
||||
from .ingest import import_watch
|
||||
|
||||
index_all()
|
||||
import_watch()
|
||||
jobs = db.queued(limit=4)
|
||||
if not jobs:
|
||||
return 0
|
||||
done = 0
|
||||
for v in jobs:
|
||||
process_job(v["id"])
|
||||
done += 1
|
||||
return done
|
||||
|
||||
|
||||
def daemon():
|
||||
index_all()
|
||||
while True:
|
||||
try:
|
||||
run_once()
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(5)
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=VideoVault Web UI
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/home/simon/Documents/Default Project/videovault
|
||||
ExecStart="/home/simon/Documents/Default Project/videovault/.venv/bin/python" -m app.ingest serve
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=VideoVault Worker (download+transcode)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/home/simon/Documents/Default Project/videovault
|
||||
ExecStart="/home/simon/Documents/Default Project/videovault/.venv/bin/python" -m app.ingest daemon
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
@@ -0,0 +1,16 @@
|
||||
services:
|
||||
meilisearch:
|
||||
image: getmeili/meilisearch:v1.8
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MEILI_MASTER_KEY: "${MEILI_KEY:-devkey}"
|
||||
MEILI_ENV: development
|
||||
ports:
|
||||
- "127.0.0.1:7700:7700"
|
||||
volumes:
|
||||
- ./data/meili:/meili_data
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:7700/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
@@ -0,0 +1,5 @@
|
||||
yt-dlp>=2024.12.13
|
||||
fastapi>=0.115.0
|
||||
uvicorn[standard]>=0.30.0
|
||||
jinja2>=3.1.0
|
||||
python-multipart>=0.0.9
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PY="$BASE/.venv/bin/python"
|
||||
|
||||
action="${1:-help}"
|
||||
case "$action" in
|
||||
setup)
|
||||
python3 -m venv "$BASE/.venv"
|
||||
"$BASE/.venv/bin/pip" install --upgrade pip
|
||||
"$BASE/.venv/bin/pip" install -r "$BASE/requirements.txt"
|
||||
"$PY" -m app.ingest init
|
||||
docker compose -f "$BASE/docker-compose.yml" up -d meilisearch
|
||||
echo "Klar. Lägg länkar i $BASE/watch/*.url eller använd UI:et."
|
||||
;;
|
||||
start)
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now vv-web vv-worker
|
||||
systemctl --user start vv-web vv-worker
|
||||
echo "UI: http://127.0.0.1:8080"
|
||||
;;
|
||||
stop)
|
||||
systemctl --user stop vv-web vv-worker
|
||||
;;
|
||||
status)
|
||||
systemctl --user is-active vv-web vv-worker
|
||||
curl -s http://127.0.0.1:8080/health
|
||||
;;
|
||||
web) "$PY" -m app.ingest serve ;;
|
||||
worker) "$PY" -m app.ingest daemon ;;
|
||||
add) shift; "$PY" -m app.ingest add "$@" ;;
|
||||
watch) "$PY" -m app.ingest watch ;;
|
||||
*)
|
||||
echo "Användning: $0 {setup|start|stop|status|web|worker|add <url>|watch}"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user