def execute(): try: write_title("lyrics") args = get_cli_args() if len(args.song_lyrics) > 0: fetch_and_render(" ".join(args.song_lyrics), True) elif args.watch: previous_song_name = None current_song_name = None while True: try: current_song_name = " - ".join(spotify.current()[::-1]) except Exception: previous_song_name = None current_song_name = None write_title("lyrics") clear_terminal() print_text("\nNothing is playing at the moment.\n") if current_song_name is not None and previous_song_name != current_song_name: previous_song_name = current_song_name write_title(f"lyrics | {current_song_name}") fetch_and_render(current_song_name, False) time.sleep(watch_timeout) else: song_name = " - ".join(spotify.current()[::-1]) fetch_and_render(song_name, False) except KeyboardInterrupt: pass except ValueError: print_text("\nNo song found with those lyrics\n") except Exception as exception: print_text(f"\n{exception}\n")
def main(): mute("false") muted = False old_song = "" while True: try: song_name_lower = spotify.current()[0].lower() song_name = spotify.current()[0] artist_name = spotify.current()[1] # Displays to the terminal the current song name and artist. if old_song != song_name: print("Now listening to: ", song_name, " - ", artist_name) old_song = song_name # Handles the mute process when there's an Ad. if 'advertisement' in song_name_lower or 'spotify' in song_name_lower: mute("true") muted = True # Handles the unmute when the ad finishes and spotify is muted. elif muted and ('advertisement' not in song_name_lower or 'spotify' not in song_name_lower): mute("false") muted = False time.sleep(1) # sleeps one second. #print(muted) except SpotifyPaused: if old_song != "": print("Spotify paused.") old_song = "" except SpotifyNotRunning or SpotifyClosed: if old_song != "": print("Spotify closed.") old_song = ""
def show_cli(make_issue=False): try: song, artist = spotify.current() # get currently playing song, artist print(lyrics(song, artist, make_issue)) print('\n(Press Ctrl+C to quit)') except SpotifyNotRunning as e: print(e) print('\n(Press Ctrl+C to quit)') song, artist = None, None while True: # refresh every 5s to check whether song changed # if changed, display the new lyrics try: try: if spotify.current() == (song, artist): raise SameSongPlaying else: song, artist = spotify.current() clear() print(lyrics(song, artist, make_issue)) print('\n(Press Ctrl+C to quit)') except (SpotifyNotRunning, SameSongPlaying): time.sleep(5) except KeyboardInterrupt: print('\nSure boss, exiting.') exit()
def get_track(): try: title, artist = spotify.current() except SpotifyNotRunning as e: return e else: return f"{artist} - {title}"
def main(): try: title, artist = spotify.current() except SpotifyNotRunning as e: print(e) else: print(f"{title} - {artist}")
def _refresh_metadata(self) -> None: """ Refreshes the API metadata: updates the artist and title of the song. The SwSpotify API works with exceptions so `SpotifyPaused` means the song isn't currently playing (the artist and title should remain the same), and `SpotifyClosed` means that there isn't a Spotify session open at that moment. """ try: self.title, self.artist = spotify.current() self.is_playing = True except SpotifyPaused: self.is_playing = False except SpotifyClosed: raise ConnectionNotReady("No song currently playing") from None # Splitting the artist and title for local songs if self.artist == '': self.artist, self.title = split_title(self.title) # Checking that the metadata is valid if "" in (self.artist, self.title): raise ConnectionNotReady( "No Spotify session currently running or no song currently" " playing.") from None
def get_spotify_mood(): try: title, artist = spotify.current() except SpotifyNotRunning as e: print(e) return " " else: return title + " from " + artist
def show_cli(make_issue=False): try: song, artist = spotify.current() # get currently playing song, artist return(lyrics(song, artist, make_issue)) print('\n(Press Ctrl+C to quit)') except SpotifyNotRunning as e: return(e) print('\n(Press Ctrl+C to quit)') song, artist = None, None
def song_changed(): # to refresh lyrics when song changed global song, artist try: if spotify.current() == (song, artist): raise SameSongPlaying else: return 'yes' except (SpotifyNotRunning, SameSongPlaying): return 'no'
def tab(): # format lyrics for the browser tab template global song, artist song, artist = spotify.current() current_lyrics = lyrics(song, artist) current_lyrics = current_lyrics.split('\n') # break lyrics line by line return render_template('lyrics.html', lyrics=current_lyrics, song=song, artist=artist)
def run(ic): global stop global currentSong restart = False try: currentSong = spotify.current() except: currentSong = ("", "") print(currentSong) try: while not stop: try: if spotify.current() != currentSong: currentSong = spotify.current() ic.stop() ic.update_menu() restart = True break except: if currentSong != ("", ""): currentSong = ("", "") ic.stop() ic.update_menu() restart = True break if currentSong[1] in skipListAR and ar_skip and autoskip: print("SKIP") s.skip() if currentSong[1] in skipListWR and wr_skip and autoskip: print("SKIP") s.skip() sleep(0.5) finally: ic.stop() if restart: sleep(0.1) Thread(target=main).start()
def artist_song(make_issue=False): try: song, artist = spotify.current() # get currently playing song, artist if(song == "Advertisement"): return("Advertisement") return("Song : "+ song +"<br> Artist : "+artist) print('\n(Press Ctrl+C to quit)') except SpotifyNotRunning as e: print(e) print('\n(Press Ctrl+C to quit)') song, artist = None, None
def tab(): # format lyrics for the browser tab template global song, artist try: song, artist = spotify.current() current_lyrics = lyrics(song, artist) except SpotifyNotRunning: current_lyrics = 'Nothing playing at the moment.' current_lyrics = current_lyrics.split('\n') # break lyrics line by line return render_template('lyrics.html', lyrics=current_lyrics, song=song, artist=artist)
def get_current_song(self): try: title, artist = spotify.current() log.info("Playing on Spotify: {artist} - {title}".format( artist=artist, title=title)) self.data = { "artist": artist, "song_title": title, "is_playing": 1 } except SpotifyPaused: self.data['is_playing'] = 0 log.info("Spotify is paused") except SpotifyClosed: log.warning( "Spotify is not running - open the Spotify app and start playing a song" ) return self.data
def run(self): while True: try: self.song, self.artist = spotify.current() if (self.song, self.artist) != (self.lyrics_song, self.lyrics_artist): self.lyrics = find_lyrics(self.song, self.artist) playing = { "song": self.song, "artist": self.artist, "lyrics": self.lyrics } self.lyrics_queue.put(playing) self.lyrics_song = self.song self.lyrics_artist = self.artist except spotify.SpotifyNotRunning: continue
def music(): try: currentSong = spotify.current() except SpotifyNotRunning: logger.info("Spotify not playing") return payload = { "type": "info", "firstRow": "Spotify", "secondRow": "Teraz jest grane" } sock.sendto(json.dumps(payload).encode(), ("192.168.8.122", 2137)) sleep(1) payload = { "type": "spotify", "firstRow": currentSong[0], "secondRow": currentSong[1] } sock.sendto(json.dumps(payload).encode(), ("192.168.8.122", 2137)) logger.info("Sent spotify info") logger.debug("Data: " + str(payload))
def main(): while True: gt = gTagger(None) input() try: title, artist = spotify.current() _, lyrics = gt._gTagger__get_genius_data(f'{title} {artist}', None) response = { "ok": True, "title": title, "artist": artist, "lyrics": lyrics } except SpotifyClosed as e: response = {"ok": False, "status": "Closed"} except SpotifyPaused as e: response = {"ok": False, "status": "Paused"} except SpotifyNotRunning as e: response = {"ok": False, "status": "Not Running"} print(json.dumps(response)) sys.stdout.flush()
def getInfoFromSpotify(): infos = spotify.current() return infos
import serial import time from SwSpotify import spotify from pynput.keyboard import Key, Controller ser = serial.Serial('COM3', 9600) keyboard = Controller() while True: try: title, artist = spotify.current() ser.write(title.encode()) ser.write('^'.encode()) ser.write(artist.encode()) except: ser.write("music paused".encode()) time.sleep(0.410) if ser.inWaiting(): action = ser.readline() if action == b'>>|\r\n': keyboard.press(Key.media_next) elif action == b'|<<\r\n': keyboard.press(Key.media_previous) elif action == b'+\r\n': keyboard.press(Key.media_volume_up) elif action == b'-\r\n': keyboard.press(Key.media_volume_down) elif action == b'>|\r\n': keyboard.press(Key.media_play_pause) elif action == b'EQ\r\n': keyboard.press(Key.media_volume_mute)
def show_cli(make_issue: bool = False) -> None: try: song, artist = spotify.current() # get currently playing song, artist print(lyrics(song, artist, make_issue)) except SpotifyNotRunning as e: print(e)
warner_records = "https://en.wikipedia.org/wiki/List_of_current_Warner_Records_artists" response = requests.get(warner_records) soup = BeautifulSoup(response.text, "html.parser") wrList = soup.findAll("li") i = 0 for li in wrList: if i < 28: i = i + 1 continue if li.text == "List of former Warner Records artists": break art = "" art = li.text if " (" in art: art = art.split(" (")[0] if " as " in art: art = art.split(" as ")[1] skipListWR.append(art) print(skipListWR) print(skipListAR) try: currentSong = spotify.current() except: currentSong = ("", "") main()