From a003eedf5810a53a0a72687f37bb2eae73baee58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ktu=C4=9F=20Karaka=C5=9Fl=C4=B1?= <20567087+goktug97@users.noreply.github.com> Date: Sat, 21 Dec 2019 11:28:11 +0300 Subject: [PATCH] add new keybindings and some refactoring --- README.md | 28 ++++++++------- setup.py | 4 +-- spotify_lyrics.py | 86 ++++++++++++++++++++++++++--------------------- utils.py | 31 ++++++++--------- 4 files changed, 81 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 06b791f..2d46de9 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Yet Another Spotify Command Line Lyrics ![Lyrics-Screenshot](https://raw.githubusercontent.com/goktug97/yet-another-spotify-lyrics/master/screenshot.jpg) ## Requirements +* Linux +* Python >= 3.6 * ueberzug * dbus-python * requests @@ -33,18 +35,20 @@ spotify-lyrics ### Keybindings -| Action | Keybinding | -|:-------------:|:------------:| -| Scroll Up | k | -| Scroll Down | j | -| Edit Lyrics | e | -| Refresh | r | -| Toggle | t | -| Next | n | -| Prev | p | -| Update Lyrics | d | -| Help | h | -| Quit Program | q | +| Action | Keybinding | +|:-------------------:|:-------------:| +| Scroll Up | k | +| Scroll Down | j | +| Beginning of Lyrics | gg | +| End of Lyrics | G | +| Edit Lyrics | e | +| Refresh | r | +| Toggle | t | +| Next | n | +| Prev | p | +| Update Lyrics | d | +| Help | h | +| Quit Program | q | - Edit Lyrics: Open lyrics in `$EDITOR`. - Refresh: Refresh lyrics and song metadata. diff --git a/setup.py b/setup.py index 4976cec..691a38f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ long_description = f.read() setup(name='yet-another-spotify-lyrics', - version='2.2.3', + version='2.3.0', description='Command Line Spotify Lyrics with Album Cover', author='Göktuğ Karakaşlı', author_email='karakasligk@gmail.com', @@ -17,7 +17,7 @@ long_description_content_type='text/markdown', url='https://github.com/goktug97/yet-another-spotify-lyrics', download_url=( - 'https://github.com/goktug97/yet-another-spotify-lyrics/archive/v2.2.3.tar.gz'), + 'https://github.com/goktug97/yet-another-spotify-lyrics/archive/v2.3.0.tar.gz'), py_modules=[os.path.splitext(os.path.basename(path))[0] for path in ['spotify_lyrics', 'utils', diff --git a/spotify_lyrics.py b/spotify_lyrics.py index 3043f77..5ab289d 100755 --- a/spotify_lyrics.py +++ b/spotify_lyrics.py @@ -118,7 +118,8 @@ def main(self, canvas): if difference > 0: self.current_line -= difference self.current_line = max(0, self.current_line) - self.current_line = min(self.current_line, len(wrapped_lines)-1) + self.current_line = min(self.current_line, + len(wrapped_lines)-n_entries) album_cover.x = self.columns//2 self.print_metadata() @@ -138,47 +139,54 @@ def main(self, canvas): utils.delete_line() key = key_poller.poll() - if key == 'q': - os.system('clear') - break - elif key == 'j': - if rows - start_row == n_entries: + if key is not None: + if key == 'q': + os.system('clear') + break + elif key == 'j' or ord(key) == 5: self.current_line += 1 - self.current_line = min(self.current_line, len(wrapped_lines)-1) - elif key == 'k': - self.current_line += -1 - self.current_line = max(self.current_line, 0) - elif key == 'e': - try: - EDITOR = os.environ.get('EDITOR') - call([EDITOR, self.lyrics_file]) - self.update_lyrics() + self.current_line = min(self.current_line, + len(wrapped_lines)-n_entries) + elif key == 'k' or ord(key) == 25: + self.current_line += -1 + self.current_line = max(self.current_line, 0) + elif key == 'e': + try: + EDITOR = os.environ.get('EDITOR') + call([EDITOR, self.lyrics_file]) + self.update_lyrics() + self.print_metadata() + utils.hide_cursor() + except TypeError: + os.system('clear') + print('$EDITOR is not set') + time.sleep(1) + elif key == 'r': self.print_metadata() - utils.hide_cursor() - except TypeError: + elif key == 'd': + os.remove(self.lyrics_file) + self.update_lyrics() + elif key == 'n': + self.spotify.next() + elif key == 'p': + self.spotify.prev() + elif key == 't': + self.spotify.toggle() + elif key == 'h': os.system('clear') - print('$EDITOR is not set') - time.sleep(1) - elif key == 'r': - self.print_metadata() - elif key == 'd': - os.remove(self.lyrics_file) - self.update_lyrics() - elif key == 'n': - self.spotify.next() - elif key == 'p': - self.spotify.prev() - elif key == 't': - self.spotify.toggle() - elif key == 'h': - os.system('clear') - album_cover.visibility = ueberzug.Visibility.INVISIBLE - utils.move_cursor(0, 0) - utils.print_help() - time.sleep(5) - self.print_metadata() - album_cover.visibility = ueberzug.Visibility.VISIBLE - key_poller.flush() + album_cover.visibility = ueberzug.Visibility.INVISIBLE + utils.move_cursor(0, 0) + utils.print_help() + time.sleep(5) + self.print_metadata() + album_cover.visibility = ueberzug.Visibility.VISIBLE + key_poller.flush() + elif key == 'g': + modified_key = key_poller.poll(timeout=1.0) + if modified_key == 'g': + self.current_line = 0 + elif key == 'G': + self.current_line = len(wrapped_lines)-n_entries def main(): diff --git a/utils.py b/utils.py index af4bacf..04546a6 100644 --- a/utils.py +++ b/utils.py @@ -55,14 +55,13 @@ def __enter__(self): def __exit__(self, type, value, traceback): termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term) - def poll(self): - dr,dw,de = select.select([sys.stdin], [], [], 0.0) + def poll(self, timeout=0.0): + dr,dw,de = select.select([sys.stdin], [], [], timeout) return sys.stdin.read(1) if not dr == [] else None def flush(self): termios.tcflush(sys.stdin, termios.TCIOFLUSH) - class Spotify(object): def __init__(self): session_bus = dbus.SessionBus() @@ -97,18 +96,20 @@ def toggle(self): def print_help(): print(boldify(''' -| Action | Keybinding | -|:-------------:|:------------:| -| Scroll Up | k | -| Scroll Down | j | -| Edit Lyrics | e | -| Refresh | r | -| Toggle | t | -| Next | n | -| Prev | p | -| Update Lyrics | d | -| Help | h | -| Quit Program | q | +| Action | Keybinding | +|:-------------------:|:-------------:| +| Scroll Up | k | +| Scroll Down | j | +| Beginning of Lyrics | gg | +| End of Lyrics | G | +| Edit Lyrics | e | +| Refresh | r | +| Toggle | t | +| Next | n | +| Prev | p | +| Update Lyrics | d | +| Help | h | +| Quit Program | q | - Edit Lyrics: Open lyrics in `$EDITOR`. - Refresh: Refresh lyrics and song metadata.