🎬 Unrar Moviez Script Suite


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 ffmpeg to re-encode the audio track (e.g., to AAC for better compatibility).
  • Copy Only – Simply extracts and moves the MKV file with no encoding.
Recommended for: Automated server environments, Plex/Emby setups, or NAS workflows with folders like UPLOAD and RETAIL-NEW.

⚙️ Requirements

Both scripts require the following tools to be installed:

  • unrar – For extracting RAR files
  • cksfv – For verifying file integrity via .sfv
  • ffmpeg – (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:

  1. Scans each subfolder in the UPLOAD directory
  2. Checks for an .sfv file and verifies the archive integrity
  3. Extracts the .mkv file using unrar
  4. Re-encodes the audio stream to AAC using ffmpeg (video is copied without re-encoding)
  5. Moves the result to the RETAIL-NEW directory
  6. 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 UPLOAD and RETAIL-NEW exist and are writable.
  • Lockfile prevents multiple parallel executions (adjust path as needed).
  • You can run the second script alternately if no transcoding is needed.