Last active
August 2, 2018 15:28
-
-
Save aadibajpai/edc5672be48c0e671dc0dcfe44487d94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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