-
Notifications
You must be signed in to change notification settings - Fork 0
/
musictag
executable file
·101 lines (91 loc) · 3.19 KB
/
musictag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
##### MP3 tagger/renamer [prereq: eyeD3]
### v0.3 - correct mp3 filename handling with IFS
### v0.2 - var rewrite for lead/trail spaces
### v0.1 - first rev + renaming
# Load myecho for nicer output
if ! type _MYECHO >/dev/null 2>&1; then
if [ -f "/etc/profile.d/01-myecho-colors.sh" ]; then
source /etc/profile.d/01-myecho-colors.sh >/dev/null 2>&1
elif [ -f "$HOME/01-myecho-colors.sh" ]; then
source "$HOME/01-myecho-colors.sh" >/dev/null 2>&1
else
echo "Nice Output - Install 'myecho' function (in homedir: 01-myecho-colors.sh)"
cd "$HOME"
curl -s -LO https://raw.githubusercontent.com/zephxs/bash/master/functions/01-myecho-colors.sh
head -20 01-myecho-colors.sh |grep -q "^_MYECHO () {" && echo "myecho installed!" || { echo "myecho install failed, exit.."; exit 1; }
source "$HOME/01-myecho-colors.sh" >/dev/null 2>&1
fi
fi
# usage
[ "$1" = '-h' -o "$1" = '--help' ] && _MYECHO -p "Usage:
# Accept mp3 file as only argument" && \
echo "$(basename $0) /path/to/file.mp3
" && exit 0
### AUTO INSTALLER / UPDATER for Termux
if type pkg >/dev/null ; then
# required pipx for easy install and update under venv
type pip >/dev/null || ( echo "... Installing pipx" && pkg install python3 && python3 -m pip install pipx; )
# install yt-dlp and update if bin older than 15 days
find $(type -P eyeD3) -mtime +15 -exec python3 -m pipx upgrade eyeD3 \; || python3 -m pipx install eyeD3
fi
# test mp3 file path as only argument
[ -z "$1" ] && { echo "Please input file path as argument" && exit 1; } || _MP3="$@"
[ -f "$_MP3" ] || { echo "$_MP3 is not a valid file.." && exit 1; }
_MYECHO -l
_MYECHO "MP3 file"
[ "$(awk -F'.' '{print $NF}' <<<$_MP3)" = 'mp3' ] && _OK || { _KO; _MYECHO -c red -p "Not a valid mp3 file"; exit 1; }
_MYECHO -c green -p "$_MP3"
# mod IFS for files containing spaces
_OLDIFS="$IFS" && IFS=''
_MP3Z="$(basename -s '.mp3' $_MP3 |sed 's/,/ /g;s/!/ /g;s/#/ /g; s/_/ /g; ')"
_ARTISTZ="${_MP3Z%%-*}"
_SONGZ="${_MP3Z##*-}"
# remove leading and trailing spaces
_SONGZ="${_SONGZ#"${_SONGZ%%[![:space:]]*}"}"
_SONGZ="${_SONGZ%"${_SONGZ##*[![:space:]]}"}"
_ARTISTZ="${_ARTISTZ%"${_ARTISTZ##*[![:space:]]}"}"
# MP3 Tag
_MYECHO -s "tags:"
eyeD3 "$_MP3"
echo
# Tag edition
read -n 1 -p "Edit ID3 tag? [Yes/No/All] : "
case $REPLY in
n|N) echo ;;
a|A) echo
_MYECHO -s "Artist:"
read -e -i "$_MP3Z" _ARTIST
_MYECHO -s "Song:"
read -e -i "$_MP3Z" _SONG
eyeD3 -a "$_ARTIST" -t "$_SONG" "$_MP3"
;;
*) echo
_MYECHO -s "Artist:"
read -e -i "$_ARTISTZ" _ARTIST
_MYECHO -s "Song:"
read -e -i "$_SONGZ" _SONG
eyeD3 -a "$_ARTIST" -t "$_SONG" "$_MP3"
;;
esac
# File rename
read -n 1 -p "Rename? [Yes/No/All] : "
case $REPLY in
n|N) echo && exit 0 ;;
a|A) echo
_MYECHO -s "MP3 Name:"
read -e -i "$_MP3Z" _MP3NAME
mv "$_MP3" "$(dirname $_MP3)/${_MP3NAME}.mp3"
;;
*) echo
if [ -z "$_ARTIST" ]; then
_MYECHO -s "MP3 Name:"
read -e -i "$_MP3Z" _MP3NAME
mv "$_MP3" "$(dirname $_MP3)/${_MP3NAME}.mp3"
_MYECHO -c green -p "$(dirname $_MP3)/${_MP3NAME}.mp3"
else
mv "$_MP3" "$(dirname $_MP3)/${_ARTIST}-${_SONG}.mp3"
_MYECHO -c green -p "$(dirname $_MP3)/${_ARTIST}-${_SONG}.mp3"
fi
;;
esac