blob: 4a9297cdbacfb2ce840af66cf87c1cd216f50385 (
plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
#!/bin/sh
#{{{ printhelp
printhelp () {
printf "amg: Auto Music Grabber; script to download, format, and tag music.\n"
printf " -h) prints this help message.\n"
printf " -u X) uses X for the URL to download from.\n"
printf " -s) processes the url as a single track as a single song.\n"
printf " -l) processes the url as a single track as an album.\n"
printf " -p) processes the yrk as a playlist as an album.\n"
printf " -a X) sets the artist name to X.\n"
printf " -A X) sets the album name to X.\n"
printf " -t X) sets the track name to X (only for a single song).\n"
printf " -T X) sets the track number to X (only for a single song).\n"
printf " -y X) sets the date to X.\n"
exit
}
#}}}
#{{{ getopts
unset ALBUM ARTIST MODE TITLE TRACKNUM YEAR
while getopts "hslpu:a:A:t:T:y:" arg; do case "${arg}" in
s) MODE='single' ;;
l) MODE='split' ;;
p) MODE='album' ;;
u) URL="$OPTARG" ;;
a) ARTIST="$OPTARG" ;;
A) ALBUM="$OPTARG" ;;
t) TITLE="$OPTARG" ;;
T) TRACKNUM="$OPTARG" ;;
y) YEAR="$OPTARG" ;;
*) printhelp ;;
esac done
#}}}
#{{{ print given args
printf "Received Tags:
Artist: $ARTIST
Album: $ALBUM
Song: $TITLE
Number: $TRACKNUM
Year: $YEAR\n\n"
#}}}
#{{{ fill in missing variables
# prompt to determine later tagging
if [ -z "$MODE" ]; then
printf "Will the link be for a [p]laylist, a[l]bum video, or [s]ong video? "
read RESPONSE
case "$RESPONSE" in
p) MODE='album' ;;
l) MODE='split' ;;
s) MODE='single' ;;
*) printhelp ;;
esac
printf "\n"
fi
# prompt to get the URL
if [ -z "$URL" ]; then
printf "Enter the link: "
read URL
printf "\n"
fi
#}}}
#{{{ base logic for certain modes
# if song, don't download playlist
case "$MODE" in
s)
SPLITTER_FLAGS="--no-playlist"
;;
l)
SPLITTER_FLAGS="--no-playlist"
unset TITLE TRACKNUM
;;
p)
unset TITLE TRACKNUM
;;
esac
#}}}
#{{{ download the video(s)
printf "Starting download...\n\n"
if [ "$(ls | wc -l)" -gt 0 ]; then
printf "Already downloaded\n"
else
yt-dlp $SPLITTER_FLAGS --format bestaudio --restrict-filenames "$URL"
fi
printf "Download stopped.\n\n"
#}}}
#{{{ while loop to remove files from list
printf "\n\nDo you want to remove any tracks?\n\n"
while true; do
ls | nl
echo -n "Enter the line number of the file to remove:\n"
read WHILE_RESPONSE
[ -z "$WHILE_RESPONSE" ] && break
rm -rf `ls | head -n "$WHILE_RESPONSE" | tail -1`
done
#}}}
#{{{ convert the downloaded files to mp3
printf "\n\nStarting to convert files..."
for i in `ls *.m4a *.webm`; do
imp3=`echo "$i" | sed 's/\.m4a$/.mp3/;s/\.webm$/.mp3/'`
[ ! -f "$imp3" ] && ffmpeg -i "$i" -acodec mp3 "$imp3" || echo "File not converted"
done
printf "Finished converting files.\n\n"
#}}}
#{{{ tag files
printf "\n\n"
for file in `ls *.mp3`; do
printf "$file\n"
if [ -z "$ARTIST" ]; then
printf "\nWho is the artist? "
read ARTIST
fi
if [ -z "$ALBUM" ]; then
printf "\nWhat is the album? "
read ALBUM
fi
if [ -z "$TITLE" ]; then
printf "\nWhat is the title? "
read TITLE
fi
if [ -z "$TRACKNUM" ]; then
printf "\nWhat is the track number? "
read TRACKNUM_
TRACKNUM="$(printf "%02d" "$TRACKNUM_")"
unset TRACKNUM_
fi
if [ -z "$YEAR" ]; then
printf "\nWhat is the release date? "
read YEAR
fi
case "$TRACKNUM" in
[!0-9]*)
unset TRACKNUM
printf "\n$TRACKNUM doesn't look like a track number!\n" 1>&2
;;
esac
FMT_ARTIST="$(echo "$ARTIST" | sed "s/[^[:alnum:].-]/_/g")"
FMT_ALBUM="$(echo "$ALBUM" | sed "s/[^[:alnum:].-]/_/g")"
FMT_TITLE="$(echo "$TITLE" | sed "s/[^[:alnum:].-]/_/g")"
[ -n "$ARTIST" ] && kid3-cli -c "set \"Artist\" \"$ARTIST\"" "$file"
[ -n "$ALBUM" ] && kid3-cli -c "set \"Album\" \"$ALBUM\"" "$file"
[ -n "$TITLE" ] && kid3-cli -c "set \"Title\" \"$TITLE\"" "$file"
[ -n "$TRACKNUM" ] && kid3-cli -c "set \"Track Number\" \"$TRACKNUM\"" "$file"
[ -n "$YEAR" ] && kid3-cli -c "set \"Date\" \"$YEAR\"" "$file"
printf "\n\n$file\n"
kid3-cli -c get "$file"
NEWFILENAME="${FMT_ARTIST}_-_${FMT_ALBUM}_-_${TRACKNUM:-00}_${FMT_TITLE}.mp3"
#NEWFILENAME="$(printf "%s" "$NEWFILENAME" | sed 's/ /_/g;s/[!@#$%^&*()-_=+{}\|;:,.<>/?`~'"\[\]\'\""']//g')"
[ -n "${ARTIST}" -a -n "${ALBUM}" -a -n "${TITLE}" ] && mv "$file" "$NEWFILENAME"
unset TITLE TRACKNUM
printf "$NEWFILENAME\n\n\n"
done
printf "\n\nDone.\n"
#}}}
|