Added some important features and update few things
This commit is contained in:
parent
972ca07d6e
commit
06e2d2df77
2 changed files with 132 additions and 53 deletions
182
src/tidler
182
src/tidler
|
@ -35,6 +35,19 @@ else
|
||||||
cover_resolution="1280" # Default value
|
cover_resolution="1280" # Default value
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$MAX_ATTEMPTS" ]; then
|
||||||
|
if [ "$MAX_ATTEMPTS" -ge 1 -a "$MAX_ATTEMPTS" -le 100 ]; then
|
||||||
|
max_attempts="$MAX_ATTEMPTS"
|
||||||
|
else
|
||||||
|
echo "Bad MAX_ATTEMPTS option. Allowed are numbers from 1 to 100."
|
||||||
|
echo "Using default value..."
|
||||||
|
|
||||||
|
max_attempts=10 # Default value
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
max_attempts=10 # Default value
|
||||||
|
fi
|
||||||
|
|
||||||
downloadTrack() {
|
downloadTrack() {
|
||||||
if [ "$#" -ge 1 ]; then
|
if [ "$#" -ge 1 ]; then
|
||||||
echo "Downloading track with ID: $1"
|
echo "Downloading track with ID: $1"
|
||||||
|
@ -50,25 +63,53 @@ downloadTrack() {
|
||||||
album_dir=""
|
album_dir=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
json_data=$(curl -s "$proxy_url/track/?id=$id&quality=$quality")
|
attempt_num=1
|
||||||
|
success=false
|
||||||
|
|
||||||
if [ "$?" -gt 0 ]; then
|
while [ $attempt_num -le $max_attempts ]; do
|
||||||
echo "Error"
|
json_data=$(curl -# "$proxy_url/track/?id=$id&quality=$quality")
|
||||||
exit 1
|
|
||||||
|
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 -s "$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
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$success" = false ]; then
|
||||||
|
echo "Attempt $attempt_num failed. Retrying..."
|
||||||
|
((attempt_num++))
|
||||||
|
sleep 1 # TODO: random sleep time
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$success" = false ]; then
|
||||||
|
echo "Failed to download after $max_attempts attempts."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
track_name=$(echo "$json_data" | jq -r '.[0].title')
|
|
||||||
|
|
||||||
artist_name=$(echo "$json_data" | jq -r '.[0].artist.name')
|
|
||||||
album_name=$(echo "$json_data" | jq -r '.[0].album.title')
|
|
||||||
url=$(echo "$json_data" | jq -r '.[-1].OriginalTrackUrl')
|
|
||||||
cover_data=$(curl -s "$proxy_url/cover/?id=$id")
|
|
||||||
cover_url=$(echo "$cover_data" | jq -r '.[]["1280"]')
|
|
||||||
|
|
||||||
track_number=$(echo "$json_data" | jq -r '.[0].trackNumber')
|
|
||||||
filename="$track_name.flac"
|
|
||||||
cover_name="cover.png"
|
|
||||||
|
|
||||||
if [ -n "$DOWNLOADS_DIR" ]; then
|
if [ -n "$DOWNLOADS_DIR" ]; then
|
||||||
download_dir="$DOWNLOADS_DIR"
|
download_dir="$DOWNLOADS_DIR"
|
||||||
else
|
else
|
||||||
|
@ -76,9 +117,9 @@ downloadTrack() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$album_dir" ]; then
|
if [ -z "$album_dir" ]; then
|
||||||
final_path="$download_dir"
|
final_path="$download_dir"
|
||||||
else
|
else
|
||||||
final_path="$download_dir/$album_dir"
|
final_path="$download_dir/$album_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$final_path"
|
mkdir -p "$final_path"
|
||||||
|
@ -96,7 +137,6 @@ downloadTrack() {
|
||||||
"$final_path/$filename"
|
"$final_path/$filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
searchTrack() {
|
searchTrack() {
|
||||||
if [ "$#" -ge 1 ]; then
|
if [ "$#" -ge 1 ]; then
|
||||||
track_name="$1"
|
track_name="$1"
|
||||||
|
@ -105,7 +145,7 @@ searchTrack() {
|
||||||
read -r track_name
|
read -r track_name
|
||||||
fi
|
fi
|
||||||
track_name=$(echo "$track_name" | sed 's/ /%20/g')
|
track_name=$(echo "$track_name" | sed 's/ /%20/g')
|
||||||
tracks=$(curl -s "$proxy_url/search/?s=$track_name" | jq -r '.items[] | "\(.id) - \(.title) by \(.artist.name)"')
|
tracks=$(curl -# "$proxy_url/search/?s=$track_name" | jq -r '.items[] | "\(.id) - \(.title) by \(.artist.name)"')
|
||||||
|
|
||||||
tracks_list=()
|
tracks_list=()
|
||||||
while IFS= read -r list; do
|
while IFS= read -r list; do
|
||||||
|
@ -138,60 +178,96 @@ downloadAlbum() {
|
||||||
else
|
else
|
||||||
base_dir="$(pwd)"
|
base_dir="$(pwd)"
|
||||||
fi
|
fi
|
||||||
json_data=$(curl -s "$proxy_url/album/?id=$id&quality=$quality")
|
|
||||||
album_name=$(echo "$json_data" | jq -r '.[0].title')
|
|
||||||
artist_name=$(echo "$json_data" | jq -r '.[0].artist.name')
|
|
||||||
album_title="$artist_name - $album_name"
|
|
||||||
album_dir="$album_title"
|
|
||||||
album_tracks_ids=$(curl -s "$proxy_url/album/?id=$id&quality=$quality" | jq -r '.[1].items[] | .item.id')
|
|
||||||
tracks_ids_list=()
|
|
||||||
while IFS= read -r list; do
|
|
||||||
tracks_ids_list+=("$list")
|
|
||||||
done <<< "$album_tracks_ids"
|
|
||||||
|
|
||||||
for track_id in "${tracks_ids_list[@]}"
|
attempt_num=1
|
||||||
do
|
success=false
|
||||||
downloadTrack "$track_id" "$album_dir"
|
|
||||||
|
while [ $attempt_num -le $max_attempts ]; do
|
||||||
|
json_data=$(curl -# "$proxy_url/album/?id=$id&quality=$quality")
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
album_name=$(echo "$json_data" | jq -r '.[0].title')
|
||||||
|
artist_name=$(echo "$json_data" | jq -r '.[0].artist.name')
|
||||||
|
album_title="$artist_name - $album_name"
|
||||||
|
album_dir="$album_title"
|
||||||
|
album_tracks_ids=$(echo "$json_data" | jq -r '.[1].items[] | .item.id')
|
||||||
|
tracks_ids_list=()
|
||||||
|
while IFS= read -r list; do
|
||||||
|
tracks_ids_list+=("$list")
|
||||||
|
done <<< "$album_tracks_ids"
|
||||||
|
|
||||||
|
for track_id in "${tracks_ids_list[@]}"; do
|
||||||
|
downloadTrack "$track_id" "$album_dir"
|
||||||
|
done
|
||||||
|
success=true
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Attempt $attempt_num failed. Retrying..."
|
||||||
|
((attempt_num++))
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$success" = false ]; then
|
||||||
|
echo "Failed to download album after $max_attempts attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
searchAlbum() {
|
searchAlbum() {
|
||||||
if [ "$#" -ge 1 ]; then
|
if [ "$#" -ge 1 ]; then
|
||||||
album_name="$1"
|
album_name="$1"
|
||||||
else
|
else
|
||||||
echo "Enter album name:"
|
echo "Enter album name:"
|
||||||
read -r album_name
|
read -r album_name
|
||||||
fi
|
fi
|
||||||
|
|
||||||
album_name=$(echo "$album_name" | sed 's/ /%20/g')
|
album_name=$(echo "$album_name" | sed 's/ /%20/g')
|
||||||
albums=$(curl -s "$proxy_url/search/?al=$album_name" | jq -r '.albums.items[] | "\(.id): \(.title)"')
|
attempt_num=1
|
||||||
|
success=false
|
||||||
|
|
||||||
albums_list=()
|
while [ $attempt_num -le $max_attempts ]; do
|
||||||
while IFS= read -r list; do
|
albums=$(curl -# "$proxy_url/search/?al=$album_name" | jq -r '.albums.items[] | "\(.id): \(.title)"')
|
||||||
albums_list+=("$list")
|
|
||||||
done <<< "$albums"
|
|
||||||
|
|
||||||
if [ "${#albums_list[@]}" -eq 1 ]; then
|
albums_list=()
|
||||||
echo "No albums found :("
|
while IFS= read -r list; do
|
||||||
exit 1
|
albums_list+=("$list")
|
||||||
fi
|
done <<< "$albums"
|
||||||
|
|
||||||
PS3="Please select an album: "
|
if [ "${#albums_list[@]}" -eq 0 ]; then
|
||||||
select t in "${albums_list[@]}"; do
|
echo "No albums found. Retrying... (Attempt $attempt_num/$max_attempts)"
|
||||||
if [ -n "$t" ]; then
|
((attempt_num++))
|
||||||
album_id=$(echo "$t" | awk -F ': ' '{print $1}')
|
sleep 1
|
||||||
echo "You selected: $t"
|
|
||||||
downloadAlbum "$album_id"
|
|
||||||
break
|
|
||||||
else
|
else
|
||||||
echo "Invalid selection. Please try again."
|
PS3="Please select an album: "
|
||||||
|
select t in "${albums_list[@]}"; do
|
||||||
|
if [ -n "$t" ]; then
|
||||||
|
album_id=$(echo "$t" | awk -F ': ' '{print $1}')
|
||||||
|
echo "You selected: $t"
|
||||||
|
downloadAlbum "$album_id"
|
||||||
|
success=true
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Invalid selection. Please try again."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$success" = true ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$success" = false ]; then
|
||||||
|
echo "Failed to find and download album after $max_attempts attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "Welcome to TiDLer!" && echo ""
|
echo "Welcome to TiDLer!" && echo ""
|
||||||
|
|
||||||
if [ "$1" = "search" ]; then
|
if [ "$1" = "search" ]; then
|
||||||
|
|
|
@ -10,3 +10,6 @@ QUALITY="LOSSLESS"
|
||||||
|
|
||||||
# Set cover art resolution -> "1280" = 1280x1280, "640" = 640x640, "80" = 80x80
|
# Set cover art resolution -> "1280" = 1280x1280, "640" = 640x640, "80" = 80x80
|
||||||
COVER_RESOLUTION="1280"
|
COVER_RESOLUTION="1280"
|
||||||
|
|
||||||
|
# If there is any problem with the API, Tidler will attempt to download the track again -> possible values are "1" to "100"
|
||||||
|
MAX_ATTEMPTS="10"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue