#!/usr/bin/env sh

# rename .MKV -> .MKV
count=`ls -1 *.JPG 2>/dev/null | wc -l`
if [ $count != 0 ]; then
  rename MKV mkv *.MKV
fi
  
# convert to opus
count=`ls -1 *.mkv 2>/dev/null | wc -l`
if [ $count != 0 ]; then
  for i in *.mkv; do
    ffmpeg -i "$i" "${i%.mkv}.opus";
    rm "$i";
  done
fi

# rename .WEBM -> .webm
count=`ls -1 *.WEBM 2>/dev/null | wc -l`
if [ $count != 0 ]; then 
  rename WEBM webm *.WEBM
fi
  
# convert to opus
count=`ls -1 *.webm 2>/dev/null | wc -l`
if [ $count != 0 ]; then
  for i in *.webm; do
    ffmpeg -i "$i" "${i%.webm}.opus";
    rm "$i";
  done
fi 

