hbashton / spotify-ripper

https://github.com/jrnewell/spotify-ripper has been revived
MIT License
494 stars 101 forks source link

Ripping playlists? #42

Open lavolp3 opened 5 years ago

lavolp3 commented 5 years ago

Playlists seem not able to be ripped. After logging in playlist is loaded and the program immediately stopped without giving an error.

Spotify Ripper - v2.9.1 Encoding output: MP3, VBR 0 Spotify bitrate: 320 kbps Unicode support: Yes Output directory: /media/downloads/spotify Settings directory: /root/.spotify-ripper Format String: {album_artist}/({year}) {album}/{track_num:2} - {track_name}.{ext} Overwrite files: No Logging in... Logged in as 1153815924 Loading playlist... Loading playlist... Logging out...

I think I have seen problems with playlists over at mopidy. Might it be related?

hedwiggggg commented 5 years ago

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

lavolp3 commented 5 years ago

@hedwiggggg thanks for the workaround.

jposemescouilles commented 5 years ago

i'm trying to find the root cause of this error. Does anyone have a clue ?

lavolp3 commented 5 years ago

I'm trying as well. There is no error in the script so the loaded playlist seems to be empty. In my system i get the" Loading playlist..." message twice then the script exits without an error. Over at the mopidy repository they are working on the issue as well and already have a workaround. Don't know if it can anyhow be implemented here...

Granville Paut notifications@github.com schrieb am Fr., 19. Okt. 2018, 05:57:

i'm trying to find the root cause of this error. Does anyone have a clue ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hbashton/spotify-ripper/issues/42#issuecomment-431237432, or mute the thread https://github.com/notifications/unsubscribe-auth/ATJ17dE99tWFDEjZahqyfCsirEnKO_Z_ks5umU2agaJpZM4XZoUi .

DevMiKeCL commented 5 years ago

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 `

reardenlife commented 5 years ago

@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
reardenlife commented 5 years ago

@DevMiKeCL , your code also had a bug. It could not download playlists longer than 100 tracks. I fixed it in my code above.

pualien commented 5 years ago

if you prefer a pythonic script take a look at this simple gist

DevMiKeCL commented 5 years ago

@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 :)

seandex commented 5 years ago

@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

mmichon commented 5 years ago

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.

thomasmerz commented 2 years ago

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