Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
retrohacking committed Oct 8, 2023
1 parent 2214884 commit 9e11329
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If the inserted tokens are correct the program will print automatically all the
The program will print a prospect of the many playlists that can be created on the user's account. But it is not necessary to create __ALL__ the generated playlists. You will have to insert the indexes of the playlists you actually want to generate.

### Playlists index parser
The generated playlists can be so much, but the program provides you a parser to easily include intervals instead of manually inserting all their indexes. Here it is:
The generated playlists can be so many, but the program provides you a parser to easily include intervals instead of manually inserting all their indexes. Here it is:

- All the playlists or intervals have to be separated by a comma (,)
- The user can insert a single index for a playlist
Expand All @@ -30,3 +30,10 @@ The generated playlists can be so much, but the program provides you a parser to

__And Gensort also sorts the playlists by the number of their songs!__ <sub>(guess you wouldn't like to listen to a playlist with only 2 songs, right? :wink:)</sub>

---
Now Gensort will work by itself, generating the chosen playlists!

Check them on your Spotify account and if you like them Star this project and feel free to open an issue or a pull request for any problem or enhancement!

\-Retro

7 changes: 4 additions & 3 deletions gensort.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from utils.authorization_manager import have_tokens,configure_tokens, read_tokens, generate_user_token, get_client_manager
from utils.gensort_functionalities import get_spotify, get_playlists, choose_playlist, pre_sort, playlist_sorting, prompt_for_playlists
from utils.window_manager import print_banner, print_playlists_name, print_sorted_playlists, print_parser_rules, print_chosen_playlists
from utils.gensort_functionalities import get_spotify, get_playlists, choose_playlist, pre_sort, playlist_sorting, prompt_for_playlists, gensort_playlists
from utils.window_manager import print_banner, print_playlists_name, print_sorted_playlists, print_parser_rules, print_chosen_playlists, print_final

def retrieve_tokens():
if not have_tokens():
Expand Down Expand Up @@ -29,4 +29,5 @@ def run_gensort(client, token):
print_parser_rules()
chosen_playlists=prompt_for_playlists(len(sorted_playlists.keys()))
print_chosen_playlists(chosen_playlists, sorted_playlists)
#create the playlists -> gensort_functionalities and get the IDs
gensort_playlists(chosen_playlists, sorted_playlists, playlists, spotify)
print_final()
4 changes: 3 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
GITHUB="https://github.com/retrohacking"

LIMIT_PLAYLIST_TRACK=100
DEFAULT_GENRES=["rock", "metal", "funk", "punk", "trap", "hip hop", "rap", "pop", "r&b", "reggae", "soul"]
DEFAULT_GENRES=["rock", "metal", "funk", "punk", "trap", "hip hop", "rap", "pop", "r&b", "reggae", "soul"]
PLAYLISTS_PREFIX="GENSORT_"
PLAYLISTS_DESCRIPTION="A playlist automatically generated by Gensort :D"
22 changes: 20 additions & 2 deletions utils/gensort_functionalities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import *
from utils.input_manager import int_input, playlist_choice_parser
from utils.file_manager import load_json
from utils.input_manager import int_input, playlist_choice_parser, check_yesno

def get_spotify(user_token, client_manager):
return spotipy.Spotify(auth=user_token)
Expand Down Expand Up @@ -69,4 +70,21 @@ def playlist_sorting(tracks):
return new_playlists

def prompt_for_playlists(max_value):
return playlist_choice_parser(max_value)
return playlist_choice_parser(max_value)

def gensort_playlists(chosen, playlists, user_playlists, spotify):
confirm=check_yesno(input("Confirm? (Y/N)\t"))
current_user = spotify.current_user()
username = current_user['uri'].split(":")[2]
if not confirm:
exit("SEE YOU NEXT TIME!\n")
for i in chosen:
sorted_playlists_name=list(playlists.keys())[i]
final_playlist_name=f"{PLAYLISTS_PREFIX}{sorted_playlists_name}"
if final_playlist_name in list(user_playlists.keys()):
final_playlist_id=user_playlists[final_playlist_name]
spotify.playlist_add_items(final_playlist_id, playlists[sorted_playlists_name])
else:
new_playlist_id=spotify.user_playlist_create(username, final_playlist_name, public=False, collaborative=False, description=PLAYLISTS_DESCRIPTION)["id"]
spotify.playlist_add_items(new_playlist_id, playlists[sorted_playlists_name])
print(f"{len(playlists[sorted_playlists_name])} songs have been added to {final_playlist_name}")
7 changes: 6 additions & 1 deletion utils/window_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ def print_chosen_playlists(chosen, playlists):
playlists_name=list(playlists.keys())
print("\nYou have chosen the following playlists:")
for p in chosen:
print(playlists_name[p])
print(playlists_name[p])

def print_final():
print("\nCheck the playlists on your Spotify, and if you like them Star the project, or open a issue for any problem!")
print(f"GITHUB - {GITHUB}/spotify_gensort")
print("\n\tSEE YOU SOON!")

0 comments on commit 9e11329

Please sign in to comment.