mpd: Rename constants
This commit is contained in:
parent
17308e2a26
commit
c5f64648de
@ -10,7 +10,7 @@ from mopidy.frontends.mpd.exceptions import MpdArgError, MpdNotImplemented
|
||||
from mopidy.frontends.mpd.protocol import handle_request, stored_playlists
|
||||
|
||||
|
||||
QUERY_FIELDS = r"""
|
||||
SEARCH_FIELDS = r"""
|
||||
[Aa]lbum
|
||||
| [Aa]rtist
|
||||
| [Aa]lbumartist
|
||||
@ -26,12 +26,12 @@ QUERY_FIELDS = r"""
|
||||
| [Aa]ny
|
||||
"""
|
||||
|
||||
QUERY_RE = r"""
|
||||
SEARCH_QUERY = r"""
|
||||
(?P<mpd_query>
|
||||
(
|
||||
"? # Optional quote around the field type
|
||||
(
|
||||
""" + QUERY_FIELDS + """
|
||||
(?:
|
||||
""" + SEARCH_FIELDS + """
|
||||
)
|
||||
"? # End of optional quote around the field type
|
||||
\ # A single space
|
||||
@ -42,27 +42,31 @@ QUERY_RE = r"""
|
||||
$
|
||||
"""
|
||||
|
||||
MPD_SEARCH_QUERY_RE = re.compile(r"""
|
||||
SEARCH_PAIR_WITHOUT_GROUPS = r"""
|
||||
\b # Only begin matching at word bundaries
|
||||
"? # Optional quote around the field type
|
||||
(?: # A non-capturing group for the field type
|
||||
""" + QUERY_FIELDS + """
|
||||
""" + SEARCH_FIELDS + """
|
||||
)
|
||||
"? # End of optional quote around the field type
|
||||
\ # A single space
|
||||
"[^"]+" # Matching a quoted search string
|
||||
""", flags=(re.UNICODE | re.VERBOSE))
|
||||
"""
|
||||
SEARCH_PAIR_WITHOUT_GROUPS_RE = re.compile(
|
||||
SEARCH_PAIR_WITHOUT_GROUPS, flags=(re.UNICODE | re.VERBOSE))
|
||||
|
||||
MPD_SEARCH_QUERY_PART_RE = re.compile(r"""
|
||||
SEARCH_PAIR_WITH_GROUPS = r"""
|
||||
\b # Only begin matching at word bundaries
|
||||
"? # Optional quote around the field type
|
||||
(?P<field>( # A capturing group for the field type
|
||||
""" + QUERY_FIELDS + """
|
||||
""" + SEARCH_FIELDS + """
|
||||
))
|
||||
"? # End of optional quote around the field type
|
||||
\ # A single space
|
||||
"(?P<what>[^"]+)" # Capturing a quoted search string
|
||||
""", flags=(re.UNICODE | re.VERBOSE))
|
||||
"""
|
||||
SEARCH_PAIR_WITH_GROUPS_RE = re.compile(
|
||||
SEARCH_PAIR_WITH_GROUPS, flags=(re.UNICODE | re.VERBOSE))
|
||||
|
||||
|
||||
def _query_from_mpd_search_format(mpd_query):
|
||||
@ -73,10 +77,10 @@ def _query_from_mpd_search_format(mpd_query):
|
||||
:param mpd_query: the MPD search query
|
||||
:type mpd_query: string
|
||||
"""
|
||||
query_parts = MPD_SEARCH_QUERY_RE.findall(mpd_query)
|
||||
pairs = SEARCH_PAIR_WITHOUT_GROUPS_RE.findall(mpd_query)
|
||||
query = {}
|
||||
for query_part in query_parts:
|
||||
m = MPD_SEARCH_QUERY_PART_RE.match(query_part)
|
||||
for pair in pairs:
|
||||
m = SEARCH_PAIR_WITH_GROUPS_RE.match(pair)
|
||||
field = m.groupdict()['field'].lower()
|
||||
if field == 'title':
|
||||
field = 'track_name'
|
||||
@ -119,7 +123,7 @@ def _artist_as_track(artist):
|
||||
artists=[artist])
|
||||
|
||||
|
||||
@handle_request(r'count\ ' + QUERY_RE)
|
||||
@handle_request(r'count\ ' + SEARCH_QUERY)
|
||||
def count(context, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
@ -146,7 +150,7 @@ def count(context, mpd_query):
|
||||
]
|
||||
|
||||
|
||||
@handle_request(r'find\ ' + QUERY_RE)
|
||||
@handle_request(r'find\ ' + SEARCH_QUERY)
|
||||
def find(context, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
@ -191,7 +195,7 @@ def find(context, mpd_query):
|
||||
return translator.tracks_to_mpd_format(result_tracks)
|
||||
|
||||
|
||||
@handle_request(r'findadd\ ' + QUERY_RE)
|
||||
@handle_request(r'findadd\ ' + SEARCH_QUERY)
|
||||
def findadd(context, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
@ -446,7 +450,7 @@ def rescan(context, uri=None):
|
||||
return update(context, uri, rescan_unmodified_files=True)
|
||||
|
||||
|
||||
@handle_request(r'search\ ' + QUERY_RE)
|
||||
@handle_request(r'search\ ' + SEARCH_QUERY)
|
||||
def search(context, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
@ -485,7 +489,7 @@ def search(context, mpd_query):
|
||||
return translator.tracks_to_mpd_format(artists + albums + tracks)
|
||||
|
||||
|
||||
@handle_request(r'searchadd\ ' + QUERY_RE)
|
||||
@handle_request(r'searchadd\ ' + SEARCH_QUERY)
|
||||
def searchadd(context, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
@ -506,7 +510,7 @@ def searchadd(context, mpd_query):
|
||||
context.core.tracklist.add(_get_tracks(results))
|
||||
|
||||
|
||||
@handle_request(r'searchaddpl\ "(?P<playlist_name>[^"]+)"\ ' + QUERY_RE)
|
||||
@handle_request(r'searchaddpl\ "(?P<playlist_name>[^"]+)"\ ' + SEARCH_QUERY)
|
||||
def searchaddpl(context, playlist_name, mpd_query):
|
||||
"""
|
||||
*musicpd.org, music database section:*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user