summaryrefslogtreecommitdiff
path: root/dotfiles/system/.local/bin/any2opus
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-07-16 11:07:55 -0500
committerCraig Jennings <c@cjennings.net>2025-07-16 11:07:55 -0500
commit3f4156d2c3c93d038d3b239672a33bbd51d47be7 (patch)
treec60ad8187525e3001b78350bf0938c151a7bb362 /dotfiles/system/.local/bin/any2opus
parent338cf81e20014a53589052a1da9b7c21c4c520e6 (diff)
latest updates as of 2025-07-16 @ 11:07 AM CDT
Diffstat (limited to 'dotfiles/system/.local/bin/any2opus')
-rwxr-xr-xdotfiles/system/.local/bin/any2opus99
1 files changed, 50 insertions, 49 deletions
diff --git a/dotfiles/system/.local/bin/any2opus b/dotfiles/system/.local/bin/any2opus
index 3fa4563..c5a7dbd 100755
--- a/dotfiles/system/.local/bin/any2opus
+++ b/dotfiles/system/.local/bin/any2opus
@@ -10,7 +10,7 @@ recursive=false
# Usage info
show_help() {
- cat << EOF
+ cat << EOF
Usage: ${0##*/} [-h] [-d] [-r] [-f FILE]
Convert audio/video files to the Opus format.
@@ -33,69 +33,70 @@ fi
# Identify arguments; quit if invalid argument
while getopts ":df:rh" opt; do
- case ${opt} in
- d)
- delete_after_conversion=true
- ;;
- f)
- filename=$OPTARG
- ;;
- r)
- recursive=true
- ;;
- h)
- show_help
- exit 0
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- show_help
- exit 1
- ;;
+ case ${opt} in
+ d)
+ delete_after_conversion=true
+ ;;
+ f)
+ filename=$OPTARG
+ ;;
+ r)
+ recursive=true
+ ;;
+ h)
+ show_help
+ exit 0
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ show_help
+ exit 1
+ ;;
esac
done
# Display error and quit if incompatible arguments
if [ "$recursive" = true ] && [ -n "$filename" ]
then
- echo "The -f and -r options cannot be used together."
- show_help
- exit 1
+ echo "The -f and -r options cannot be used together."
+ show_help
+ exit 1
+fi
# Convert function checks mime-type and converts/deletes a single file
convert() {
- f=$1
- # Check the mime-type of the file
- mime_type=$(file -b --mime-type "$f")
- # If the file is an audio or video file and not already in opus format then convert it to opus
- if [[ $mime_type == video/* || $mime_type == audio/* ]] && [[ $f != *.opus ]]; then
- ffmpeg -i "$f" "${f%.*}.opus"
- # If the '-d' option was specified, delete the original file after conversion
- if $delete_after_conversion; then
- rm "$f"
- fi
- fi
+ f=$1
+ # Check the mime-type of the file
+ mime_type=$(file -b --mime-type "$f")
+ # If the file is an audio or video file and not already in opus format then convert it to opus
+ if [[ $mime_type == video/* || $mime_type == audio/* ]] && [[ $f != *.opus ]]; then
+ ffmpeg -i "$f" "${f%.*}.opus"
+ # If the '-d' option was specified, delete the original file after conversion
+ if $delete_after_conversion; then
+ rm "$f"
+ fi
+ fi
}
# Use above convert function based on user's intended set of files
if [ "$recursive" = true ]
then
- # convert all media files in current and child directories
- find . -type f -exec bash -c 'convert "$0"' {} \;
+ # convert all media files in current and child directories
+ find . -type f -exec bash -c 'convert "$0"' {} \;
elif [[ -n $filename ]]
then
- # if filename is not empty, convert only this file
- convert $filename
+ # if filename is not empty, convert only this file
+ convert $filename
else
- # Convert all
- echo "All non-opus media files in the current directory will be converted. Originals are kept."
- read -p "Proceed? (Y/n) " -n 1 -r
- echo
- if [[ $REPLY =~ ^[Yy]$ ]]
- then
- # Iterate over each file in the directory and convert
- for f in *; do
- convert $f
- done
- fi
+ # Convert all
+ echo "All non-opus media files in the current directory will be converted. Originals are kept."
+ read -p "Proceed? (Y/n) " -n 1 -r
+ echo
+ if [[ $REPLY =~ ^[Yy]$ ]]
+ then
+ # Iterate over each file in the directory and convert
+ for f in *; do
+ convert $f
+ done
+ fi
fi