commit b071f74a7f63a33173b1e8ab0d375f2e783f8185 Author: poka Date: Sat May 7 02:47:04 2022 +0200 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d61611 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib/* +.login.auth diff --git a/.login.auth.template b/.login.auth.template new file mode 100644 index 0000000..5106656 --- /dev/null +++ b/.login.auth.template @@ -0,0 +1,3 @@ +sp_id="" +sp_password="" +sp_token="" diff --git a/.spotify_appkey.key b/.spotify_appkey.key new file mode 100755 index 0000000..4688806 Binary files /dev/null and b/.spotify_appkey.key differ diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..b217114 --- /dev/null +++ b/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [[ ! $(which python) ]]; then + if [[ ! $(which pyenv) ]]; then + echo "pyenv installation..." + curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash + echo "Restat terminal and relaunch this install script" + exit 0 + fi + + pyenv install 3.9.6 + pyenv global 3.9.6 +fi + +sudo apt install lame build-essential libffi-dev +wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add - #add mopidy's libspotify repository +sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/stretch.list #valid for Debian Stretch. +sudo apt update && sudo apt install libspotify12 libspotify-dev python-spotify #install libspotify from mopidy's repository +mkdir -p lib +cp .login.auth.template .login.auth +chmod 600 .login.auth + +git clone https://github.com/lavolp3/spotify-ripper.git lib/spotify-ripper && cd lib/spotify-ripper && python setup.py install +pyenv rehash diff --git a/spotify-dl.sh b/spotify-dl.sh new file mode 100755 index 0000000..550b99b --- /dev/null +++ b/spotify-dl.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +output="/mnt/e/Musique" +format="{artist} - {track_name}.{ext}" + +[[ ! $1 ]] && echo "Please give a search" && exit 1 +source .login.auth + +track=$(echo "$@" | sed 's/ /%20/g ') + +if [[ $(echo "$track" | grep "open.spotify.com") ]]; then + link="$track" + [[ $(echo "$link" | grep "open.spotify.com/album") ]] && format="{artist} - {album}/{track_name}.{ext}" +else + link=$(curl -sX "GET" "https://api.spotify.com/v1/search?q=$track&type=track" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $sp_token" | jq -r '.[].items[0].external_urls.spotify') +fi + +SPOTIPY_CLIENT_ID="" SPOTIPY_CLIENT_SECRET="" SPOTIPY_REDIRECT_URI="" python lib/spotify_ripper/main.py -k .spotify_appkey.key -u "$sp_id" -p "$sp_password" $link -f "$output/$format"