Comments (12)
@DevMiKeCL
I will simplify a little bit
$ cat spotify-get-tracks.sh
#!/usr/bin/env bash
set -e
set -o errexit
CID=${2}
CS=${3}
auth=$(echo -n "$CID:$CS" | base64 -w 0)
t=$(curl -X "POST" -H "Authorization: Basic $auth" -d grant_type=client_credentials https://accounts.spotify.com/api/token)
token=$(echo "$t" | jq -r '.access_token')
playlisturl="${1}"
user=$(echo $playlisturl | cut -d "/" -f5)
uri=$(echo $playlisturl | cut -d "/" -f7 | cut -d "?" -f1)
t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri?fields=name" -H "Authorization: Bearer $token")
playlist=$(echo "$t" | jq -r '.name')
offset=0
while (( $offset < 42000 )); do
t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri/tracks?fields=items(track(uri))&offset=$offset" -H "Authorization: Bearer $token" )
tracks=$(echo "$t" | jq -r '.items[] | .track | .uri' )
echo "$tracks"
if [ -z "$tracks" ]; then
break
fi
offset=$[$offset + 100]
done
from spotify-ripper.
I've got the same problem. A possible workaround is, to select all the songs from the playlist and just hit Share -> Copy Spotify URIs
Edit: And obviously put them in a .txt file and give the spotify-ripper the path to the file
from spotify-ripper.
Aquí tengo una solución para cargar playlist
i have a little solution :)
Filename: getpl.sh
command ./getpl.sh
` ClientID=""
ClientSecret=""
#Generar el codigo de autorizacion base64 ClientID:ClientSecret
basic=$(echo -n $ClientID:$ClientSecret | base64)
basic=$(sed 's/ //g' <<< $basic)
#Capturar Token
token=$(curl -X "POST" -H "Authorization: Basic $basic" -d grant_type=client_credentials https://accounts.spotify.com/api/token)
token=$(sed 's/{"access_token":"//g' <<< $token)
token=$(sed 's/","token_type":"Bearer","expires_in":3600,"scope":""}//g' <<< $token)
#Capturar Usuario y URI de playlist
#ex spotify:user:mikers2016:playlist:2jsFLqiTfNpMDfWgq8v9Zv
echo -e "Ingrese la direccion URI de la playlist\n"
read playlist
user=$(echo $playlist | cut -d ":" -f3)
uri=$(echo $playlist | cut -d ":" -f5)
#echo "https://api.spotify.com/v1/users/"$user"/playlists/"$uri"/tracks?fields=items(track(uri))"
#echo "https://api.spotify.com/v1/users/$user/playlists/"$uri"/tracks?fields=items(track(uri))" -H "Authorization: Bearer "$token #>> lista.txt
echo "Capturando nombre de playlist"
nombreplaylist=$(GET "https://api.spotify.com/v1/users/$user/playlists/$uri?fields=name" -H "Authorization: Bearer $token")
#echo $nombreplaylist
nombreplaylist=$(sed 's/{ "name" : "//g' <<< $nombreplaylist)
nombreplaylist=$(sed 's/" }//g' <<< $nombreplaylist)
nombreplaylist=$(sed 's/ /./g' <<< $nombreplaylist)
echo -e "nombre de playlist:\n"
echo $nombreplaylist
if [ ! -d "V.A.-$nombreplaylist" ]; then
echo -e "Creando directorio, accediendo"
mkdir "V.A.-$nombreplaylist"
cd "V.A.-$nombreplaylist"
else
echo "Directorio existente, accediendo..."
cd "V.A.-$nombreplaylist"
fi
#Captura de tracks en un archivo de texto
GET "https://api.spotify.com/v1/users/$user/playlists/$uri/tracks?fields=items(track(uri))" -H "Authorization: Bearer $token" >> lista.txt
#echo -e "Generando Lista\n"
if [ -f "$nombreplaylist.txt" ]; then
echo -e "Lista existente, sobreescribiendo Lista\n"
rm $nombreplaylist.txt
else
echo -e "Generando Lista\n"
fi
grep spotify lista.txt >> $nombreplaylist.txt
rm lista.txt
find -name $nombreplaylist.txt -exec sed -i 's/ "uri" : "//g' {} ;
find -name $nombreplaylist.txt -exec sed -i 's/"//g' {} ;
echo -e "Iniciando Rippeo\n"
spotify-ripper $nombreplaylist.txt `
from spotify-ripper.
@hedwiggggg thanks for the workaround.
from spotify-ripper.
i'm trying to find the root cause of this error. Does anyone have a clue ?
from spotify-ripper.
from spotify-ripper.
@DevMiKeCL , your code also had a bug. It could not download playlists longer than 100 tracks.
I fixed it in my code above.
from spotify-ripper.
if you prefer a pythonic script take a look at this simple gist
from spotify-ripper.
@DevMiKeCL , your code also had a bug. It could not download playlists longer than 100 tracks.
I fixed it in my code above.
great, thanks! i will try your code :)
from spotify-ripper.
@DevMiKeCL
I will simplify a little bit$ cat spotify-get-tracks.sh #!/usr/bin/env bash set -e set -o errexit CID=${2} CS=${3} auth=$(echo -n "$CID:$CS" | base64 -w 0) t=$(curl -X "POST" -H "Authorization: Basic $auth" -d grant_type=client_credentials https://accounts.spotify.com/api/token) token=$(echo "$t" | jq -r '.access_token') playlisturl="${1}" user=$(echo $playlisturl | cut -d "/" -f5) uri=$(echo $playlisturl | cut -d "/" -f7 | cut -d "?" -f1) t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri?fields=name" -H "Authorization: Bearer $token") playlist=$(echo "$t" | jq -r '.name') offset=0 while (( $offset < 42000 )); do t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri/tracks?fields=items(track(uri))&offset=$offset" -H "Authorization: Bearer $token" ) tracks=$(echo "$t" | jq -r '.items[] | .track | .uri' ) echo "$tracks" if [ -z "$tracks" ]; then break fi offset=$[$offset + 100] done
damn nice
from spotify-ripper.
I couldn't get the spotify-get-tracks.sh
variants to work (for instance, base64
doesn't have a -w
argument on MacOS), but here's a quick shell script to download from a file of track URIs:
#!/bin/sh
trap 'exit' INT
while read track; do
echo "Ripping $track to $2"
spotify-ripper -d $2 $track
done < $1
Open your playlist(s), select all the tracks in them, right click, Share->Copy Spotify URIs, then paste into a file. Do spotify-get-tracks.sh ~/tracks ~/music/new-playlist
to download all the tracks in ~/tracks
to ~/music/new-playlist
. No argument checking, so be careful.
from spotify-ripper.
I use this for getting the token:
# ---
# generate Spotify oauth token with given client id and secret:
client_id=$(jq -r '.id' ~/.config/spotify_client_creds.json 2>/dev/null)
client_secret=$(jq -r '.secret' ~/.config/spotify_client_creds.json 2>/dev/null)
[ "$client_id" == "" ] || [ "$client_secret" == "" ] && { sed -rn 's/^### ?//;T;p' "$0"; exit 1; }
encoded_creds="$(echo -n "$client_id:$client_secret" | base64 -w 0)"
token=$(curl -s "https://accounts.spotify.com/api/token" -d "grant_type=client_credentials" -H "Authorization: Basic $encoded_creds" | jq -r .access_token)
# ---
With a JSON file ~/.config/spotify_client_creds.json
like this:
{
"id": "xxx",
"secret": "yyy"
}
Then checking for (mandatory) parameters:
# ---
# check for mandatory parameter:
[ -z "$2" ] && { \
echo "Usage: $(basename $0) user playlisturl"
echo "Example: $(basename $0) spotify https://open.spotify.com/playlist/37i9dQZF1DWXqv38T3vrCH"
echo -e "\nThis can be used like this:"
echo -e "for tracks in \$(./spotify-get-tracks.sh spotify https://open.spotify.com/playlist/37i9dQZF1DWXqv38T3vrCH); do\n uri=\$tracks\n docker exec spotify-ripper1 spotify-ripper \$uri\ndone\n"
exit 1
}
playlisturl="${2}"
user="${1}"
# ---
And finally getting everything working (after some shellshecks have been done):
# ---
uri=$(echo "$playlisturl" | cut -d "/" -f5)
t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri?fields=name" -H "Authorization: Bearer $token" 2>/dev/null)
#playlist=$(echo "$t" | jq -r '.name') ### SC2034: playlist appears unused. Verify use (or export if used externally).
offset=0
#while (( $offset < 42000 )); do ### SC2004: $/${} is unnecessary on arithmetic variables.
while (( offset < 42000 )); do
t=$(curl "https://api.spotify.com/v1/users/$user/playlists/$uri/tracks?fields=items(track(uri))&offset=$offset" -H "Authorization: Bearer $token" 2>/dev/null)
tracks=$(echo "$t" | jq -r '.items[] | .track | .uri' )
if [ -z "$tracks" ]; then
break
fi
echo "$tracks"
#offset=$[$offset + 100] ### SC2007: Use $((..)) instead of deprecated $[..]
offset=$((offset + 100))
done
# ---
ℹ️
https://github.com/koalaman/shellcheck/wiki/SC2004
https://github.com/koalaman/shellcheck/wiki/SC2007
https://github.com/koalaman/shellcheck/wiki/SC2034
from spotify-ripper.
Related Issues (20)
- hangs when loading large list of URIs HOT 1
- [ISSUE REMOVED]
- Coverart not working any more, but http still does
- Does anyone have working cover-art version? HOT 31
- Segmentation error (core dumped)
- Tags return to default after rip is complete
- Where to get the app key? HOT 28
- Avoid LastFM Scrobbling
- Help to install spotify-ripper HOT 4
- Error during login HOT 1
- Problem installing from setup.py HOT 1
- Raspberry Pi 3 : Problem with appkey HOT 1
- downloading playlists HOT 4
- Fix cover and missing featurings
- Rip complete - WARNING: argument missing for 'b'
- Add support for pyspotify v2.1.3
- Problem with naming in Python 3.9 HOT 1
- 'spotify.utils' has no attribute 'IntEnum' HOT 1
- Mark project as archive & add explanation for why it won't work anymore HOT 1
- after I login spotify when ripping it says i need a premium account HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spotify-ripper.