Skip to content

Instantly share code, notes, and snippets.

@Allypost
Created October 5, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Allypost/c383912e2612716d20d2fca4043a8778 to your computer and use it in GitHub Desktop.
Save Allypost/c383912e2612716d20d2fca4043a8778 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
printf "\e[3;4mScanning...\e[0m\r"
FILES=`find ./*.webm -maxdepth 1 -type f 2>/dev/null`
FILES=($FILES)
MAX_FILE_LEN=-1
for str in "${FILES[@]}"; do
filename=$(basename -- "$str")
extension="${filename##*.}"
filename="${filename%.*}"
if [[ ${#filename} -gt ${MAX_FILE_LEN} ]]; then
MAX_FILE_LEN=${#filename}
fi
done
total="${#FILES[@]}"
success=0
for filepath in "${FILES[@]}"; do
location="$PWD"
filename=$(basename -- "$filepath")
extension="${filename##*.}"
filename="${filename%.*}"
oldName="${filename}.${extension}"
newName="${filename}.mp4"
oldFull="${location}/${oldName}"
newFull="${location}/${newName}"
if [ -f "$newFull" ]; then
if [ -f "$oldFull" ]; then
# kioclient5 move "$newFull" trash:/ 2>/dev/null
rm "$newFull"
fi
fi
printf "Converting \e[1;36;40m%-${MAX_FILE_LEN}s\e[0m from \e[1m\`%s\`\e[0m to \e[1m\`%s\`\e[0m... " "$filename" "$extension" "mp4"
__OLD_TIMEFORMAT=$TIMEFORMAT
export TIMEFORMAT='%3lR'
res=`(time ffmpeg -y -loglevel panic -i "$oldFull" "$newFull") 2>&1`
res_exit_code=$?
cmd_duration=$(echo "$res" | tail -n1)
export TIMEFORMAT=${__OLD_TIMEFORMAT}
unset __OLD_TIMEFORMAT
if [[ "$res_exit_code" -ne '0' ]]; then
echo -e "\e[1;101m DEAD \e[0m $res_exit_code"
rm "$newFull" 2>/dev/null
continue
fi
if [ -z `find "$newFull" -maxdepth 1 -type f -size +1k 2>/dev/null` ]; then
echo -e "\e[1;101m FAIL \e[0m"
rm "$newFull" 2>/dev/null
continue
fi
touch -r "$oldFull" "$newFull"
# kioclient5 move "$oldFull" trash:/ 2>/dev/null
rm "$oldFull"
echo -e "\e[30;42m DONE \e[0m \e[4m$cmd_duration\e[0m"
((success++))
done
echo -e "\e[30;42m FINISHED $success/$total \e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment