feat(media): a TV mover that will not file a show the library already has
Two fixes found by one live sweep, shipped together because the second is what makes the first finishable. 1. scripts/media-tv.py — the other half of media-plan.py's refusal to file TV. Groups episode-shaped files by the series name before the marker (media-titles.ep_of, imported not restated), writes a plan in the executor's own format: <library>/<Series> (<year>)/Season <NN>/<own name>.<ext>. Refuses a group below --min, an episode naming no season, and an episode the destination library already holds at the same byte count — the movie share carries a second copy of all 124 Monk episodes the TV library has had for years; a duplicate is Frank's call, never a tool's copy. Applied by media-apply.py with its own journal and --root /mnt/entropy. 2. scripts/media-apply.py — gone meant "rmdir intended", so a folder whose rmdir failed was blacklisted forever and no later sweep could finish it (live movie sweep: 4517 targeted, 146 permanently stranded). gone now means "actually gone": a failed intent is retried by the next sweep. tests: 9 new tests in media_relayout.bats, each red against the previous revision — 8 TV + 1 sweep retry behind a chmod 500 parent. ./tests/run.sh 633 green. No live move run yet.
This commit is contained in:
1 parent
5cd9a0c4c2
commit
e83162a2ac
4 files changed
+456
-6
No files matched your search
@@ -21,6 +21,7 @@ load helpers
|
||||
PLAN="$REPO_ROOT/scripts/media-plan.py"
|
||||
CENSUS="$REPO_ROOT/scripts/media-census.py"
|
||||
APPLY="$REPO_ROOT/scripts/media-apply.py"
|
||||
TV="$REPO_ROOT/scripts/media-tv.py"
|
||||
|
||||
# probe_row FILE DUR [RES] [AUDIO] [SUBS] — one probed-TSV row: the twelve
|
||||
# columns media-census.py probe writes (bytes, path, dur, vcodec, res, fps,
|
||||
@@ -47,6 +48,9 @@ setup() {
|
||||
PLEX="$BATS_TEST_TMPDIR/plex.tsv"
|
||||
OUT="$BATS_TEST_TMPDIR/plan.tsv"
|
||||
EXC="$BATS_TEST_TMPDIR/exceptions.txt"
|
||||
TVLIB="$BATS_TEST_TMPDIR/TVShows"
|
||||
TVPLAN="$BATS_TEST_TMPDIR/tv.tsv"
|
||||
TVJ="$BATS_TEST_TMPDIR/tv.jsonl"
|
||||
: > "$PROBED"
|
||||
printf 'file\tleaf_title\tleaf_year\n' > "$PLEX"
|
||||
|
||||
@@ -136,6 +140,33 @@ for line in open(sys.argv[1]):
|
||||
' "$OUT" "$1"
|
||||
}
|
||||
|
||||
# tv_plan — the TV mover over the fixture library; its stdout is the operator's
|
||||
# census of what it called a series and what it refused to touch.
|
||||
tv_plan() {
|
||||
run python3 "$TV" --root "$LIB" --library "$TVLIB" --out "$TVPLAN"
|
||||
[ "$status" -eq 0 ]
|
||||
printf '%s\n' "$output" > "$BATS_TEST_TMPDIR/tv.out"
|
||||
}
|
||||
|
||||
# tv_apply — that plan through the same executor. The destination is a sibling
|
||||
# share, so the plan is applied at the root that holds both libraries.
|
||||
tv_apply() {
|
||||
run python3 "$APPLY" apply --plan "$TVPLAN" --root "$BATS_TEST_TMPDIR" \
|
||||
--journal "$TVJ" --apply
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
# tv_dst_of SRC — the destination the TV plan gives one file, empty if none.
|
||||
tv_dst_of() {
|
||||
python3 -c '
|
||||
import sys
|
||||
for line in open(sys.argv[1]):
|
||||
f = line.rstrip("\n").split("\t")
|
||||
if len(f) > 2 and f[1] == sys.argv[2]:
|
||||
print(f[2]); break
|
||||
' "$TVPLAN" "$1"
|
||||
}
|
||||
|
||||
@test "a film lands in Title (year)/Title (year).mkv, named by Plex" {
|
||||
plan
|
||||
[ "$(dst_of "$LIB/Alien (1979)/Alien.1979.1080p.BluRay.x265.10bit.mkv")" \
|
||||
@@ -243,6 +274,81 @@ for k in sorted(pile):
|
||||
= "$LIB/The Godfather Part 2 (1974)/The Godfather Part 2 (1974).mkv" ]
|
||||
}
|
||||
|
||||
@test "the TV mover files a box set into the TV library in Jellyfin shape" {
|
||||
tv_plan
|
||||
tv_apply
|
||||
[ -e "$TVLIB/Monk (2002)/Season 01/Monk - S01E01 - Mr Monk and the Rival.mkv" ]
|
||||
[ -e "$TVLIB/Big Little Lies/Season 01/Big Little Lies S01E01.mp4" ]
|
||||
[ ! -e "$LIB/Monk 2002 Seasons 1 to 8/Season 1/Monk - S01E01 - Mr Monk and the Rival.mkv" ]
|
||||
# films are not the TV mover's business
|
||||
[ -e "$LIB/Alien (1979)/Alien.1979.1080p.BluRay.x265.10bit.mkv" ]
|
||||
}
|
||||
|
||||
@test "the TV mover leaves a film whose name only looks like an episode" {
|
||||
tv_plan
|
||||
tv_apply
|
||||
local gf="$LIB/The Godfather Part 2 (1974)/The.Godfather.Part.2.1974.1080p.BluRay.mkv"
|
||||
[ "$(tv_dst_of "$gf")" = "" ]
|
||||
[ -e "$gf" ]
|
||||
grep -q "Godfather.*not a series" "$BATS_TEST_TMPDIR/tv.out"
|
||||
}
|
||||
|
||||
@test "the TV mover keeps an episode's own subtitle with the episode" {
|
||||
at "$LIB/Monk 2002 Seasons 1 to 8/Season 1/Monk - S01E01 - Mr Monk and the Rival.srt" 40000
|
||||
tv_plan
|
||||
tv_apply
|
||||
[ -e "$TVLIB/Monk (2002)/Season 01/Monk - S01E01 - Mr Monk and the Rival.srt" ]
|
||||
}
|
||||
|
||||
@test "a second TV move finds nothing left to move" {
|
||||
tv_plan
|
||||
tv_apply
|
||||
tv_plan
|
||||
grep -q "0 moves" "$BATS_TEST_TMPDIR/tv.out"
|
||||
}
|
||||
|
||||
@test "a show whose own name carries the year is not given it twice" {
|
||||
local d="$LIB/Leah Remini Scientology and the Aftermath (2016)/Season 1"
|
||||
for e in 01 02 03 04 05; do
|
||||
at "$d/Leah Remini Scientology and the Aftermath (2016) - S01E$e - Episode.mkv" 3000000
|
||||
done
|
||||
tv_plan
|
||||
tv_apply
|
||||
[ -e "$TVLIB/Leah Remini Scientology and the Aftermath (2016)/Season 01/Leah Remini Scientology and the Aftermath (2016) - S01E01 - Episode.mkv" ]
|
||||
[ ! -e "$TVLIB/Leah Remini Scientology and the Aftermath (2016) (2016)" ]
|
||||
}
|
||||
|
||||
@test "an all-lowercase series name is written the way the library writes names" {
|
||||
for e in 01 02 03 04 05; do
|
||||
at "$LIB/downton abbey 2010/Season 1/downton abbey - s01e$e - episode title.mkv" 3000000
|
||||
done
|
||||
tv_plan
|
||||
tv_apply
|
||||
# the FOLDER is titled; the file keeps the name the library already holds
|
||||
[ -e "$TVLIB/Downton Abbey (2010)/Season 01/downton abbey - s01e01 - episode title.mkv" ]
|
||||
}
|
||||
|
||||
@test "the mover leaves an episode the TV library already holds" {
|
||||
local src="$LIB/Monk 2002 Seasons 1 to 8/Season 1/Monk - S01E01 - Mr Monk and the Rival.mkv"
|
||||
for e in 01 02 03 04 05; do
|
||||
at "$TVLIB/Monk (2002)/Season 01/Monk - S01E$e - Mr Monk and the Rival.mkv" 3000000
|
||||
done
|
||||
tv_plan
|
||||
[ -z "$(tv_dst_of "$src")" ]
|
||||
[ -e "$src" ]
|
||||
grep -q "Monk.*already in" "$BATS_TEST_TMPDIR/tv.out"
|
||||
}
|
||||
|
||||
@test "an episode the TV library holds in another encode is still moved" {
|
||||
for e in 01 02 03 04 05; do
|
||||
at "$TVLIB/Big Little Lies/Season 01/Big Little Lies S01E$e 1080p.mp4" 4000000
|
||||
done
|
||||
tv_plan
|
||||
tv_apply
|
||||
[ -e "$TVLIB/Big Little Lies/Season 01/Big Little Lies S01E01.mp4" ]
|
||||
[ -e "$TVLIB/Big Little Lies/Season 01/Big Little Lies S01E01 1080p.mp4" ]
|
||||
}
|
||||
|
||||
@test "every file in the census is placed or kept — nothing is dropped" {
|
||||
plan
|
||||
python3 - "$ENUM" "$OUT" <<'PY'
|
||||
@@ -419,6 +525,22 @@ PY
|
||||
[ ! -e "$LIB/AMERICAN POP" ]
|
||||
}
|
||||
|
||||
@test "a sweep whose rmdir failed tries those folders again" {
|
||||
plan
|
||||
apply_plan
|
||||
mkdir -p "$LIB/AMERICAN POP/Screens"
|
||||
chmod 500 "$LIB/AMERICAN POP" # readable, but nothing can be removed
|
||||
run python3 "$APPLY" sweep --root "$LIB" --journal "$JOURNAL" --apply
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"left in place"* ]]
|
||||
[ -e "$LIB/AMERICAN POP/Screens" ]
|
||||
chmod 700 "$LIB/AMERICAN POP" # the operator cleared the blocker
|
||||
run python3 "$APPLY" sweep --root "$LIB" --journal "$JOURNAL" --apply
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"left in place: "* ]]
|
||||
[ ! -e "$LIB/AMERICAN POP" ]
|
||||
}
|
||||
|
||||
@test "sweep without --apply reports the husks and changes nothing" {
|
||||
plan
|
||||
apply_plan
|
||||
|
||||
Reference in new issue
Block a user