fix search
This commit is contained in:
parent
33f17887c2
commit
64f738c5f0
|
@ -394,21 +394,58 @@ class PysonicSubsonicApi(object):
|
||||||
|
|
||||||
# TODO make this more efficient
|
# TODO make this more efficient
|
||||||
albums = 0
|
albums = 0
|
||||||
for item in self.library.get_artists():
|
for album in self.library.get_albums():
|
||||||
if query in item["name"].lower():
|
if query not in album["name"].lower():
|
||||||
response.add_child("album", _parent="searchResult2", **self.render_node(item, item["metadata"], {}, {}))
|
continue
|
||||||
albums += 1
|
|
||||||
if albums >= albumCount:
|
response.add_child("album", _parent="searchResult2",
|
||||||
break
|
id=album["dir"],
|
||||||
|
parent=album["artistdir"],
|
||||||
|
isDir="true",
|
||||||
|
title=album["name"],
|
||||||
|
album=album["name"],
|
||||||
|
artist=album["artistname"],
|
||||||
|
coverArt=album["coverid"]
|
||||||
|
#year=TODO
|
||||||
|
# playCount="0"
|
||||||
|
# created="2016-05-08T05:31:31.000Z"/>)
|
||||||
|
)
|
||||||
|
albums += 1
|
||||||
|
if albums >= albumCount:
|
||||||
|
break
|
||||||
|
|
||||||
# TODO make this more efficient
|
# TODO make this more efficient
|
||||||
songs = 0
|
songs = 0
|
||||||
for item in self.library.get_songs(limit=9999999, shuffle=False):
|
for song in self.library.db.get_songs():
|
||||||
if query in item["name"].lower():
|
if query not in song["title"].lower():
|
||||||
response.add_child("song", _parent="searchResult2", **self.render_node(item, item["metadata"], {}, {}))
|
continue
|
||||||
songs += 1
|
|
||||||
if songs > songCount:
|
response.add_child("song", _parent="searchResult2",
|
||||||
break
|
id=song["id"],
|
||||||
|
parent=song["albumdir"],
|
||||||
|
isDir="false",
|
||||||
|
title=song["title"],
|
||||||
|
album=song["albumname"],
|
||||||
|
artist=song["artistname"],
|
||||||
|
track=song["track"],
|
||||||
|
year=song["year"],
|
||||||
|
genre=song["genrename"],
|
||||||
|
coverArt=song["albumcoverid"],
|
||||||
|
size=song["size"],
|
||||||
|
contentType=song["format"],
|
||||||
|
duration=song["length"],
|
||||||
|
bitRate=song["bitrate"],
|
||||||
|
path=song["file"],
|
||||||
|
playCount=420,
|
||||||
|
albumId=song["albumid"],
|
||||||
|
type="music"
|
||||||
|
# suffix="mp3"
|
||||||
|
# created="2012-09-17T22:35:19.000Z"
|
||||||
|
)
|
||||||
|
|
||||||
|
songs += 1
|
||||||
|
if songs > songCount:
|
||||||
|
break
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ class PysonicDatabase(object):
|
||||||
return libs
|
return libs
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_artists(self, cursor, id=None, dirid=None, sortby=None, order=None):
|
def get_artists(self, cursor, id=None, dirid=None, sortby="name", order=None):
|
||||||
assert order in ["asc", "desc", None]
|
assert order in ["asc", "desc", None]
|
||||||
artists = []
|
artists = []
|
||||||
q = "SELECT * FROM artists"
|
q = "SELECT * FROM artists"
|
||||||
|
@ -213,14 +213,14 @@ class PysonicDatabase(object):
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_albums(self, cursor, id=None, artist=None, sortby=None, order=None, limit=None):
|
def get_albums(self, cursor, id=None, artist=None, sortby="name", order=None, limit=None):
|
||||||
"""
|
"""
|
||||||
:param limit: int or tuple of int, int. translates directly to sql logic.
|
:param limit: int or tuple of int, int. translates directly to sql logic.
|
||||||
"""
|
"""
|
||||||
if order:
|
if order:
|
||||||
order = {"asc": "ASC", "desc": "DESC"}[order]
|
order = {"asc": "ASC", "desc": "DESC"}[order]
|
||||||
|
|
||||||
if sortby and sortby == "random":
|
if sortby == "random":
|
||||||
sortby = "RANDOM()"
|
sortby = "RANDOM()"
|
||||||
|
|
||||||
albums = []
|
albums = []
|
||||||
|
@ -263,13 +263,13 @@ class PysonicDatabase(object):
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
@readcursor
|
@readcursor
|
||||||
def get_songs(self, cursor, id=None, genre=None, sortby=None, order=None, limit=None):
|
def get_songs(self, cursor, id=None, genre=None, sortby="title", order=None, limit=None):
|
||||||
# TODO make this query massively uglier by joining albums and artists so that artistid etc can be a filter
|
# TODO make this query massively uglier by joining albums and artists so that artistid etc can be a filter
|
||||||
# or maybe lookup those IDs in the library layer?
|
# or maybe lookup those IDs in the library layer?
|
||||||
if order:
|
if order:
|
||||||
order = {"asc": "ASC", "desc": "DESC"}[order]
|
order = {"asc": "ASC", "desc": "DESC"}[order]
|
||||||
|
|
||||||
if sortby and sortby == "random":
|
if sortby == "random":
|
||||||
sortby = "RANDOM()"
|
sortby = "RANDOM()"
|
||||||
|
|
||||||
songs = []
|
songs = []
|
||||||
|
@ -280,10 +280,13 @@ class PysonicDatabase(object):
|
||||||
alb.name as albumname,
|
alb.name as albumname,
|
||||||
alb.coverid as albumcoverid,
|
alb.coverid as albumcoverid,
|
||||||
art.name as artistname,
|
art.name as artistname,
|
||||||
g.name as genrename
|
g.name as genrename,
|
||||||
|
albdir.id as albumdir
|
||||||
FROM songs as s
|
FROM songs as s
|
||||||
INNER JOIN albums as alb
|
INNER JOIN albums as alb
|
||||||
on s.albumid == alb.id
|
on s.albumid == alb.id
|
||||||
|
INNER JOIN dirs as albdir
|
||||||
|
on albdir.id = alb.dir
|
||||||
INNER JOIN artists as art
|
INNER JOIN artists as art
|
||||||
on alb.artistid = art.id
|
on alb.artistid = art.id
|
||||||
LEFT JOIN genres as g
|
LEFT JOIN genres as g
|
||||||
|
|
Loading…
Reference in New Issue