Skip to content

Commit

Permalink
update to autoSpotify v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Grem6 committed Feb 20, 2023
1 parent 65ecc76 commit 9d2b0c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source Code/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*refer read-me for more info*
- Version: 1.0
- Version: 1.1
- Gecko-version: 0.32.2
- Browser-client: firefox⭐
- Developer: **Grem**
Expand Down
34 changes: 31 additions & 3 deletions Source Code/spotipy_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,48 @@ def auto_spotify():
current_user = sp.current_user()
user_id = current_user['id']
print('\n')
print('Hi', current_user['display_name'])
print('Hi ' + current_user['display_name'] + '!')
print('\n')

playlist_exists = os.path.exists('playlists_auto.conf')
local_playlist_exists = os.path.exists('my_playlist.txt')


if playlist_exists:

#if playlist created by autospotify already exists locally;
#if playlist created by autospotify/user already exists locally;

config.read(r'playlists_auto.conf')

playlist_id = config['playlist']['id']
playlist_name = config['playlist']['name']
print(f'playlist : {playlist_name} found! ')

print('\x1b[0;32;40m' + 'Checking for locally saved songs..' + '\x1b[0m')

if local_playlist_exists:
print('\x1b[0;32;40m' + 'local saves found!' + '\x1b[0m')
print('\x1b[0;32;40m' + 'Adding songs...' + '\x1b[0m')
with open('local_playlist.txt') as f:
while True:
line = f.readline()
if not line:
break
song = line.strip()

output = sp.search(song, limit=1, offset=0,
type='track', market=None)
for track in output['tracks']['items']:
tracks = [track['uri']]

sp.user_playlist_remove_all_occurrences_of_tracks(
user_id, playlist_id, tracks)
sp.user_playlist_add_tracks(
user_id, playlist_id, tracks, position=None)
print('\x1b[0;32;40m' + 'All tracks added!' + '\x1b[0m')
print('\x1b[0;32;40m' + '**removed duplicate entries**' + '\x1b[0m')

pass

#user choice to add to locally found playlist
# if yes, run this;
print(f"\n{YELLOW}Do you want to add to this existing playlist? | (yes/no): ",end='')
Expand Down Expand Up @@ -159,3 +186,4 @@ def auto_spotify():
print('\x1b[0;32;40m' + 'All tracks added!' + '\x1b[0m')
print('\x1b[0;32;40m' + '**removed duplicate entries**' + '\x1b[0m')


0 comments on commit 9d2b0c9

Please sign in to comment.