diff --git a/README.md b/README.md index 39e85ce..ab9a180 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ *Tidal music downloader based on the hifi-tui API* -### https://github.com/sachinsenal0x64/Hifi-Tui +### Based on [hifi-tui](https://github.com/sachinsenal0x64/Hifi-Tui) ## Requirements - `bash`, `curl`, `jq`, `awk`, `flac` @@ -11,7 +11,7 @@ - Create install scripts/guides (WIP) - Migrate from Bash to a POSIX-compliant shell - Add Cover, and other metadata to vorbis tag (Almost done) -- Lyrics download (WIP) +- Lyrics download (Almost done) - Implement search & download for playlists, albums, and artists (WIP) - Support downloading multiple search results - Allow users to choose audio quality (currently defaults to LOSSLESS) @@ -30,11 +30,6 @@ git clone https://git.medvidek77.tech/Medvidek77/tidler.git && cd tidler git checkout dev ``` -- Add permissions as root: -``` -chmod +x src/tidler -``` - - Run: ``` src/tidler diff --git a/scripts/ArchLinux/PKGBUILD b/scripts/ArchLinux/PKGBUILD index a5d0a4e..d3eb27a 100644 --- a/scripts/ArchLinux/PKGBUILD +++ b/scripts/ArchLinux/PKGBUILD @@ -1,8 +1,8 @@ # Maintainer: Medvidek77 pkgname=tidler -pkgver=0.3.0 -pkgrel=3 +pkgver=0.3.1 +pkgrel=1 pkgdesc="Tidal music downloader based on the hifi-tui API" arch=('any') url="https://git.medvidek77.tech/Medvidek77/tidler" diff --git a/scripts/ArchLinux/PKGBUILD-git b/scripts/ArchLinux/PKGBUILD-git index 611a132..a5a92c2 100644 --- a/scripts/ArchLinux/PKGBUILD-git +++ b/scripts/ArchLinux/PKGBUILD-git @@ -1,8 +1,8 @@ # Maintainer: Medvidek77 pkgname=tidler -pkgver=0.3.0 -pkgrel=3 +pkgver=0.3.1 +pkgrel=1 pkgdesc="Tidal music downloader based on the hifi-tui API" arch=('any') url="https://git.medvidek77.tech/Medvidek77/tidler" diff --git a/src/tidler b/src/tidler index e015973..b9cfc51 100755 --- a/src/tidler +++ b/src/tidler @@ -1,8 +1,8 @@ -#!/bin/bash +#!/usr/bin/env bash . tidler.conf # Load ENVs from config file -version="0.3.0" +version="0.3.2" 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,52 @@ downloadTrack() { fi fi + if [ "$success" = false ]; then echo "Attempt $attempt_num failed. Retrying..." ((attempt_num++)) - sleep "1.$(tr -cd 0-9 possible values are "1" to "100" -MAX_ATTEMPTS="10" +MAX_ATTEMPTS="15"