Skip to content

Commit a98a18d

Browse files
committed
feat: Add colours to the script to make it beautiful
1 parent 571d01d commit a98a18d

1 file changed

Lines changed: 45 additions & 31 deletions

File tree

audio2mp3.sh

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ set -euo pipefail
1111
# Last Modified: 14-03-2025
1212
# Usage: audio2mp3.sh -f <input_file> [-o <output_path>] | -d <directory> [-o <output_directory>] [-r] [-c] [-s] [-nc]
1313

14+
# Color definitions
15+
RED="\033[0;31m"
16+
GREEN="\033[0;32m"
17+
YELLOW="\033[1;33m"
18+
BLUE="\033[0;34m"
19+
MAGENTA="\033[0;35m"
20+
CYAN="\033[0;36m"
21+
WHITE="\033[1;37m"
22+
BOLD="\033[1m"
23+
NC="\033[0m" # No Color
24+
1425
# Default values
1526
OUTPUT_FILE=""
1627
OUTPUT_DIR=""
@@ -21,40 +32,41 @@ NO_CONFIRM=false # -nc flag
2132

2233
# Function to display ASCII art
2334
show_ascii() {
24-
echo "
35+
echo -e "${CYAN}
2536
2637
█████╗ ██╗ ██╗██████╗ ██╗ ██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗
2738
██╔══██╗██║ ██║██╔══██╗██║██╔═══██╗╚════██╗████╗ ████║██╔══██╗╚════██╗
2839
███████║██║ ██║██║ ██║██║██║ ██║ █████╔╝██╔████╔██║██████╔╝ █████╔╝
2940
██╔══██║██║ ██║██║ ██║██║██║ ██║██╔═══╝ ██║╚██╔╝██║██╔═══╝ ╚═══██╗
3041
██║ ██║╚██████╔╝██████╔╝██║╚██████╔╝███████╗██║ ╚═╝ ██║██║ ██████╔╝
3142
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═════╝
32-
"
43+
${NC}"
44+
echo -e "${MAGENTA}🎵 Audio to MP3 Converter - v0.2.1 🎵${NC}\n"
3345
}
3446

3547
# Function to display help information
3648
show_help() {
37-
echo "
38-
Converts single or multiple audio files to MP3 using FFmpeg. Supports batch processing, metadata
49+
echo -e "
50+
${BOLD}Converts single or multiple audio files to MP3 using FFmpeg.${NC} Supports batch processing, metadata
3951
preservation, and optional copy mode. Saves output in the input file's directory or a specified
4052
location.
4153
42-
Supported audio formats: WAV, FLAC, OGG, AAC, M4A, ALAC, AIFF, and OPUS.
54+
${YELLOW}Supported audio formats:${NC} WAV, FLAC, OGG, AAC, M4A, ALAC, AIFF, and OPUS.
4355
44-
Usage: $0 -f <input_file> [-o <output_path>] | -d <directory> [-o <output_directory>] [-r] [-c] [-s] [-nc]
56+
${BOLD}Usage:${NC} $0 -f <input_file> [-o <output_path>] | -d <directory> [-o <output_directory>] [-r] [-c] [-s] [-nc]
4557
46-
Options:
47-
Required Flags (Must provide either -f or -d):
48-
-f, --file <input_file> Convert a single file.
49-
-d, --directory <directory> Convert all supported files in a directory.
58+
${GREEN}Options:${NC}
59+
${BOLD}Required Flags${NC} (Must provide either -f or -d):
60+
${BLUE}-f, --file <input_file>${NC} Convert a single file.
61+
${BLUE}-d, --directory <directory>${NC} Convert all supported files in a directory.
5062
51-
Optional Flags:
52-
-o, --output <output_path> Specify output file (if using -f) or output directory (if using -d).
53-
-r, --recursive Process directories recursively.
54-
-c, --copy Convert without re-encoding if possible.
55-
-s, --skip-existing Skip existing files without prompt.
56-
-nc, --no-confirm Automatically overwrite existing files without asking.
57-
-h, --help Show this help message.
63+
${BOLD}Optional Flags:${NC}
64+
${CYAN}-o, --output <output_path>${NC} Specify output file (if using -f) or output directory (if using -d).
65+
${CYAN}-r, --recursive${NC} Process directories recursively.
66+
${CYAN}-c, --copy${NC} Convert without re-encoding if possible.
67+
${CYAN}-s, --skip-existing${NC} Skip existing files without prompt.
68+
${CYAN}-nc, --no-confirm${NC} Automatically overwrite existing files without asking.
69+
${CYAN}-h, --help${NC} Show this help message.
5870
"
5971
}
6072

