Added lyrics downloading

This commit is contained in:
Medvidek77 2025-04-20 11:24:27 +02:00
parent 9973ccc5df
commit 4a60838f93

View file

@ -2,7 +2,7 @@
. tidler.conf # Load ENVs from config file
version="0.3.0"
version="0.3.1"
if [ -n "$PROXY_URL" ]; then
@ -50,6 +50,7 @@ else
max_attempts="10" # Default value
fi
downloadTrack() {
if [ "$#" -ge 1 ]; then
echo "Downloading track with ID: $1"
@ -59,14 +60,10 @@ downloadTrack() {
read -r id
fi
if [ "$#" -ge 2 ]; then
album_dir="$2"
else
album_dir=""
fi
attempt_num=1
success=false
lrc_success=false
while [ $attempt_num -le $max_attempts ]; do
json_data=$(curl -# "$proxy_url/track/?id=$id&quality=$quality")
@ -87,11 +84,32 @@ downloadTrack() {
cover_data=$(curl -# "$proxy_url/cover/?id=$id")
cover_url=$(echo "$cover_data" | jq -r '.[]["1280"] // empty')
if [ -n "$cover_url" ]; then
date_data=$(echo "$json_data" | jq -r '.[0].streamStartDate // empty' )
date=$(expr substr "$date_data" 1 10)
year=$(expr substr "$date_data" 1 4)
if [ -n "$year" ]; then
track_number=$(echo "$json_data" | jq -r '.[0].trackNumber')
filename="$track_name.flac"
cover_name="cover.png"
cover_name="tidler_temp_cover_$track_name.png"
success=true
lyrics_data=$(curl -# "$proxy_url/lyrics/?id=$id")
if [ $? -eq 0 ]; then
timed_lyrics=$(echo "$lyrics_data" | jq -r '.[0].subtitles')
if [ -n "$timed_lyrics" ]; then
lrc_success=true
elif [ "$timed_lyrics" == "null" ]; then
echo "Lyrics not found"
fi
fi
fi
break
fi
fi
@ -100,6 +118,7 @@ downloadTrack() {
fi
fi
if [ "$success" = false ]; then
echo "Attempt $attempt_num failed. Retrying..."
((attempt_num++))
@ -107,38 +126,43 @@ downloadTrack() {
fi
done
if [ "$success" = false ]; then
echo "Failed to download after $max_attempts attempts."
exit 1
fi
if [ -n "$DOWNLOADS_DIR" ]; then
download_dir="$DOWNLOADS_DIR"
else
download_dir="$(pwd)"
fi
if [ -z "$album_dir" ]; then
final_path="$download_dir"
else
final_path="$download_dir/$album_dir"
fi
final_path="$download_dir/$artist_name/$album_name"
mkdir -p "$final_path"
curl -# "$url" -o "$final_path/$filename"
curl -# "$cover_url" -o "$final_path/$cover_name"
curl -# "$cover_url" -o "/tmp/$cover_name"
# Metadata
metaflac \
--set-tag="NAME=$track_name" \
--set-tag="ARTIST=$artist_name" \
--set-tag="ALBUM=$album_name" \
--set-tag="TRACKNUMBER=$track_number" \
--import-picture-from="$final_path/$cover_name" \
${lrc_success:+--set-tag="LYRICS=$timed_lyrics"} \
--set-tag="DATE=$date" \
--set-tag="YEAR=$year" \
--import-picture-from="/tmp/$cover_name" \
"$final_path/$filename"
rm "/tmp/$cover_name"
}
searchTrack() {
if [ "$#" -ge 1 ]; then
track_name="$1"
@ -268,6 +292,13 @@ searchAlbum() {
fi
}
#searchArtist() {
#}
#downloadArtist() {
#}
if [ "$1" = "search" ]; then
if [ "$#" -ge 2 ]; then
@ -277,12 +308,14 @@ if [ "$1" = "search" ]; then
else
searchTrack
fi
elif [ "$1" = "download" ]; then
if [ "$#" -ge 2 ]; then
downloadTrack "$2"
else
downloadTrack
fi
elif [ "$1" = "album" ]; then
if [ "$#" -ge 2 ]; then
shift
@ -291,6 +324,7 @@ elif [ "$1" = "album" ]; then
else
searchAlbum
fi
elif [ "$1" == "version" ]; then
echo "TiDLer $version by Medvidek77"
@ -318,7 +352,9 @@ else
echo "2. Search single track with text"
echo ""
echo "3. Search and download whole album with text"
read option
if [ "$option" -eq 1 ]; then
downloadTrack
elif [ "$option" -eq 2 ]; then
@ -327,3 +363,4 @@ else
searchAlbum
fi
fi