Skip to content

Commit f095240

Browse files
committed
improvements
- reset current line after the lyrics update - some refactoring
1 parent 60caa03 commit f095240

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

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.1.0',
11+
version='2.1.1',
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.1.0.tar.gz'),
20+
'https://github.com/goktug97/yet-another-spotify-lyrics/archive/v2.1.1.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: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Lyrics(object):
2626
def __init__(self):
2727
self.spotify = utils.Spotify()
2828
self.home = str(Path.home())
29+
self.current_line = 0
2930

3031
def update_directories(self):
3132
self.lyrics_directory = os.path.join(self.home, '.cache', 'spotify-lyrics')
@@ -52,6 +53,8 @@ def update_directories(self):
5253
pass
5354

5455
def print_metadata(self):
56+
os.system('clear')
57+
utils.move_cursor(0, 0)
5558
print(f'\033[95mArtist: {self.artist}\033[0m')
5659
print(f'\033[95mAlbum: {self.album}\033[0m')
5760
print(f'\033[95mSong: {self.song}\033[0m')
@@ -71,6 +74,7 @@ def update_lyrics(self):
7174
self.save_lyrics()
7275
else:
7376
self.lyrics = self.read_lyrics()
77+
self.current_line = 0
7478

7579
@ueberzug.Canvas()
7680
def main(self, canvas):
@@ -90,11 +94,8 @@ def main(self, canvas):
9094

9195
utils.hide_cursor()
9296

93-
os.system('clear')
94-
utils.move_cursor(0, 0)
9597
self.print_metadata()
9698

97-
current_line = 0
9899
start_row = 5
99100

100101
with utils.KeyPoller() as key_poller:
@@ -107,25 +108,18 @@ def main(self, canvas):
107108
self.art_url = art_url
108109
self.update_directories()
109110
self.update_lyrics()
110-
111111
album_cover.path = self.image_file
112-
113-
os.system('clear')
114-
utils.move_cursor(0, 0)
115112
self.print_metadata()
116113

117114
rows, columns = utils.terminal_size()
118115
if self.rows != rows or self.columns != columns:
119116
difference = rows - self.rows
120117
self.rows, self.columns = rows, columns
121118
if difference > 0:
122-
current_line -= difference
123-
current_line = max(0, current_line)
124-
current_line = min(current_line, len(wrapped_lines)-1)
119+
self.current_line -= difference
120+
self.current_line = max(0, self.current_line)
121+
self.current_line = min(self.current_line, len(wrapped_lines)-1)
125122
album_cover.x = self.columns//2
126-
127-
os.system('clear')
128-
utils.move_cursor(0, 0)
129123
self.print_metadata()
130124

131125
lines = self.lyrics.split('\n')
@@ -135,9 +129,9 @@ def main(self, canvas):
135129
textwrap.fill(line, columns//2-2).split('\n'))
136130

137131
utils.move_cursor(0, start_row)
138-
n_entries = min(rows+current_line-start_row,
139-
len(wrapped_lines)) - current_line
140-
for i in range(current_line, current_line + n_entries):
132+
n_entries = min(rows+self.current_line-start_row,
133+
len(wrapped_lines)) - self.current_line
134+
for i in range(self.current_line, self.current_line + n_entries):
141135
utils.delete_line()
142136
print(utils.boldify(wrapped_lines[i]))
143137
utils.move_cursor(0, n_entries+start_row)
@@ -149,24 +143,23 @@ def main(self, canvas):
149143
break
150144
elif key == 'j':
151145
if rows - start_row == n_entries:
152-
current_line += 1
153-
current_line = min(current_line, len(wrapped_lines)-1)
146+
self.current_line += 1
147+
self.current_line = min(self.current_line, len(wrapped_lines)-1)
154148
elif key == 'k':
155-
current_line += -1
156-
current_line = max(current_line, 0)
149+
self.current_line += -1
150+
self.current_line = max(self.current_line, 0)
157151
elif key == 'e':
158152
try:
159153
EDITOR = os.environ.get('EDITOR')
160154
call([EDITOR, self.lyrics_file])
161155
self.update_lyrics()
156+
self.print_metadata()
162157
utils.hide_cursor()
163158
except TypeError:
164159
os.system('clear')
165160
print('$EDITOR is not set')
166161
time.sleep(1)
167162
elif key == 'r':
168-
os.system('clear')
169-
utils.move_cursor(0, 0)
170163
self.print_metadata()
171164
elif key == 'd':
172165
os.remove(self.lyrics_file)

0 commit comments

Comments
 (0)