From 4a60838f93f5d4478a3c3c6e2972e158a556f03a Mon Sep 17 00:00:00 2001 From: Medvidek77 Date: Sun, 20 Apr 2025 11:24:27 +0200 Subject: [PATCH] Added lyrics downloading --- src/tidler | 93 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/src/tidler b/src/tidler index e015973..57a198f 100755 --- a/src/tidler +++ b/src/tidler @@ -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,39 +60,56 @@ 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") - + if [ $? -eq 0 ]; then track_name=$(echo "$json_data" | jq -r '.[0].title // empty') - + if [ -n "$track_name" ]; then artist_name=$(echo "$json_data" | jq -r '.[0].artist.name // empty') - + if [ -n "$artist_name" ]; then album_name=$(echo "$json_data" | jq -r '.[0].album.title // empty') - + if [ -n "$album_name" ]; then url=$(echo "$json_data" | jq -r '.[-1].OriginalTrackUrl // empty') - + if [ -n "$url" ]; then cover_data=$(curl -# "$proxy_url/cover/?id=$id") cover_url=$(echo "$cover_data" | jq -r '.[]["1280"] // empty') - - if [ -n "$cover_url" ]; then - track_number=$(echo "$json_data" | jq -r '.[0].trackNumber') - filename="$track_name.flac" - cover_name="cover.png" - success=true + + + 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="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,45 +118,51 @@ downloadTrack() { fi fi + if [ "$success" = false ]; then echo "Attempt $attempt_num failed. Retrying..." ((attempt_num++)) - sleep "1.$(tr -cd 0-9