Fredrik Erlandsson

Logo

PhD in Computer science, data scientist at Consid AB.

Script to extract movies from an img file.

2014-02-11

The following scipt can be used to extract movies from an img file. The minlength=600 reflects that the movie must be 600 seconds to be included.

#/bin/sh

for IMG in `find . -iname \*.img`; do
  DIR=`dirname $IMG`
  basename ${IMG%.img}
  /Applications/MakeMKV.app/Contents/MacOS/makemkvcon \
    --minlength=600 mkv \
    iso:${IMG} all `dirname ${IMG}`

  # Rename files
  for MKV in `ls $DIR/title*.mkv`; do
    F=`basename ${MKV}`
    mv -v $MKV ${IMG%.img}.${F:5:2}.mkv
  done
done

Script to rename mkv files

The following is a script used to rename mkv files based on size. The assumption is that small files just are trailers.

#!/bin/bash

for d in *; do
  cd "$d"; pwd;
  rm *.srt;
  for f in *; do
    if [ `du -m "$f" | cut -f1` -lt 1000 ]; then
      mv "$f" "${d// /_}_#`echo $f| \
        sed -e 's/.*-\([0-2][0-9]\).*/\1/' -e 's/.*le\([0-2][0-9]\).*/\1/' -e 's/.*t\([0-2][0-9]\).*/\1/'`-trailer.mkv"
    else
      mv -v "$f" "$d.mkv"
  done
  cd /volume3/Media/makemkv/done/
  echo $d
done