Skip to content

Instantly share code, notes, and snippets.

@hroncok
Last active December 10, 2015 18:58
Show Gist options
  • Save hroncok/4478724 to your computer and use it in GitHub Desktop.
Save hroncok/4478724 to your computer and use it in GitHub Desktop.
Renames subtitles to video file name, use as a Custom action for Thunar
#!/bin/bash
# BSDL Miro Hrončok <[email protected]>
# subrnm .avi .srt (or vice versa)
if [ $# -ne 2 ]; then
#echo "USAGE: subrnm .avi .srt (or vice versa)"
zenity --error --text "Nebyly vybrány dva soubory"
exit 1
fi
# Which is which
filename=$(basename "$1")
extension=${filename##*.}
# Video first
if [ "$extension" == "avi" ] || [ "$extension" == "mp4" ] || [ "$extension" == "mkv" ] || [ "$extension" == "part" ] || [ "$extension" == "crdownload" ]; then
#echo "First file is a video"
subtitles=$(basename "$2")
extension=${subtitles##*.}
if [ "$extension" != "srt" ] && [ "$extension" != "sub" ]; then
#echo "First file is a video. Second file are not subtitles"
zenity --error --text "První soubor je videem, ale druhý nejsou titulky"
exit 1
fi
filename=${filename%.*}
dir=$(dirname "$1")
mv "$2" "$dir/$filename.$extension"
exit 0
fi
# Subtitles first
if [ "$extension" == "srt" ] || [ "$extension" == "sub" ]; then
#echo "First file are subtitles"
video=$(basename "$2")
videext=${video##*.}
if [ "$videext" != "avi" ] && [ "$videext" != "mp4" ] && [ "$videext" != "mkv" ] && [ "$videext" != "crdownload" ] && [ "$videext" != "part" ]; then
#echo "First file are subtitles. Second file in not a video"
zenity --error --text "První soubor jsou titulky, ale druhý není videem"
exit 1
fi
video=${video%.*}
dir=$(dirname "$2")
mv "$1" "$dir/$video.$extension"
exit 0
fi
#echo "USAGE: subrnm .avi .srt (or vice versa)"
zenity --error --text "První soubor není videem ani to nejsou titulky"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment