Files
mymovies/add_movie.sh
2026-08-08 02:41:46 +02:00

57 lines
2.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Добавление фильма в catalog.json плагина Lampa "Мои фильмы"
# Использование:
# ./add_movie.sh --id inception --title "Начало" --orig "Inception" --year 2010 \
# --genre "фанстика,боевик" --rating 8.8 --desc "..." \
# --poster covers/inception.jpg --torrent torrents/inception.torrent
#
# После правки делает git commit + push. Деплой в Coolify — отдельно (руками или вебхук).
set -euo pipefail
cd "$(dirname "$0")"
ID="" TITLE="" ORIG="" YEAR="" GENRE="" RATING="" DESC="" POSTER="" TORRENT=""
while [[ $# -gt 0 ]]; do
case "$1" in
--id) ID="$2"; shift 2;;
--title) TITLE="$2"; shift 2;;
--orig) ORIG="$2"; shift 2;;
--year) YEAR="$2"; shift 2;;
--genre) GENRE="$2"; shift 2;;
--rating) RATING="$2"; shift 2;;
--desc) DESC="$2"; shift 2;;
--poster) POSTER="$2"; shift 2;;
--torrent) TORRENT="$2"; shift 2;;
*) echo "Unknown arg: $1"; exit 1;;
esac
done
[[ -z "$ID" || -z "$TITLE" ]] && { echo "Нужны хотя бы --id и --title"; exit 1; }
python3 - "$ID" "$TITLE" "$ORIG" "$YEAR" "$GENRE" "$RATING" "$DESC" "$POSTER" "$TORRENT" <<'PY'
import sys, json
id_, title, orig, year, genre, rating, desc, poster, torrent = sys.argv[1:]
with open('catalog.json','r',encoding='utf-8') as f:
cat = json.load(f)
if any(m.get('id')==id_ for m in cat['movies']):
print('Фильм с id=%s уже есть' % id_); sys.exit(1)
m = {"id": id_, "title": title}
if orig: m["original_title"] = orig
if year: m["year"] = int(year)
if genre: m["genre"] = [g.strip() for g in genre.split(',') if g.strip()]
if rating: m["rating"] = float(rating)
if desc: m["description"] = desc
if poster: m["poster"] = poster
if torrent:m["torrent"] = torrent
cat['movies'].append(m)
cat['updated'] = __import__('datetime').date.today().isoformat()
with open('catalog.json','w',encoding='utf-8') as f:
json.dump(cat, f, ensure_ascii=False, indent=2)
print('Добавлен:', title)
PY
git add catalog.json
git commit -q -m "movie: add $TITLE"
git push origin master
echo "Запушено. Деплой в Coolify — отдельно."