Jun-22-2021, 10:24 PM
First off I apologize if I use terminology wrong, I don't know python coding but got help from an expert, currently unavailable, who made me a few complex scripts using spotipy python library that uses spotify api, and a program called anybar that monitors current song status and displays as different colored dots in mac menu bar.
Which is necessary when dealing with thousands of songs and deep digging through spotifies catalog. Which is my main hobby.
Anyway, the relevant section in the monitoring script is if a song I marked as liked (I actually heard and disliked) the dot will be one color, or false (I haven't come across it or have and like it) the dot automatically switches to another color.
As I started using it heavily I realized I forgot the scenario of songs I heard AND liked AND are in a playlist already, so just skip them when digging as I would a bad song.
So I'd like to to add three more options (can you add that to a true/false choice in python easily?), that it's true, false, UNLESS it's in playlist 1, or 2, or 3, in that case it will be a different color, I'll choose the corresponding colors to those scenarios.
Maybe posting the scripts would better help explain what he did and how I need to add one part to another to make one big code.
I removed any creditials etc, but they're in the real scripts.
this is the add to playlist code.
the liked_colors section needs new conditions,
so that it's True: "question",
False: "exclamation", unless it's in SPOTIFY_PLAYLIST_ID = (and there will be three playlists, but I can fill the colors and playlist IDs myself
Which is necessary when dealing with thousands of songs and deep digging through spotifies catalog. Which is my main hobby.
Anyway, the relevant section in the monitoring script is if a song I marked as liked (I actually heard and disliked) the dot will be one color, or false (I haven't come across it or have and like it) the dot automatically switches to another color.
As I started using it heavily I realized I forgot the scenario of songs I heard AND liked AND are in a playlist already, so just skip them when digging as I would a bad song.
So I'd like to to add three more options (can you add that to a true/false choice in python easily?), that it's true, false, UNLESS it's in playlist 1, or 2, or 3, in that case it will be a different color, I'll choose the corresponding colors to those scenarios.
Maybe posting the scripts would better help explain what he did and how I need to add one part to another to make one big code.
I removed any creditials etc, but they're in the real scripts.
this is the add to playlist code.
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# START Custom Credentials
SPOTIPY_CLIENT_ID = ''
SPOTIPY_CLIENT_SECRET = ''
SPOTIFY_USERNAME = ''
# ID of the playlist where the track needs to be added
SPOTIFY_PLAYLIST_ID = ''
# The cache file absolute path
SPOTIFY_CACHE = ''
# END Custom Credentials
SPOTIPY_REDIRECT_URI = ''
scope = "user-library-read user-read-currently-playing user-read-playback-state playlist-modify-public playlist-modify-private"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope, client_id=SPOTIPY_CLIENT_ID,
username=SPOTIFY_USERNAME,
client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI, cache_path=SPOTIFY_CACHE))
current_track = sp.current_playback()
if current_track is None:
print('No track is beeing played right now')
else:
# Track info
track_id = current_track['item']['id']
print('Currently playing {track} ({track_id}'.format(
track=current_track['item']['name'], track_id=track_id))
try:
added = sp.user_playlist_add_tracks(
user=SPOTIFY_USERNAME, playlist_id=SPOTIFY_PLAYLIST_ID, tracks=[track_id])
except:
added = None
if added is None:
print('# Unable to add the track')
else:
print('# Track has been added successfully to your playlist')and this is the anybar monitoring part that needs the first script incorporated into it somehowthe liked_colors section needs new conditions,
so that it's True: "question",
False: "exclamation", unless it's in SPOTIFY_PLAYLIST_ID = (and there will be three playlists, but I can fill the colors and playlist IDs myself
from pprint import pprint
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from anybar import AnyBar
import threading
# START Custom Credentials
SPOTIPY_CLIENT_ID = ''
SPOTIPY_CLIENT_SECRET = ''
SPOTIFY_USERNAME = ''
# The cache file absolute path
SPOTIFY_CACHE = ''
# END Custom Credentials
SPOTIPY_REDIRECT_URI = ''
PATH_TO_BASH_SCRIPT = ''
INTERVAL_SECONDS = 1
playing_colors = {
True: "green",
False: "red",
}
liked_colors = {
True: "question",
False: "exclamation",
}
shuffle_colors = {
True: "purple",
False: "blue",
}
repeat_colors = {
"track": "green",
"context": "blue",
"off": "cyan",
}
scope = "user-library-read user-read-currently-playing user-read-playback-state playlist-modify-public playlist-modify-private"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope, client_id=SPOTIPY_CLIENT_ID,
username=SPOTIFY_USERNAME,
client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI, cache_path=SPOTIFY_CACHE))
playing_status = AnyBar(port=)
liked_status = AnyBar(port=)
shuffle_status = AnyBar(port=)
repeat_status = AnyBar(port=)
def thread():
global playing_status
global liked_status
global shuffle_status
global repeat_status
global playing_colors
global liked_colors
global shuffle_colors
global repeat_colors
track = sp.current_playback()
if track is None:
# Playing Mode
playing_status.change(playing_colors[False])
else:
if track.get('is_playing') is not None and not track['is_playing']:
playing_status.change(playing_colors[False])
else:
playing_status.change(playing_colors[True])
isLiked = sp.current_user_saved_tracks_contains(
tracks=[track['item']['id']])[0]
if isLiked:
# Liked Mode
liked_status.change(liked_colors[False])
else:
liked_status.change(liked_colors[True])
# Shuffle mode
shuffle_status.change(
shuffle_colors[track['shuffle_state']])
# Repeat mode
repeat_status.change(repeat_colors[track['repeat_state']])
threading.Timer(INTERVAL_SECONDS, thread).start()
thread()anyway, if it's a simple cut and paste kind of thing it would be greatly appreciated if someone could look it over and come up with the solution, if it's difficult I understand, no hard feelings, figured I'd try, and will try and get him when he's not so busy if he is nice enough to help me out again.
