-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetroConvert.command
More file actions
executable file
·84 lines (72 loc) · 2.87 KB
/
Copy pathRetroConvert.command
File metadata and controls
executable file
·84 lines (72 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
#===============================================================================
# RetroConvert.command -- double-click me.
#
# Converts EVERY video in the folder this file sits in, including all
# subfolders (so drop it in the root of a shows folder or an SD card and it
# handles Season 01/, Season 02/, ... on its own).
#
# Copy this file wherever you want to convert. It looks for retro-convert.sh
# next to itself first, then falls back to ~/Desktop/RetroConvert/.
#===============================================================================
set -u
# Resolve the folder this .command lives in, following a symlink if needed.
SELF="$0"
while [ -L "$SELF" ]; do SELF="$(readlink "$SELF")"; done
ROOT="$(cd "$(dirname "$SELF")" && pwd)"
# Find the engine.
ENGINE=""
for cand in "$ROOT/retro-convert.sh" "$HOME/Desktop/RetroConvert/retro-convert.sh"; do
[ -f "$cand" ] && { ENGINE="$cand"; break; }
done
if [ -z "$ENGINE" ]; then
echo "Could not find retro-convert.sh."
echo "Keep this file next to it, or leave a copy in ~/Desktop/RetroConvert/."
echo; read -r -p "Press Return to close." _; exit 1
fi
chmod +x "$ENGINE" 2>/dev/null
bold=$'\033[1m'; dim=$'\033[2m'; ylw=$'\033[33m'; grn=$'\033[32m'; rst=$'\033[0m'
clear
cat <<BANNER
${bold}RetroConvert${rst} -- 480p SD for FieldStation42
Folder: ${bold}$ROOT${rst}
(this folder and everything inside it)
BANNER
# --- safety: show the plan before touching anything --------------------------
# WHY: double-clicking is easy to do by accident, and the default behaviour
# deletes each source once its replacement verifies. Always show the counts and
# make the user say yes first.
echo "${dim}Scanning... (reads every file header, can take a minute on a slow card)${rst}"
echo
"$ENGINE" "$ROOT" --dry-run 2>&1 | sed -n '/^Scanning/,$p'
echo
PLAN=$(ls -td "$ROOT"/runs/* 2>/dev/null | head -1)
[ -z "$PLAN" ] && PLAN=$(ls -td "$HOME/Desktop/RetroConvert"/runs/* 2>/dev/null | head -1)
NEED=0
[ -n "$PLAN" ] && [ -f "$PLAN/jobs.txt" ] && NEED=$(wc -l < "$PLAN/jobs.txt" | tr -d ' ')
if [ "$NEED" -eq 0 ]; then
echo "${grn}Nothing needs converting here.${rst}"
echo; read -r -p "Press Return to close." _; exit 0
fi
echo "${ylw}This will convert $NEED file(s) and DELETE each original once its"
echo "replacement passes verification. Originals are only removed after a"
echo "successful check; anything that fails keeps its source.${rst}"
echo
printf 'Type %syes%s to start (anything else cancels): ' "$bold" "$rst"
read -r answer
case "$answer" in
yes|YES|Yes) ;;
*) echo; echo "Cancelled. Nothing was changed."; echo
read -r -p "Press Return to close." _; exit 0 ;;
esac
echo
"$ENGINE" "$ROOT"
STATUS=$?
echo
if [ $STATUS -eq 0 ]; then
echo "${grn}Finished.${rst}"
else
echo "${ylw}Stopped (exit $STATUS). Re-run to resume -- finished files are skipped.${rst}"
fi
echo
read -r -p "Press Return to close this window." _