feat: Implement downloading by artist url
This commit is contained in:
parent
fc8419c30f
commit
902391d032
64
funkblubber
64
funkblubber
|
@ -5,6 +5,43 @@ errecho()
|
||||||
echo -e "\e[0;31m${1}\e[0m" 1>&2
|
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
|
for dep in jq curl
|
||||||
do
|
do
|
||||||
if [ -z $(which $dep) ]
|
if [ -z $(which $dep) ]
|
||||||
|
@ -22,7 +59,7 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
domain=$(echo "$1" | cut -f 3 -d '/')
|
domain=$(echo "$1" | cut -f 3 -d '/')
|
||||||
echo "So your domain is $domain..."
|
echo "Parsing $domain"
|
||||||
|
|
||||||
album_flag="albums"
|
album_flag="albums"
|
||||||
artist_flag="artists"
|
artist_flag="artists"
|
||||||
|
@ -32,13 +69,13 @@ for chunk in "${chunks[@]}"
|
||||||
do
|
do
|
||||||
case $chunk in
|
case $chunk in
|
||||||
$album_flag)
|
$album_flag)
|
||||||
echo "Found out it's an album..."
|
echo "Parsing album"
|
||||||
look_for_id_of=$album_flag
|
look_for_id_of=$album_flag
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
|
||||||
$artist_flag)
|
$artist_flag)
|
||||||
echo -n "Found out it's an artist..."
|
echo -n "Parsing artist"
|
||||||
look_for_id_of=$artist_flag
|
look_for_id_of=$artist_flag
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
@ -46,27 +83,14 @@ do
|
||||||
|
|
||||||
case $look_for_id_of in
|
case $look_for_id_of in
|
||||||
$album_flag)
|
$album_flag)
|
||||||
echo "And its ID is ${chunk}..."
|
echo "Get ID ${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 .)
|
getalbum $chunk $domain
|
||||||
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
|
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
$artist_flag)
|
$artist_flag)
|
||||||
echo -n "And its ID is ${chunk}..."
|
echo "Get ID ${chunk}"
|
||||||
|
getartist $chunk $domain
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue