diff --git a/supysonic/api/media.py b/supysonic/api/media.py index 5b6dfd0..f43311d 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -24,7 +24,7 @@ from xml.etree import ElementTree from zipstream import ZipStream from ..cache import CacheMiss -from ..db import Track, Album, Folder, now +from ..db import Track, Album, Artist, Folder, now from ..covers import EXTENSIONS from . import get_entity, get_entity_id, api_routing @@ -413,7 +413,11 @@ def lyrics(): artist = request.values["artist"] title = request.values["title"] - query = Track.select(lambda t: title in t.title and artist in t.artist.name) + query = ( + Track.select() + .join(Artist) + .where(Track.title.contains(title), Artist.name.contains(artist)) + ) for track in query: # Read from track metadata lyrics = mediafile.MediaFile(track.path).lyrics diff --git a/tests/net/test_lyrics.py b/tests/net/test_lyrics.py index 158fddf..18057d9 100644 --- a/tests/net/test_lyrics.py +++ b/tests/net/test_lyrics.py @@ -1,7 +1,7 @@ # This file is part of Supysonic. # Supysonic is a Python implementation of the Subsonic server API. # -# Copyright (C) 2017 Alban 'spl0k' Féron +# Copyright (C) 2017-2022 Alban 'spl0k' Féron # # Distributed under terms of the GNU AGPLv3 license. @@ -10,8 +10,6 @@ import os.path import requests import unittest -from pony.orm import db_session - from supysonic.db import Folder, Artist, Album, Track from ..api.apitestbase import ApiTestBase @@ -21,42 +19,41 @@ class LyricsTestCase(ApiTestBase): def setUp(self): super().setUp() - with db_session: - folder = Folder( - name="Root", - path=os.path.abspath("tests/assets/lyrics"), - root=True, - ) + folder = Folder.create( + name="Root", + path=os.path.abspath("tests/assets/lyrics"), + root=True, + ) - artist = Artist(name="Artist") - album = Album(artist=artist, name="Album") + artist = Artist.create(name="Artist") + album = Album.create(artist=artist, name="Album") - Track( - title="Nope", - number=1, - disc=1, - artist=artist, - album=album, - path=os.path.abspath("tests/assets/lyrics/empty.mp3"), - root_folder=folder, - folder=folder, - duration=2, - bitrate=320, - last_modification=0, - ) - Track( - title="Yay", - number=1, - disc=1, - artist=artist, - album=album, - path=os.path.abspath("tests/assets/lyrics/withlyrics.mp3"), - root_folder=folder, - folder=folder, - duration=2, - bitrate=320, - last_modification=0, - ) + Track.create( + title="Nope", + number=1, + disc=1, + artist=artist, + album=album, + path=os.path.abspath("tests/assets/lyrics/empty.mp3"), + root_folder=folder, + folder=folder, + duration=2, + bitrate=320, + last_modification=0, + ) + Track.create( + title="Yay", + number=1, + disc=1, + artist=artist, + album=album, + path=os.path.abspath("tests/assets/lyrics/withlyrics.mp3"), + root_folder=folder, + folder=folder, + duration=2, + bitrate=320, + last_modification=0, + ) def test_get_lyrics(self): self._make_request("getLyrics", error=10)