Skip to content

Commit

Permalink
Merge pull request #43 from Jugran/feature/lyrics-provider
Browse files Browse the repository at this point in the history
Feature/lyrics provider
  • Loading branch information
Jugran authored Sep 9, 2024
2 parents 446dc03 + 6724208 commit 862c6a0
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 109 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: File",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/lyrics/lyrics_in_terminal.py",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}/lyrics:${PYTHONPATH}"
},
"justMyCode": true
},
]
}
4 changes: 2 additions & 2 deletions lyrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

CACHE_PATH = Path.home().joinpath('.cache', 'lyrics')

CONFIG_PATH = Path.home().joinpath('.config', 'lyrics-in-terminal','lyrics.cfg')
CONFIG_PATH = Path.home().joinpath('.config', 'lyrics-in-terminal', 'lyrics.cfg')

__version__ = '1.6.0'
__version__ = '1.7.0-dev'

if not CONFIG_PATH.exists():
from shutil import copy
Expand Down
4 changes: 1 addition & 3 deletions lyrics/lyrics.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ step-up=arrow_left
step-down=arrow_right
step-size=5

google=R
azLyrics=r

left=j
center=k
right=l

autoswitchtoggle=a
cycle-source=s

delete=d
edit=e
Expand Down
2 changes: 1 addition & 1 deletion lyrics/lyrics_in_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def wrapper(*args, **kwargs):


@ErrorHandler
def init_pager(stdscr):
def init_pager(stdscr=None):
defaults = Config('OPTIONS')

if len(sys.argv) >= 2:
Expand Down
7 changes: 2 additions & 5 deletions lyrics/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@ def update(self):

return False

def refresh(self, source=None, cache=True):
def refresh(self, cycle_source=False, source=None, cache=True):
''' Re-fetches lyrics from procided source
source -> source name ('google' or 'azlyrics')
cache -> bool | wether to store cache file
'''

if source is None:
source = self.default_source
self.track.get_lyrics(source, cache=cache)
self.track.get_lyrics(source, cycle_source, cache)
23 changes: 18 additions & 5 deletions lyrics/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class Track:
def __init__(self,
artist=None,
title=None,
artist='',
title='',
align=1,
width=0):

Expand All @@ -15,9 +15,11 @@ def __init__(self,
self.alignment = align
self.width = width
self.length = 0
self.lyrics = None
self.lyrics = []
self.source = None
self.album = None
self.trackid = None
self.sources = ['google', 'azlyrics', 'genius']

def __str__(self):
''' trackname in format "{artist} - {title}"
Expand Down Expand Up @@ -57,10 +59,21 @@ def update(self, artist, title, album, trackid):
# self.art_url = art_url
# self.get_lyrics()

def get_lyrics(self, source, cache=True):
def get_lyrics(self, source, cycle_source=False, cache=True):
''' fetch lyrics off the internet
'''
self.lyrics = util.get_lyrics(self.track_name, source, cache=cache)
if self.source is None or self.source == 'cache':
self.source = source or self.sources[0]

if cycle_source:
curr_source = self.sources.index(self.source)
next_source = (curr_source + 1) % len(self.sources)
source = self.sources[next_source]
cache = False
else:
source = 'any'

self.lyrics, self.source = util.get_lyrics(self.track_name, source, cache=cache)
self.width = len(max(self.lyrics, key=len))
self.length = len(self.lyrics)

Expand Down
Loading

0 comments on commit 862c6a0

Please sign in to comment.