Skip to content

Commit

Permalink
add new keybindings and some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
goktug97 committed Dec 21, 2019
1 parent 645160d commit a003eed
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 68 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,18 +35,20 @@ spotify-lyrics

### Keybindings

| Action | Keybinding |
|:-------------:|:------------:|
| Scroll Up | <kbd>k</kbd> |
| Scroll Down | <kbd>j</kbd> |
| Edit Lyrics | <kbd>e</kbd> |
| Refresh | <kbd>r</kbd> |
| Toggle | <kbd>t</kbd> |
| Next | <kbd>n</kbd> |
| Prev | <kbd>p</kbd> |
| Update Lyrics | <kbd>d</kbd> |
| Help | <kbd>h</kbd> |
| Quit Program | <kbd>q</kbd> |
| Action | Keybinding |
|:-------------------:|:-------------:|
| Scroll Up | <kbd>k</kbd> |
| Scroll Down | <kbd>j</kbd> |
| Beginning of Lyrics | <kbd>gg</kbd> |
| End of Lyrics | <kbd>G</kbd> |
| Edit Lyrics | <kbd>e</kbd> |
| Refresh | <kbd>r</kbd> |
| Toggle | <kbd>t</kbd> |
| Next | <kbd>n</kbd> |
| Prev | <kbd>p</kbd> |
| Update Lyrics | <kbd>d</kbd> |
| Help | <kbd>h</kbd> |
| Quit Program | <kbd>q</kbd> |

- Edit Lyrics: Open lyrics in `$EDITOR`.
- Refresh: Refresh lyrics and song metadata.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
86 changes: 47 additions & 39 deletions spotify_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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():
Expand Down
31 changes: 16 additions & 15 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 | <kbd>k</kbd> |
| Scroll Down | <kbd>j</kbd> |
| Beginning of Lyrics | <kbd>gg</kbd> |
| End of Lyrics | <kbd>G</kbd> |
| Edit Lyrics | <kbd>e</kbd> |
| Refresh | <kbd>r</kbd> |
| Toggle | <kbd>t</kbd> |
| Next | <kbd>n</kbd> |
| Prev | <kbd>p</kbd> |
| Update Lyrics | <kbd>d</kbd> |
| Help | <kbd>h</kbd> |
| Quit Program | <kbd>q</kbd> |
- Edit Lyrics: Open lyrics in `$EDITOR`.
- Refresh: Refresh lyrics and song metadata.
Expand Down

0 comments on commit a003eed

Please sign in to comment.