This might be lined up better than the code block below - https://gist.github.com/4540352
- Code: Select all
#!/usr/bin/env bash
# youtube2what
[[ $# -ne 0 ]] || { echo "
Missing argument.
You need to name at least one video file.
" ; exit 1 ; }
# if yad is installed, use in preference
if [[ -f /usr/bin/yad ]]; then
DIALOG="yad"
INFO="image=gtk-dialog-info"
QUESTION="image=gtk-dialog-question"
WARNING="image=gtk-dialog-warning"
ERROR="image=gtk-dialog-error"
#buttons
BUTTON0="button"
BUTTON1="button"
BUTTON0NUM=":0"
BUTTON1NUM=":1"
#cancel button always returns 1 as $?
#ok button always returns 0 as $?
#ok is default (highlighted)
#buttons in yad dialog window may show reversed from zenity window, e.g.
#yad: ok -- cancel (0 -- 1)
#zenity: cancel -- ok (1 -- 0)
elif [[ -f /usr/bin/zenity ]]; then
# use zenity
DIALOG="zenity"
INFO="info"
QUESTION="question"
WARNING="warning"
ERROR="error"
#buttons
BUTTON0="ok-label"
BUTTON1="cancel-label"
BUTTON0NUM=""
BUTTON1NUM=""
else
nodialog="yes"
fi
if [[ $nodialog = "yes" ]]; then
while true ; do
echo "
Enter one of the following formats:
mp3 flac ogg avi mp4 mkv
"
read format
done
else
format=$($DIALOG --entry --title="Choose format" --text="Enter one of the following target formats:
mp3 flac ogg avi mp4 mkv")
fi
case "$format" in
mp3)
for MOVIE in "$@" ; do
AUDIOOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -f mp3 "$AUDIOOUT".mp3
done ;;
flac)
for MOVIE in "$@" ; do
AUDIOOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -f flac "$AUDIOOUT".flac
done ;;
ogg)
for MOVIE in "$@" ; do
AUDIOOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -f ogg "$AUDIOOUT".ogg
done ;;
avi)
for MOVIE in "$@" ; do
VIDOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -b 798k -ab 128k "$VIDOUT".avi
done ;;
mp4)
for MOVIE in "$@" ; do
VIDOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -acodec copy -vcodec copy "$VIDOUT".mp4
done ;;
mkv)
for MOVIE in "$@" ; do
VIDOUT=$(basename "$MOVIE" |sed 's/\(.*\)\..*/\1/')
ffmpeg -i "$MOVIE" -acodec copy -vcodec copy "$VIDOUT".mkv
done ;;
*) if [[ $nodialog = "yes" ]]; then
echo "
Unsupported format. Try one of these next time:
mp3 flac avi mp4 mkv
"
exit 1
else
$DIALOG --$ERROR --title=Error! --text="Unsupported format. Try one of these next time\:
mp3 flac ogg avi mp4 mkv "
exit 1
fi
esac
exit 0