[booblyrics] able to search by artist or songtitle
This commit is contained in:
parent
74e6e30b55
commit
0628802b72
6 changed files with 66 additions and 18 deletions
|
|
@ -69,6 +69,7 @@ class Booblyrics(ReplApplication):
|
|||
COMMANDS_FORMATTERS = {'search': 'lyrics_list',
|
||||
'get': 'lyrics_get',
|
||||
}
|
||||
SEARCH_CRITERIAS = ['artist','song']
|
||||
|
||||
def complete_get(self, text, line, *ignored):
|
||||
args = line.split(' ')
|
||||
|
|
@ -99,17 +100,23 @@ class Booblyrics(ReplApplication):
|
|||
self.format(songlyrics)
|
||||
self.flush()
|
||||
|
||||
def do_search(self, pattern):
|
||||
"""
|
||||
search [PATTERN]
|
||||
def complete_search(self, text, line, *ignored):
|
||||
args = line.split(' ')
|
||||
if len(args) == 2:
|
||||
return self.SEARCH_CRITERIAS
|
||||
|
||||
Search lyrics.
|
||||
def do_search(self, line):
|
||||
"""
|
||||
search [artist | song] [PATTERN]
|
||||
|
||||
Search lyrics by artist name or by song title.
|
||||
"""
|
||||
criteria, pattern = self.parse_command_args(line, 2, 1)
|
||||
self.change_path([u'search'])
|
||||
if not pattern:
|
||||
pattern = None
|
||||
|
||||
self.start_format(pattern=pattern)
|
||||
for backend, songlyrics in self.do('iter_lyrics', pattern=pattern):
|
||||
for backend, songlyrics in self.do('iter_lyrics', criteria, pattern):
|
||||
self.cached_format(songlyrics)
|
||||
self.flush()
|
||||
|
|
|
|||
|
|
@ -41,10 +41,13 @@ class ICapLyrics(IBaseCap):
|
|||
"""
|
||||
Lyrics websites.
|
||||
"""
|
||||
def iter_lyrics(self, pattern):
|
||||
def iter_lyrics(self, criteria, pattern):
|
||||
"""
|
||||
Search lyrics and iterate on results.
|
||||
Search lyrics by artist or by song
|
||||
and iterate on results.
|
||||
|
||||
:param criteria: 'artist' or 'song'
|
||||
:type criteria: str
|
||||
:param pattern: pattern to search
|
||||
:type pattern: str
|
||||
:rtype: iter[:class:`SongLyrics`]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue