Skip to content

Commit a003eed

Browse files
committed
add new keybindings and some refactoring
1 parent 645160d commit a003eed

File tree

4 files changed

+81
-68
lines changed

4 files changed

+81
-68
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Yet Another Spotify Command Line Lyrics
44
![Lyrics-Screenshot](https://raw.githubusercontent.com/goktug97/yet-another-spotify-lyrics/master/screenshot.jpg)
55

66
## Requirements
7+
* Linux
8+
* Python >= 3.6
79
* ueberzug
810
* dbus-python
911
* requests
@@ -33,18 +35,20 @@ spotify-lyrics
3335

3436
### Keybindings
3537

36-
| Action | Keybinding |
37-
|:-------------:|:------------:|
38-
| Scroll Up | <kbd>k</kbd> |
39-
| Scroll Down | <kbd>j</kbd> |
40-
| Edit Lyrics | <kbd>e</kbd> |
41-
| Refresh | <kbd>r</kbd> |
42-
| Toggle | <kbd>t</kbd> |
43-
| Next | <kbd>n</kbd> |
44-
| Prev | <kbd>p</kbd> |
45-
| Update Lyrics | <kbd>d</kbd> |
46-
| Help | <kbd>h</kbd> |
47-
| Quit Program | <kbd>q</kbd> |
38+
| Action | Keybinding |
39+
|:-------------------:|:-------------:|
40+
| Scroll Up | <kbd>k</kbd> |
41+
| Scroll Down | <kbd>j</kbd> |
42+
| Beginning of Lyrics | <kbd>gg</kbd> |
43+
| End of Lyrics | <kbd>G</kbd> |
44+
| Edit Lyrics | <kbd>e</kbd> |
45+
| Refresh | <kbd>r</kbd> |
46+
| Toggle | <kbd>t</kbd> |
47+
| Next | <kbd>n</kbd> |
48+
| Prev | <kbd>p</kbd> |
49+
| Update Lyrics | <kbd>d</kbd> |
50+
| Help | <kbd>h</kbd> |
51+
| Quit Program | <kbd>q</kbd> |
4852

4953
- Edit Lyrics: Open lyrics in `$EDITOR`.
5054
- Refresh: Refresh lyrics and song metadata.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
long_description = f.read()
99

1010
setup(name='yet-another-spotify-lyrics',
11-
version='2.2.3',
11+
version='2.3.0',
1212
description='Command Line Spotify Lyrics with Album Cover',
1313
author='Göktuğ Karakaşlı',
1414
author_email='[email protected]',
@@ -17,7 +17,7 @@
1717
long_description_content_type='text/markdown',
1818
url='https://github.com/goktug97/yet-another-spotify-lyrics',
1919
download_url=(
20-
'https://github.com/goktug97/yet-another-spotify-lyrics/archive/v2.2.3.tar.gz'),
20+
'https://github.com/goktug97/yet-another-spotify-lyrics/archive/v2.3.0.tar.gz'),
2121
py_modules=[os.path.splitext(os.path.basename(path))[0]
2222
for path in ['spotify_lyrics',
2323
'utils',

spotify_lyrics.py

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def main(self, canvas):
118118
if difference > 0:
119119
self.current_line -= difference
120120
self.current_line = max(0, self.current_line)
121-
self.current_line = min(self.current_line, len(wrapped_lines)-1)
121+
self.current_line = min(self.current_line,
122+
len(wrapped_lines)-n_entries)
122123
album_cover.x = self.columns//2
123124
self.print_metadata()
124125

@@ -138,47 +139,54 @@ def main(self, canvas):
138139
utils.delete_line()
139140

140141
key = key_poller.poll()
141-
if key == 'q':
142-
os.system('clear')
143-
break
144-
elif key == 'j':
145-
if rows - start_row == n_entries:
142+
if key is not None:
143+
if key == 'q':
144+
os.system('clear')
145+
break
146+
elif key == 'j' or ord(key) == 5:
146147
self.current_line += 1
147-
self.current_line = min(self.current_line, len(wrapped_lines)-1)
148-
elif key == 'k':
149-
self.current_line += -1
150-
self.current_line = max(self.current_line, 0)
151-
elif key == 'e':
152-
try:
153-
EDITOR = os.environ.get('EDITOR')
154-
call([EDITOR, self.lyrics_file])
155-
self.update_lyrics()
148+
self.current_line = min(self.current_line,
149+
len(wrapped_lines)-n_entries)
150+
elif key == 'k' or ord(key) == 25:
151+
self.current_line += -1
152+
self.current_line = max(self.current_line, 0)
153+
elif key == 'e':
154+
try:
155+
EDITOR = os.environ.get('EDITOR')
156+
call([EDITOR, self.lyrics_file])
157+
self.update_lyrics()
158+
self.print_metadata()
159+
utils.hide_cursor()
160+
except TypeError:
161+
os.system('clear')
162+
print('$EDITOR is not set')
163+
time.sleep(1)
164+
elif key == 'r':
156165
self.print_metadata()
157-
utils.hide_cursor()
158-
except TypeError:
166+
elif key == 'd':
167+
os.remove(self.lyrics_file)
168+
self.update_lyrics()
169+
elif key == 'n':
170+
self.spotify.next()
171+
elif key == 'p':
172+
self.spotify.prev()
173+
elif key == 't':
174+
self.spotify.toggle()
175+
elif key == 'h':
159176
os.system('clear')
160-
print('$EDITOR is not set')
161-
time.sleep(1)
162-
elif key == 'r':
163-
self.print_metadata()
164-
elif key == 'd':
165-
os.remove(self.lyrics_file)
166-
self.update_lyrics()
167-
elif key == 'n':
168-
self.spotify.next()
169-
elif key == 'p':
170-
self.spotify.prev()
171-
elif key == 't':
172-
self.spotify.toggle()
173-
elif key == 'h':
174-
os.system('clear')
175-
album_cover.visibility = ueberzug.Visibility.INVISIBLE
176-
utils.move_cursor(0, 0)
177-
utils.print_help()
178-
time.sleep(5)
179-
self.print_metadata()
180-
album_cover.visibility = ueberzug.Visibility.VISIBLE
181-
key_poller.flush()
177+
album_cover.visibility = ueberzug.Visibility.INVISIBLE
178+
utils.move_cursor(0, 0)
179+
utils.print_help()
180+
time.sleep(5)
181+
self.print_metadata()
182+
album_cover.visibility = ueberzug.Visibility.VISIBLE
183+
key_poller.flush()
184+
elif key == 'g':
185+
modified_key = key_poller.poll(timeout=1.0)
186+
if modified_key == 'g':
187+
self.current_line = 0
188+
elif key == 'G':
189+
self.current_line = len(wrapped_lines)-n_entries
182190

183191

184192
def main():

utils.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ def __enter__(self):
5555
def __exit__(self, type, value, traceback):
5656
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
5757

58-
def poll(self):
59-
dr,dw,de = select.select([sys.stdin], [], [], 0.0)
58+
def poll(self, timeout=0.0):
59+
dr,dw,de = select.select([sys.stdin], [], [], timeout)
6060
return sys.stdin.read(1) if not dr == [] else None
6161

6262
def flush(self):
6363
termios.tcflush(sys.stdin, termios.TCIOFLUSH)
6464

65-
6665
class Spotify(object):
6766
def __init__(self):
6867
session_bus = dbus.SessionBus()
@@ -97,18 +96,20 @@ def toggle(self):
9796

9897
def print_help():
9998
print(boldify('''
100-
| Action | Keybinding |
101-
|:-------------:|:------------:|
102-
| Scroll Up | k |
103-
| Scroll Down | j |
104-
| Edit Lyrics | e |
105-
| Refresh | r |
106-
| Toggle | t |
107-
| Next | n |
108-
| Prev | p |
109-
| Update Lyrics | d |
110-
| Help | h |
111-
| Quit Program | q |
99+
| Action | Keybinding |
100+
|:-------------------:|:-------------:|
101+
| Scroll Up | <kbd>k</kbd> |
102+
| Scroll Down | <kbd>j</kbd> |
103+
| Beginning of Lyrics | <kbd>gg</kbd> |
104+
| End of Lyrics | <kbd>G</kbd> |
105+
| Edit Lyrics | <kbd>e</kbd> |
106+
| Refresh | <kbd>r</kbd> |
107+
| Toggle | <kbd>t</kbd> |
108+
| Next | <kbd>n</kbd> |
109+
| Prev | <kbd>p</kbd> |
110+
| Update Lyrics | <kbd>d</kbd> |
111+
| Help | <kbd>h</kbd> |
112+
| Quit Program | <kbd>q</kbd> |
112113
113114
- Edit Lyrics: Open lyrics in `$EDITOR`.
114115
- Refresh: Refresh lyrics and song metadata.

0 commit comments

Comments
 (0)