arnaucube
arnaucube/jellyfin-toolsPublic Self-hosted repository
jellyfin-tools/jellyfin-year-review/scripts/generate-review.sh
jellyfin-year-review/scripts/generate-review.shRaw
 1#!/bin/sh
 2# Generate a selected year using the operator's .env and native Jellystat history.
 3set -eu
 4
 5if [ "$#" -ne 1 ]; then
 6  echo 'usage: scripts/generate-review.sh YEAR' >&2
 7  exit 1
 8fi
 9case "$1" in
10  [0-9][0-9][0-9][0-9]) ;;
11  *) echo 'Year must be between 1970 and 9998.' >&2; exit 1 ;;
12esac
13if [ "$1" -lt 1970 ] || [ "$1" -gt 9998 ]; then
14  echo 'Year must be between 1970 and 9998.' >&2
15  exit 1
16fi
17
18cd "$(dirname "$0")/.."
19umask 077
20printf 'review: Preparing recap generation for %s...\n' "$1" >&2
21if [ -f .env ]; then
22  set -a
23  . ./.env
24  set +a
25fi
26: "${JELLYFIN_URL:?Set JELLYFIN_URL in .env}"
27: "${JELLYFIN_API_KEY:?Set JELLYFIN_API_KEY in .env}"
28for reel_dependency in go psql; do
29  if ! command -v "$reel_dependency" >/dev/null 2>&1; then
30    printf 'review: Missing required command: %s. Install Go 1.27.2 and the PostgreSQL client (psql), then retry.\n' "$reel_dependency" >&2
31    exit 127
32  fi
33done
34
35mkdir -p input data cache
36reel_captured_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
37printf 'review: Exporting Jellystat history...\n' >&2
38if scripts/export-jellystat.sh input/jellystat.jsonl; then
39  :
40else
41  reel_export_status=$?
42  printf 'review: History export failed. Check PostgreSQL access and PGPASSWORD; review generation was not started.\n' >&2
43  exit "$reel_export_status"
44fi
45printf 'review: Generating the recap and downloading Jellyfin posters...\n' >&2
46exec go run ./cmd/review generate --year "$1" \
47  --history input/jellystat.jsonl --captured-at "$reel_captured_at" \
48  --coverage "${REVIEW_COVERAGE:-Native Jellystat export; collection coverage not verified}" \
49  --output data --cache cache