Skip to content

Instantly share code, notes, and snippets.

@aadibajpai
Last active August 2, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadibajpai/edc5672be48c0e671dc0dcfe44487d94 to your computer and use it in GitHub Desktop.
Save aadibajpai/edc5672be48c0e671dc0dcfe44487d94 to your computer and use it in GitHub Desktop.
import argparse
from swaglyrics.cli import lyrics, clear
from swaglyrics.tab import app
from swaglyrics import spotify
import time
def main():
parser = argparse.ArgumentParser(
description="Get lyrics for 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.')
args = parser.parse_args()
if args.tab:
app.run()
elif args.cli:
song = spotify.song() # get currently playing song
artist = spotify.artist() # get currently playing artist
print(lyrics(song, artist))
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))
print('\n(Press Ctrl+C to quit)')
except KeyboardInterrupt:
exit()
else:
parser.print_help()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment