album_search.py
search_album(term)
¶
Search for albums.
Source code in mps_youtube/commands/album_search.py
@command(r'album\s*(.{0,500})', 'album')
def search_album(term):
"""Search for albums. """
# pylint: disable=R0914,R0912
if not term:
show_message("Enter album name:", c.g, update=True)
term = input("> ")
if not term or len(term) < 2:
g.message = c.r + "Not enough input!" + c.w
g.content = content_py.generate_songlist_display()
return
album = _get_mb_album(term)
if not album:
show_message("Album '%s' not found!" % term)
return
prompt = "Artist? [%s] > " % album['artist']
util.xprint(prompt, end="")
artistentry = input().strip()
if artistentry:
if artistentry == "q":
show_message("Album search abandoned!")
return
album = _get_mb_album(term, artist=artistentry)
if not album:
show_message("Album '%s' by '%s' not found!" % (term, artistentry))
return
title, artist = album['title'], album['artist']
mb_tracks = _get_mb_tracks(album['aid'])
if not mb_tracks:
show_message("Album '%s' by '%s' has 0 tracks!" % (title, artist))
return
msg = "%s%s%s by %s%s%s\n\n" % (c.g, title, c.w, c.g, artist, c.w)
msg += "Enter to begin matching or [q] to abort"
g.message = msg
g.content = "Tracks:\n"
for n, track in enumerate(mb_tracks, 1):
g.content += "%02s %s" % (n, track['title'])
g.content += "\n"
screen.update()
entry = input("Continue? [Enter] > ")
if entry == "":
pass
else:
show_message("Album search abandoned!")
return
songs = []
screen.clear()
itt = _match_tracks(artist, title, mb_tracks)
stash = config.SEARCH_MUSIC.get, config.ORDER.get
config.SEARCH_MUSIC.value = True
config.ORDER.value = "relevance"
try:
songs.extend(itt)
except KeyboardInterrupt:
util.xprint("%sHalted!%s" % (c.r, c.w))
finally:
config.SEARCH_MUSIC.value, config.ORDER.value = stash
if songs:
util.xprint("\n%s / %s songs matched" % (len(songs), len(mb_tracks)))
input("Press Enter to continue")
if g.lastfm_network:
g.artist = artist
g.album = title
g.scrobble = True
# Fill up queue with all the track names
g.scrobble_queue = [t['title'] for t in mb_tracks]
msg = "Contents of album %s%s - %s%s %s(%d/%d)%s:" % (
c.y, artist, title, c.w, c.b, len(songs), len(mb_tracks), c.w)
failmsg = "Found no album tracks for %s%s%s" % (c.y, title, c.w)
paginatesongs(songs, msg=msg, failmsg=failmsg)
show_message(message, col='', update=False)
¶
Show message using col, update screen if required.
Source code in mps_youtube/commands/album_search.py
def show_message(message, col=c.r, update=False):
""" Show message using col, update screen if required. """
g.content = content_py.generate_songlist_display()
g.message = col + message + c.w
if update:
screen.update()