-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f0b246
commit 0727f29
Showing
8 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
.venv | ||
.venv | ||
tokens.json | ||
activate.bat | ||
.cache* | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from utils.authorization_manager import have_tokens,configure_tokens, read_tokens, generate_user_token | ||
|
||
def check_tokens(): | ||
if not have_tokens(): | ||
configure_tokens() | ||
|
||
def authorization(): | ||
username, client_id, client_secret = read_tokens() | ||
return generate_user_token(username, client_id, client_secret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from gensort import check_tokens, authorization | ||
|
||
def main(): | ||
check_tokens() | ||
token=authorization() | ||
|
||
|
||
if __name__=="__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
certifi==2023.7.22 | ||
charset-normalizer==3.2.0 | ||
idna==3.4 | ||
redis==5.0.1 | ||
requests==2.31.0 | ||
six==1.16.0 | ||
spotipy==2.23.0 | ||
urllib3==2.0.5 | ||
webencodings==0.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import spotipy | ||
REDIRECT="http://localhost/" | ||
SCOPE="playlist-modify-private playlist-modify-public" | ||
TOKENS_FILE="tokens.json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from . import * | ||
from utils.file_manager import create_json, check_json, load_json | ||
from os import system | ||
from webbrowser import open | ||
|
||
|
||
LOGIN_PAGE="https://accounts.spotify.com/it/login" | ||
CREATE_APP_PAGE="https://developer.spotify.com/dashboard/create" | ||
|
||
def have_tokens(): | ||
return check_json(TOKENS_FILE) | ||
|
||
def configure_tokens(): | ||
tokens={} | ||
own_credentials=input("Do you already own the CLIENT ID and the CLIENT SECRET? (Y/N) ") | ||
if not own_credentials: | ||
print("This process will guide you through the configuration of your tokens.") | ||
system("pause") | ||
print("First of all register or login on Spotify\n"+ | ||
"If the program does not automatically redirect you to the page, navigate to:\n"+ | ||
LOGIN_PAGE) | ||
open(LOGIN_PAGE, new=0) | ||
system("pause") | ||
print() | ||
print("Now, fill the form:\n"+ | ||
"\tApp name: Genres Sorter\n"+ | ||
"\tApp description: Sort out your messy playlists!\n"+ | ||
"\tWebsite: https://github.com/retrohacking/spotify_gensort \n"+ | ||
"\tRedirect URIs: http://localhost/\n"+ | ||
"If the program does not automatically redirect you to the page, navigate to:\n"+ | ||
CREATE_APP_PAGE) | ||
open(CREATE_APP_PAGE, new=0) | ||
system("pause") | ||
print() | ||
print("We're almost done:\n"+ | ||
"Select the app that you have just created -> Settings\n") | ||
|
||
tokens["client_id"]=input("Insert here the Client ID: ") | ||
tokens["client_secret"]=input("Insert here the Client Secret: ") | ||
tokens["username"]=input("Insert your Spotify username (find it at https://www.spotify.com/us/account/profile/): ") | ||
create_json(TOKENS_FILE, tokens) | ||
|
||
def read_tokens(): | ||
client_tokens=load_json(TOKENS_FILE) | ||
return client_tokens["username"], client_tokens["client_id"], client_tokens["client_secret"] | ||
|
||
def generate_user_token(uname, c_id, c_secret): | ||
return spotipy.util.prompt_for_user_token(username=uname, scope=SCOPE, client_id=c_id, client_secret=c_secret, redirect_uri=REDIRECT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from json import dumps, load | ||
from os.path import isfile | ||
|
||
def check_json(file): | ||
if isfile(file): | ||
return True | ||
else: | ||
return False | ||
|
||
def create_json(filename, data): | ||
if not ".json" in filename: | ||
filename+=".json" | ||
jsondata=dumps(data, indent=4) | ||
file=open(filename, "w") | ||
file.write(jsondata) | ||
file.close() | ||
|
||
def load_json(file): | ||
f=open(file, "r") | ||
jsonfile=load(f) | ||
f.close() | ||
return jsonfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def check_yesno(answer): | ||
if answer.lowercase()=="y": | ||
return True | ||
else: | ||
return False |