arnaucube
arnaucube/configsPublic Self-hosted repository
configs/bin/parse-blueray
bin/parse-bluerayRaw
 1#!/usr/bin/env bash
 2
 3# NOTE: needs mkvtoolnix installed, ie. `apt install mkvtoolnix`.
 4
 5set -e
 6
 7OUT="$PWD"
 8echo "processing current directory: $OUT"
 9
10for dir in */ ; do
11  [ -d "$dir" ] || continue
12  echo "processing $dir"
13
14  cd "$dir"
15
16  # prefer .rar if present
17  rarfile=$(ls *.rar 2>/dev/null | head -n1)
18  if [ -z "$rarfile" ]; then
19    rarfile=$(ls *.r00 2>/dev/null | head -n1)
20  fi
21
22  if [ -z "$rarfile" ]; then
23    echo "  no .rar/.r00 in $dir, skipping"
24    cd ..
25    continue
26  fi
27
28  unrar x -o+ "$rarfile" . || { echo "  extraction failed in $dir"; cd ..; continue; }
29
30  # find first video file
31  video=$(find . -maxdepth 1 -type f \
32    \( -iname '*.mkv' -o -iname '*.mp4' -o -iname '*.avi' -o -iname '*.m2ts' \) \
33    ! -iname '*sample*' | head -n1)
34
35  if [ -z "$video" ]; then
36    echo "  no video found after extraction in $dir"
37    cd ..
38    continue
39  fi
40
41  base=$(basename "$dir" /)
42  out="$OUT/${base}.mkv"
43
44  echo "  muxing '$video' -> '$out'"
45  mkvmerge -o "$out" "$video"
46
47  cd ..
48done
49