Skip to content

Commit 31bdcf2

Browse files
committed
Added a settings to change the separator between the song name and the artist
1 parent 7109601 commit 31bdcf2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

notify.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def setup_env_file():
4444
refresh_token = input("Please enter your Spotify refresh token: ")
4545
bot_refresh_rate = input("Please enter the bot refresh rate (in seconds): ")
4646
note_prefix = input("Please enter the desired prefix that will be displayed before the song name and artist")
47-
47+
separator = input("Please enter the separator between the song name and the artist")
4848
ig_username = input("Please enter your Instagram username: ")
4949
ig_password = input("Please enter your Instagram password: ")
5050

@@ -57,6 +57,7 @@ def setup_env_file():
5757
env_file.write(f"SPOTIPY_CLIENT_SECRET={client_secret}\n")
5858
env_file.write(f"SPOTIPY_REFRESH_TOKEN={refresh_token}\n")
5959
env_file.write(f"BOT_REFRESH_RATE={bot_refresh_rate}\n")
60+
env_file.write(f'SONG_SEPARATOR={separator}')
6061
env_file.write(f"IG_USERNAME={ig_username}\n")
6162
env_file.write(f"IG_PASSWORD={ig_password}\n")
6263
env_file.write(f"IG_NOTE_PREFIX={note_prefix}\n")
@@ -77,14 +78,16 @@ def setup_env_file():
7778
IG_CREDENTIAL_PATH = './ig_settings.json'
7879

7980
SLEEP_TIME = os.getenv("BOT_REFRESH_RATE") # in seconds
80-
81+
SONG_SEPARATOR = os.getenv("SONG_SEPARATOR")
8182
# Spotify credentials
8283
SPOTIFY_CLIENT_ID = os.getenv("SPOTIPY_CLIENT_ID")
8384
SPOTIFY_CLIENT_SECRET = os.getenv("SPOTIPY_CLIENT_SECRET")
8485
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIPY_REFRESH_TOKEN")
8586

8687
if not all([SPOTIFY_CLIENT_SECRET, SPOTIFY_CLIENT_ID, SPOTIFY_REFRESH_TOKEN]):
8788
raise Exception("Can't find Spotify credentials in the .env file")
89+
if not SONG_SEPARATOR:
90+
SONG_SEPARATOR = "-"
8891

8992
def get_access_token(client_id, client_secret, refresh_token):
9093
debug("Getting an access token from Spotify API ...")
@@ -132,13 +135,14 @@ def __init__(self):
132135
self._cl.dump_settings(IG_CREDENTIAL_PATH)
133136
debug('Instagram credentials has been saved !')
134137

135-
def send_music_note(self, song_name, artist):
138+
def send_music_note(self, song_name, artist,separator):
139+
136140
previous_note = None
137-
note_content = f"{IG_NOTE_PREFIX} {song_name} - {artist}" if IG_NOTE_PREFIX else f"🎧 {song_name} - {artist}"
141+
note_content = f"{IG_NOTE_PREFIX} {song_name} {separator} {artist}" if IG_NOTE_PREFIX else f"🎧 {song_name} {separator} {artist}"
138142
if note_content == previous_note and previous_note is not None:
139143
debug("The content of the note is the same as before, no need to send a new one")
140144
if len(note_content) < 60:
141-
self._cl.send_note(f"{IG_NOTE_PREFIX} : {song_name} - {artist}" if IG_NOTE_PREFIX else f"🎧 : {song_name} - {artist}", 0)
145+
self._cl.send_note(f"{IG_NOTE_PREFIX} : {song_name} {separator} {artist}" if IG_NOTE_PREFIX else f"🎧 : {song_name} {separator} {artist}", 0)
142146
previous_note = note_content
143147

144148
else:
@@ -153,7 +157,7 @@ def update(self, spotify):
153157
note_content = f"{song_name} - {artist}"
154158
debug(note_content)
155159
debug("Sending note to Instagram API.")
156-
bot.send_music_note(song_name, artist)
160+
bot.send_music_note(song_name, artist,SONG_SEPARATOR)
157161
debug(f'Note should be set on {IG_USERNAME} account.')
158162
else:
159163
debug("Nothing is playing currently.")

0 commit comments

Comments
 (0)