feat: Implement downloading by artist url

master
NaiJi ✨ 1 year ago
parent fc8419c30f
commit 902391d032

@ -5,6 +5,43 @@ errecho()
echo -e "\e[0;31m${1}\e[0m" 1>&2
}
getalbum()
{
aldum_id=$1
domain=$2
response=$(curl -X GET "https://${domain}/api/v1/tracks/?album=${album_id}&ordering=creation_date&page=1&page_size=16&scope=all" -H "accept: application/json")
echo "${response}" | jq '.results' | jq -c '.[]' | while read song
do
echo "${song}" | jq '.uploads' | jq -c '.[]' | while read upload
do
extension=$(echo ${upload} | jq -r '.extension')
folder=$(echo ${song} | jq -r '.album.title' | sed 's#/#_#g')
mkdir -p "${folder}"
title=$(echo ${song} | jq -r '.title' | sed 's#/#_#g')
listen_url=$(echo ${song} | jq -r '.listen_url')
echo "https://${domain}${listen_url}"
echo " - '${title}'"
echo " - $extension"
curl -X GET "https://${domain}${listen_url}" -H "accept: */*" -o "${folder}/${title}.${extension}"
break
done
done
}
getartist()
{
artist_id=$1
domain=$2
response=$(curl -X GET "https://${domain}/api/v1/albums/?artist=${artist_id}&ordering=creation_date&page=1&page_size=16&scope=all" -H "accept: application/json")
echo "${response}" | jq '.results' | jq -c '.[]' | while read album
do
album_id=$(echo "${album}" | jq -r '.id')
album_title=$(echo "${album}" | jq -r '.title')
echo " - Album: ${album_title}"
getalbum $album_id $domain
done
}
for dep in jq curl
do
if [ -z $(which $dep) ]
@ -22,7 +59,7 @@ then
fi
domain=$(echo "$1" | cut -f 3 -d '/')
echo "So your domain is $domain..."
echo "Parsing $domain"
album_flag="albums"
artist_flag="artists"
@ -32,13 +69,13 @@ for chunk in "${chunks[@]}"
do
case $chunk in
$album_flag)
echo "Found out it's an album..."
echo "Parsing album"
look_for_id_of=$album_flag
continue
;;
$artist_flag)
echo -n "Found out it's an artist..."
echo -n "Parsing artist"
look_for_id_of=$artist_flag
continue
;;
@ -46,27 +83,14 @@ do
case $look_for_id_of in
$album_flag)
echo "And its ID is ${chunk}..."
response=$(curl -X GET "https://${domain}/api/v1/tracks/?album=${chunk}&ordering=creation_date&page=1&page_size=16&scope=all" -H "accept: application/json" | jq .)
echo "${response}" | jq '.results' | jq -c '.[]' | while read song
do
echo "${song}" | jq '.uploads' | jq -c '.[]' | while read upload
do
extension=$(echo ${upload} | jq -r '.extension')
folder=$(echo ${song} | jq -r '.album.title' | sed 's#/#_#g')
mkdir -p "${folder}"
title=$(echo ${song} | jq -r '.title' | sed 's#/#_#g')
listen_url=$(echo ${song} | jq -r '.listen_url')
echo "Downloading '${title}'..."
curl -X GET "https://${domain}${listen_url}" -H "accept: */*" -o "${folder}/${title}.${extension}"
break
done
done
echo "Get ID ${chunk}"
getalbum $chunk $domain
exit 0
;;
$artist_flag)
echo -n "And its ID is ${chunk}..."
echo "Get ID ${chunk}"
getartist $chunk $domain
exit 0
;;
esac

Loading…
Cancel
Save