Skip to content

Commit 2fc8916

Browse files
Merge pull request #1 from homelabshq/feat/release-0.0.1
2 parents a98a18d + 7be7e14 commit 2fc8916

3 files changed

Lines changed: 74 additions & 47 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 beecave-homelab
3+
Copyright (c) 2025 Kanishk Pachauri
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a Bash script that converts various audio file formats (e.g., `.wav`, `.
44

55
## Versions
66

7-
**Current version**: 0.2.1
7+
**Current version**: 0.0.1
88

99
## Table of Contents
1010

audio2mp3.sh

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ set -euo pipefail
44
# Script Description: Converts single or multiple audio files to MP3 using FFmpeg.
55
# Supports batch processing, metadata preservation, and optional copy mode.
66
# Saves output in the input file's directory or a specified location.
7-
# Author: elvee
8-
# Version: 0.2.1
7+
# Author: Mr-Sunglasses
8+
# Version: 0.0.1
99
# License: MIT
10-
# Creation Date: 27-09-2024
11-
# Last Modified: 14-03-2025
1210
# Usage: audio2mp3.sh -f <input_file> [-o <output_path>] | -d <directory> [-o <output_directory>] [-r] [-c] [-s] [-nc]
1311

1412
# Color definitions
@@ -20,6 +18,7 @@ MAGENTA="\033[0;35m"
2018
CYAN="\033[0;36m"
2119
WHITE="\033[1;37m"
2220
BOLD="\033[1m"
21+
DIM="\033[2m"
2322
NC="\033[0m" # No Color
2423

2524
# Default values
@@ -28,7 +27,7 @@ OUTPUT_DIR=""
2827
COPY_MODE=false
2928
RECURSIVE_MODE=false
3029
SKIP_EXISTING=false
31-
NO_CONFIRM=false # -nc flag
30+
NO_CONFIRM=false # -nc flag
3231

3332
# Function to display ASCII art
3433
show_ascii() {
@@ -41,7 +40,7 @@ show_ascii() {
4140
██║ ██║╚██████╔╝██████╔╝██║╚██████╔╝███████╗██║ ╚═╝ ██║██║ ██████╔╝
4241
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═════╝
4342
${NC}"
44-
echo -e "${MAGENTA}🎵 Audio to MP3 Converter - v0.2.1 🎵${NC}\n"
43+
echo -e "${MAGENTA}🎵 Audio to MP3 Converter - v0.0.1 🎵${NC}\n"
4544
}
4645

4746
# Function to display help information
@@ -70,6 +69,24 @@ ${GREEN}Options:${NC}
7069
"
7170
}
7271

72+
# Function to check prerequisites
73+
check_prerequisites() {
74+
echo -e "[${BLUE}+${NC}] ${DIM}Checking prerequisites...${NC}"
75+
76+
# Check if FFmpeg is installed
77+
if ! command -v ffmpeg &>/dev/null; then
78+
echo -e "[${RED}${NC}] ${RED}FFmpeg is not installed or not in PATH.${NC}"
79+
echo -e " ${YELLOW}Please install FFmpeg:${NC}"
80+
echo -e " ${CYAN}Ubuntu/Debian:${NC} sudo apt install ffmpeg"
81+
echo -e " ${CYAN}macOS:${NC} brew install ffmpeg"
82+
echo -e " ${CYAN}Windows:${NC} Download from https://ffmpeg.org/download.html"
83+
exit 2
84+
fi
85+
86+
echo -e "[${GREEN}${NC}] ${GREEN}FFmpeg found: $(ffmpeg -version | head -n1 | cut -d' ' -f3)${NC}"
87+
echo -e "[${GREEN}+${NC}] ${GREEN}All prerequisites are met.${NC}"
88+
}
89+
7390
# Function to convert a single audio file to MP3 while preserving metadata
7491
convert_to_mp3() {
7592
local input_file="$1"
@@ -151,50 +168,56 @@ main() {
151168

152169
while [[ $# -gt 0 ]]; do
153170
case $1 in
154-
-f|--file)
155-
input_file="$2"
156-
shift 2
157-
;;
158-
-o|--output)
159-
OUTPUT_DIR="$2"
160-
shift 2
161-
;;
162-
-d|--directory)
163-
directory="$2"
164-
shift 2
165-
;;
166-
-r|--recursive)
167-
RECURSIVE_MODE=true
168-
shift
169-
;;
170-
-c|--copy)
171-
COPY_MODE=true
172-
shift
173-
;;
174-
-s|--skip-existing)
175-
SKIP_EXISTING=true
176-
shift
177-
;;
178-
-nc|--no-confirm)
179-
NO_CONFIRM=true
180-
shift
181-
;;
182-
-h|--help)
183-
show_ascii
184-
show_help
185-
exit 0
186-
;;
187-
*)
188-
show_ascii
189-
show_help
190-
echo -e "[${RED}+${NC}] ${RED}Invalid option: $1${NC}"
191-
exit 1
192-
;;
171+
-f | --file)
172+
input_file="$2"
173+
shift 2
174+
;;
175+
-o | --output)
176+
OUTPUT_DIR="$2"
177+
shift 2
178+
;;
179+
-d | --directory)
180+
directory="$2"
181+
shift 2
182+
;;
183+
-r | --recursive)
184+
RECURSIVE_MODE=true
185+
shift
186+
;;
187+
-c | --copy)
188+
COPY_MODE=true
189+
shift
190+
;;
191+
-s | --skip-existing)
192+
SKIP_EXISTING=true
193+
shift
194+
;;
195+
-nc | --no-confirm)
196+
NO_CONFIRM=true
197+
shift
198+
;;
199+
-h | --help)
200+
show_ascii
201+
check_prerequisites
202+
echo
203+
show_help
204+
exit 0
205+
;;
206+
*)
207+
show_ascii
208+
check_prerequisites
209+
echo
210+
show_help
211+
echo -e "[${RED}+${NC}] ${RED}Invalid option: $1${NC}"
212+
exit 1
213+
;;
193214
esac
194215
done
195216

196217
if [[ -n "$directory" ]]; then
197218
show_ascii
219+
check_prerequisites
220+
echo
198221
process_directory "$directory"
199222
elif [[ -n "$input_file" ]]; then
200223
local file_name
@@ -205,9 +228,13 @@ main() {
205228

206229
local output_file="${destination_dir}/${file_name%.*}.mp3"
207230
show_ascii
231+
check_prerequisites
232+
echo
208233
convert_to_mp3 "$input_file" "$output_file"
209234
else
210235
show_ascii
236+
check_prerequisites
237+
echo
211238
show_help
212239
echo -e "[${RED}+${NC}] ${RED}No input file or directory provided.${NC}"
213240
exit 1

0 commit comments

Comments
 (0)