@@ -66,28 +78,28 @@ convert_to_mp3() {
6678
# Check if file exists and confirm overwrite only once
6779
if [ -f "$output_file" ]; then
6880
if [ "$SKIP_EXISTING" = true ]; then
69-
echo "[+] Skipping existing file '$output_file'."
81+
echo -e "[${YELLOW}+${NC}] ${YELLOW}Skipping existing file '${BOLD}$output_file${NC}${YELLOW}'.${NC}"
7082
return
7183
fi
7284
if [ "$NO_CONFIRM" = false ]; then
73-
echo "[+] Warning: '$output_file' already exists."
74-
echo "[+] Do you want to overwrite it? (y/n)"
85+
echo -e "[${YELLOW}+${NC}] ${YELLOW}Warning: '${BOLD}$output_file${NC}${YELLOW}' already exists.${NC}"
86+
echo -e "[${BLUE}+${NC}] ${BLUE}Do you want to overwrite it? (y/n)${NC}"
7587
read -r overwrite
7688
if [[ "$overwrite" != "y" ]]; then
77-
echo "[+] Skipping conversion for '$input_file'."
89+
echo -e "[${RED}+${NC}] ${RED}Skipping conversion for '${BOLD}$input_file${NC}${RED}'.${NC}"
7890
return
7991
fi
8092
fi
8193
fi
8294

8395
if [ "$COPY_MODE" = true ]; then
84-
echo "[+] Copying '$input_file' to '$output_file' while preserving metadata..."
96+
echo -e "[${GREEN}+${NC}] ${GREEN}Copying '${BOLD}$input_file${NC}${GREEN}' to '${BOLD}$output_file${NC}${GREEN}' while preserving metadata...${NC}"
8597
ffmpeg -i "$input_file" -map_metadata 0:s:a:0 -acodec copy -y "$output_file"
8698
else
87-
echo "[+] Converting '$input_file' to '$output_file' while preserving metadata..."
99+
echo -e "[${GREEN}+${NC}] ${GREEN}Converting '${BOLD}$input_file${NC}${GREEN}' to '${BOLD}$output_file${NC}${GREEN}' while preserving metadata...${NC}"
88100
ffmpeg -i "$input_file" -map_metadata 0:s:a:0 -q:a 0 -y "$output_file"
89101
fi
90-
echo "[+] Operation completed."
102+
echo -e "[${MAGENTA}+${NC}] ${MAGENTA}Operation completed.${NC}"
91103
}
92104

93105
# Function to process all audio files in a directory
@@ -97,22 +109,24 @@ process_directory() {
97109

98110
local files
99111
if [ "$RECURSIVE_MODE" = true ]; then
112+
echo -e "[${BLUE}+${NC}] ${BLUE}Searching recursively in '${BOLD}$dir${NC}${BLUE}'...${NC}"
100113
files=$(find "$dir" -type f \( -iname "*.wav" -o -iname "*.flac" -o -iname "*.ogg" -o -iname "*.aac" -o -iname "*.m4a" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.opus" \))
101114
else
115+
echo -e "[${BLUE}+${NC}] ${BLUE}Searching in '${BOLD}$dir${NC}${BLUE}'...${NC}"
102116
files=$(find "$dir" -maxdepth 1 -type f \( -iname "*.wav" -o -iname "*.flac" -o -iname "*.ogg" -o -iname "*.aac" -o -iname "*.m4a" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.opus" \))
103117
fi
104118

105119
if [[ -z "$files" ]]; then
106-
echo "[+] No supported audio files found in '$dir'."
120+
echo -e "[${RED}+${NC}] ${RED}No supported audio files found in '${BOLD}$dir${NC}${RED}'.${NC}"
107121
exit 1
108122
fi
109123

110-
echo "[+] Found the following audio files in '$dir':"
111-
echo "$files"
112-
echo "[+] Do you want to proceed with conversion? (y/n)"
124+
echo -e "[${GREEN}+${NC}] ${GREEN}Found the following audio files in '${BOLD}$dir${NC}${GREEN}':${NC}"
125+
echo -e "${CYAN}$files${NC}"
126+
echo -e "[${YELLOW}+${NC}] ${YELLOW}Do you want to proceed with conversion? (y/n)${NC}"
113127
read -r confirmation
114128
if [[ "$confirmation" != "y" ]]; then
115-
echo "[+] Operation cancelled."
129+
echo -e "[${RED}+${NC}] ${RED}Operation cancelled.${NC}"
116130
exit 0
117131
fi
118132

@@ -173,7 +187,7 @@ main() {
173187
*)
174188
show_ascii
175189
show_help
176-
echo "Invalid option: $1"
190+
echo -e "[${RED}+${NC}] ${RED}Invalid option: $1${NC}"
177191
exit 1
178192
;;
179193
esac
@@ -195,7 +209,7 @@ main() {
195209
else
196210
show_ascii
197211
show_help
198-
echo "[+] No input file or directory provided."
212+
echo -e "[${RED}+${NC}] ${RED}No input file or directory provided.${NC}"
199213
exit 1
200214
fi
201215
}

0 commit comments

Comments
 (0)