This guide documents two bash scripts designed to automate the processing of movie releases (e.g., from Usenet or scene releases) that are stored in .rar archives and optionally include .sfv verification files.
Choose between two modes:
- With Transcoding – Uses
ffmpegto re-encode the audio track (e.g., to AAC for better compatibility). - Copy Only – Simply extracts and moves the MKV file with no encoding.
UPLOAD and RETAIL-NEW.
⚙️ Requirements
Both scripts require the following tools to be installed:
unrar– For extracting RAR filescksfv– For verifying file integrity via .sfvffmpeg– (Only for the transcoding script)
🔧 Install on Ubuntu/Debian
sudo apt update
sudo apt install unrar cksfv ffmpeg🔁 Script 1: unrar-moviez-transcode.sh (with ffmpeg)
This script performs the following steps:
- Scans each subfolder in the
UPLOADdirectory - Checks for an
.sfvfile and verifies the archive integrity - Extracts the
.mkvfile usingunrar - Re-encodes the audio stream to AAC using
ffmpeg(video is copied without re-encoding) - Moves the result to the
RETAIL-NEWdirectory - Deletes the original folder
#!/bin/bash
# === Configuration ===
bindir="/home/VOD"
lockfile="$bindir/.lockfile_unrar"
upload="$bindir/UPLOAD"
files="$bindir/RETAIL-NEW"
# === Dependency check ===
for cmd in cksfv unrar ffmpeg; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is not installed."
exit 1
fi
done
# === Prevent parallel execution ===
[ -f "$lockfile" ] && echo "Script already running." && exit 1
touch "$lockfile"
for dir in "$upload"/*/; do
[ -d "$dir" ] || continue
echo "[*] Processing $dir"
cd "$dir"
if ls *.sfv 1> /dev/null 2>&1; then
echo "Verifying archive..."
cksfv -q *.sfv || continue
fi
unrar e -y *.rar
mkv=$(ls *.mkv | head -n1)
if [ -n "$mkv" ]; then
out="$files/$(basename "$dir").mkv"
echo "Transcoding audio..."
ffmpeg -i "$mkv" -c:v copy -c:a aac -b:a 160k "$out"
echo "[✓] Done: $out"
fi
rm -rf "$dir"
done
rm -f "$lockfile"📦 Script 2: unrar-moviez-copy.sh (copy only)
Same as above, but without transcoding. It simply extracts and moves the first .mkv file found.
#!/bin/bash
# === Configuration ===
bindir="/home/VOD"
lockfile="$bindir/.lockfile_unrar"
upload="$bindir/UPLOAD"
files="$bindir/RETAIL-NEW"
# === Dependency check ===
for cmd in cksfv unrar; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is not installed."
exit 1
fi
done
# === Prevent parallel execution ===
[ -f "$lockfile" ] && echo "Script already running." && exit 1
touch "$lockfile"
for dir in "$upload"/*/; do
[ -d "$dir" ] || continue
echo "[*] Processing $dir"
cd "$dir"
if ls *.sfv 1> /dev/null 2>&1; then
echo "Verifying archive..."
cksfv -q *.sfv || continue
fi
unrar e -y *.rar
mkv=$(ls *.mkv | head -n1)
if [ -n "$mkv" ]; then
mv "$mkv" "$files/$(basename "$dir").mkv"
echo "[✓] Copied: $files/$(basename "$dir").mkv"
fi
rm -rf "$dir"
done
rm -f "$lockfile"📅 Automation (Optional)
*/15 * * * * /home/VOD/unrar-moviez-transcode.sh >/dev/null 2>&1🔐 Notes
- Ensure that folders like
UPLOADandRETAIL-NEWexist and are writable. - Lockfile prevents multiple parallel executions (adjust path as needed).
- You can run the second script alternately if no transcoding is needed.