def main(): # print(r""" # ____ _ _ # / ___|_ ____ _ __ _| | _ _ _ __(_) ___ ___ # \___ \ \ /\ / / _` |/ _` | | | | | | '__| |/ __/ __| # ___) \ V V / (_| | (_| | |__| |_| | | | | (__\__ \ # |____/ \_/\_/ \__,_|\__, |_____\__, |_| |_|\___|___/ # |___/ |___/ # """) # print('\n') parser = argparse.ArgumentParser( description="Get lyrics for the currently playing song on Spotify. Either --tab or --cli is required.") parser.add_argument('-t', '--tab', action='store_true', help='Display lyrics in a browser tab.') parser.add_argument('-c', '--cli', action='store_true', help='Display lyrics in the command-line.') parser.add_argument('-n', '--no-issue', action='store_false', help='Disable issue-making on cli.') args = parser.parse_args() unsupported_precheck() if args.tab: print('Firing up a browser tab!') app.template_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app.static_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static') port = 5042 # random url = "http://127.0.0.1:{port}".format(port=port) threading.Timer(1.25, lambda: webbrowser.open(url)).start() app.run(port=port) elif args.cli: make_issue = args.no_issue song = spotify.song() # get currently playing song artist = spotify.artist() # get currently playing artist print(lyrics(song, artist, make_issue)) print('\n(Press Ctrl+C to quit)') while True: # refresh every 5s to check whether song changed # if changed, display the new lyrics try: if song == spotify.song() and artist == spotify.artist(): time.sleep(5) else: song = spotify.song() artist = spotify.artist() if song and artist is not None: clear() print(lyrics(song, artist, make_issue)) print('\n(Press Ctrl+C to quit)') except KeyboardInterrupt: exit() if os.environ.get("TESTING", "False") != "False": break else: parser.print_help()
def test_that_artist_function_calls_get_info(self, mock, mock_sys, mock_no_native_spotify): """ test that artist function calls get_info_web when native is not running. This works by mocking the get_info_linux which is called since we mock the platform as linux. NOTE that this would work on any platform I just mocked the platform to save mocking every get_info function with the SpotifyNotRunning error. This should cause the 'current' function to now run get_info_web due to the exception thrown. """ mock_sys.platform = "Linux" artist() self.assertTrue(mock.called)
def run(self): global last_song, last_artist, curr_artist, curr_song, got_error try: while True: curr_song = sp.song() curr_artist = sp.artist() if last_song != curr_song: self.changed_data.emit(True) elif last_song == curr_song and last_artist != curr_artist: self.changed_data.emit(True) data = curr_song + ";data;" + curr_artist self.info_data.emit(data) last_song = curr_song last_artist = curr_artist sleep(0.5) except sp.SpotifyNotRunning as e: if not got_error: self.error_data.emit("<NOERR>" + curr_lyrics + "<NOERR>") got_error = True if curr_lyrics == info_msg: print("(DEBUG) " + str(e)) self.error_data.emit(error_msg) sleep(0.5) self.run()
def __init__(self, parent): global last_song, last_artist QWidget.__init__(self) self.Parent = parent self.searchLyricsBtn = QPushButton("Search for lyrics!", self) self.searchLyricsBtn.setGeometry(QRect(510, 570, 280, 71)) self.searchLyricsBtn.setEnabled(True) self.currentArtistText = QLabel("Current artist: -", self) self.currentArtistText.setGeometry(QRect(10, 10, 770, 30)) self.currentArtistText.setScaledContents(False) self.currentSongText = QLabel("Current song: -", self) self.currentSongText.setGeometry(QRect(10, 25, 770, 60)) self.currentSongText.setScaledContents(False) self.currentSongText.setWordWrap(True) self.searchedSongInfo = QLabel("Searched song: -", self) self.searchedSongInfo.setGeometry(QRect(10, 110, 770, 60)) self.searchedSongInfo.setScaledContents(False) self.searchedSongInfo.setWordWrap(True) self.auto_search_checkbox = QCheckBox('Auto search lyrics?', self) self.auto_search_checkbox.setGeometry(QRect(515, 515, 770, 60)) self.textBrowser = QTextBrowser(self) self.textBrowser.setGeometry(QRect(10, 160, 490, 480)) self.verLbl = QLabel("Version: 4.1", self) self.verLbl.setGeometry(QRect(725, 0, 100, 15)) self.searchLyricsBtn.clicked.connect(self.search_lyrics) self.auto_search_checkbox.toggled.connect(self.auto_search_lyrics) self.searchLyricsBtn.setStyleSheet("font: 25pt") self.currentSongText.setStyleSheet("font: 15pt") self.currentArtistText.setStyleSheet("font: 15pt") self.searchedSongInfo.setStyleSheet("font: 15pt") self.auto_search_checkbox.setStyleSheet("font: 14pt") self.textBrowser.setStyleSheet("font: 13pt") self.verLbl.setStyleSheet("font: 10pt") self.textBrowser.setText(info_msg) if auto_search == 'False': self.searchLyricsBtn.setEnabled(True) self.auto_search_checkbox.setChecked(False) else: self.searchLyricsBtn.setEnabled(False) self.auto_search_checkbox.setChecked(True) last_song = sp.song() last_artist = sp.artist() self.info_updater()
def tab(): # format lyrics for the browser tab template global song, artist song = spotify.song() artist = spotify.artist() 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 NowPlaying(): prev = "" input1 = input( "Write the message! (ex: Now playing {Artist} | {Music} -> Now Playing Darude | Sandstorm)" ) input1 = input1.replace("{Artist}", "{0}") input1 = input1.replace("{Music}", "{1}") file = open("NowPlaying.txt", "w") while True: if str(spotify.artist()) == "None": song = "Not Playing" else: song = input1.format(spotify.artist(), spotify.song()) if song != prev: file = open("NowPlaying.txt", "w") prev = song print(song) file.write(song) file.close() time.sleep(5)
print(str(i) + ":") print(" - Name: %s" % voice.name) i = i + 1 quit() if (args.set != None): voices = engine.getProperty('voices') if (args.set > len(voices) - 1): print("Input voice out of range. Please input a number from 0 to " + str(len(voices) - 1)) quit() engine.setProperty('voice', voices[args.set].id) engine.setProperty('rate', args.rate) while True: try: song = spotify.song() artist = spotify.artist() if (not (song == None or artist == None) and (song != prevsong or artist != prevartist)): if (args.delay != 0): time.sleep(args.delay) engine.say("Playing " + song + " by " + artist) engine.runAndWait() print("Playing " + song + " by " + artist) prevsong = song prevartist = artist except spotify.SpotifyNotRunning as e: pass time.sleep(1)
def test_that_artist_function_calls_get_info(self, mock): """ test that test artist function calls get_info_windows function """ x = artist() self.assertTrue(mock.called)
def test_that_artist_function_returns_None_when_error(self, mock): """ test that test artist function returns None when the get_info_windows function will return an error """ x = artist() self.assertEqual(x, None)
previous = None i = 0 root = None while i < 100000: # gets the current song being played current = spotify.song() while current is not None and previous != current: print('previous song: ', previous) print('current song: ', current) previous = current currentSongTitle = spotify.song() # gets the current artist currentArtist = spotify.artist() # gets the current lyrics of the song currentLyrics = lyrics(currentSongTitle, currentArtist) root = tk.Tk() root.title("Spotify Lyrics") root.configure(width=10, height=5) txt = tk.Text(root) txt.configure(font=("Century Gothic", 12), wrap='word') scrollbar = tk.Scrollbar(root, orient="vertical") scrollbar.config(command=txt.yview) scrollbar.pack(side="right", fill="y") txt.insert(tk.END, currentSongTitle + "\n")
def spotify_get_artist(): return spotify.artist()
import serial import time from SwSpotify import spotify ser = serial.Serial('COM3', 9600) # serial port pause = ("No connection...") # string displayed when pause error = ("ERROR") # string displayed when other error occur while True: # loop try: song = (spotify.song() + " - " + spotify.artist()) # code to try except spotify.SpotifyNotRunning: # block of code executed when spotify is paused or closed ser.write(pause.encode()) # sends pause to serial port time.sleep(1) except: # block of code executed when other error occur ser.write(error.encode()) # sends error to serial port time.sleep(1) else: # block of code executed if no errors ser.write(song.encode()) # sends song to serial port time.sleep(1)
def getSong(): song = spotify.song() artist = spotify.artist() bio = "I am currently listening to: \n" + song + " \n" + artist + "\nhttps://github.com/tpby2005/spotify-to-twitter" return bio