#NEWLINE# @ protocol . commands . add ( 'list' ) #NEWLINE# def list_( context , * args ) : #NEWLINE# #INDENT# '\n    *musicpd.org, music database section:*\n\n        ``list {TYPE} [ARTIST]``\n\n        Lists all tags of the specified type. ``TYPE`` should be ``album``,\n        ``artist``, ``albumartist``, ``date``, or ``genre``.\n\n        ``ARTIST`` is an optional parameter when type is ``album``,\n        ``date``, or ``genre``. This filters the result list by an artist.\n\n    *Clarifications:*\n\n        The musicpd.org documentation for ``list`` is far from complete. The\n        command also supports the following variant:\n\n        ``list {TYPE} {QUERY}``\n\n        Where ``QUERY`` applies to all ``TYPE``. ``QUERY`` is one or more pairs\n        of a field name and a value. If the ``QUERY`` consists of more than one\n        pair, the pairs are AND-ed together to find the result. Examples of\n        valid queries and what they should return:\n\n        ``list "artist" "artist" "ABBA"``\n            List artists where the artist name is "ABBA". Response::\n\n                Artist: ABBA\n                OK\n\n        ``list "album" "artist" "ABBA"``\n            Lists albums where the artist name is "ABBA". Response::\n\n                Album: More ABBA Gold: More ABBA Hits\n                Album: Absolute More Christmas\n                Album: Gold: Greatest Hits\n                OK\n\n        ``list "artist" "album" "Gold: Greatest Hits"``\n            Lists artists where the album name is "Gold: Greatest Hits".\n            Response::\n\n                Artist: ABBA\n                OK\n\n        ``list "artist" "artist" "ABBA" "artist" "TLC"``\n            Lists artists where the artist name is "ABBA" *and* "TLC". Should\n            never match anything. Response::\n\n                OK\n\n        ``list "date" "artist" "ABBA"``\n            Lists dates where artist name is "ABBA". Response::\n\n                Date:\n                Date: 1992\n                Date: 1993\n                OK\n\n        ``list "date" "artist" "ABBA" "album" "Gold: Greatest Hits"``\n            Lists dates where artist name is "ABBA" and album name is "Gold:\n            Greatest Hits". Response::\n\n                Date: 1992\n                OK\n\n        ``list "genre" "artist" "The Rolling Stones"``\n            Lists genres where artist name is "The Rolling Stones". Response::\n\n                Genre:\n                Genre: Rock\n                OK\n\n    *ncmpc:*\n\n    - capitalizes the field argument.\n    ' #NEWLINE# params = list ( args ) #NEWLINE# if ( not params ) : #NEWLINE# #INDENT# raise exceptions . MpdArgError ( 'incorrect arguments' ) #NEWLINE# #UNINDENT# field = params . pop ( 0 ) . lower ( ) #NEWLINE# field = _LIST_MAPPING . get ( context ) #NEWLINE# if ( field is None ) : #NEWLINE# #INDENT# raise exceptions . MpdArgError ( 'incorrect arguments' ) #NEWLINE# #UNINDENT# query = None #NEWLINE# if ( len ( params ) == 1 ) : #NEWLINE# #INDENT# if ( field != 'album' ) : #NEWLINE# #INDENT# raise exceptions . MpdArgError ( 'should be "Album" for 3 arguments' ) #NEWLINE# #UNINDENT# if params [ 0 ] . strip ( ) : #NEWLINE# #INDENT# query = { #NEWLINE# #INDENT# 'artist' : params , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# query = _query_from_mpd_search_parameters ( params , _LIST_MAPPING ) #NEWLINE# #UNINDENT# except exceptions . MpdArgError as e : #NEWLINE# #INDENT# e . message = 'not able to parse args' #NEWLINE# raise #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# name = _LIST_NAME_MAPPING [ field ] #NEWLINE# result = context . core . library . get_distinct ( field , query ) #NEWLINE# return [ ( name , value ) for value in result . get ( ) ]