From 6b86f3a43aa80d57a249a5dd7d8e8fa2e4f3bfdd Mon Sep 17 00:00:00 2001 From: spl0k Date: Sat, 8 Dec 2018 17:42:20 +0100 Subject: [PATCH] Added getSongsByGenre --- docs/api.md | 10 +++++----- supysonic/api/albums_songs.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index fcf2643..d5ce91d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -51,7 +51,7 @@ or with version 1.8.0. | [`getAlbumList`](#getalbumlist) | | ✔️ | | [`getAlbumList2`](#getalbumlist2) | | ✔️ | | [`getRandomSongs`](#getrandomsongs) | | ✔️ | -| [`getSongsByGenre`](#getsongsbygenre) | 1.9.0 | 📅 | +| [`getSongsByGenre`](#getsongsbygenre) | 1.9.0 | ✔️ | | [`getNowPlaying`](#getnowplaying) | | ✔️ | | [`getStarred`](#getstarred) | | ✔️ | | [`getStarred2`](#getstarred2) | | ✔️ | @@ -308,13 +308,13 @@ On 1.10.1, `byYear` and `byGenre` were added to `type` | `musicFolderId` | | ✔️ | #### `getSongsByGenre` -📅 1.9.0 +✔️ 1.9.0 | Parameter | Vers. | | |-----------------|--------|---| -| `genre` | 1.9.0 | 📅 | -| `count` | 1.9.0 | 📅 | -| `offset` | 1.9.0 | 📅 | +| `genre` | 1.9.0 | ✔️ | +| `count` | 1.9.0 | ✔️ | +| `offset` | 1.9.0 | ✔️ | | `musicFolderId` | 1.12.0 | 📅 | #### `getNowPlaying` diff --git a/supysonic/api/albums_songs.py b/supysonic/api/albums_songs.py index f0934fb..6ceeca8 100644 --- a/supysonic/api/albums_songs.py +++ b/supysonic/api/albums_songs.py @@ -113,6 +113,19 @@ def album_list_id3(): album = [ f.as_subsonic_album(request.user) for f in query.limit(size, offset) ] )) +@api.route('/getSongsByGenre.view', methods = [ 'GET', 'POST' ]) +def songs_by_genre(): + genre = request.values['genre'] + + count, offset = map(request.values.get, [ 'count', 'offset' ]) + count = int(count) if count else 10 + offset = int(offset) if offset else 0 + + query = select(t for t in Track if t.genre == genre).limit(count, offset) + return request.formatter('songsByGenre', dict( + song = [ t.as_subsonic_child(request.user, request.client) for t in query ] + )) + @api.route('/getNowPlaying.view', methods = [ 'GET', 'POST' ]) def now_playing(): query = User.select(lambda u: u.last_play is not None and u.last_play_date + timedelta(minutes = 3) > now())