Skip to content

Commit 2be3f63

Browse files
committed
Subsonic: Provide a non-dummy implementation for getNowPlaying
Replace the empty/dummy implementation added in b23a56a with a one returning some valid data. As usual, we don't provide other users' data even though that's how the endpoint is specified because we don't want to leak any user data without an explicit consent. The song shown in the response is based on the scrobbling messages from the clients.
1 parent 5ac623d commit 2be3f63

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Limit also album art search to the path provided with argument `--folder`
2020
- Identify playlist-type radio streams from the Content-Type header instead of the URL, hopefully making the logic more robust
2121
- Updated the getID3 library to the release version 1.9.24-202509040923
22+
- Subsonic API:
23+
* Non-dummy implementation for the endpoint `getNowPlaying`
2224
- OpenSubsonic API:
2325
* Add property `mediaType` to the result type `Child`
2426
* Add properties `genres` and `artists` to the album results

lib/Controller/SubsonicController.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,20 @@ protected function getScanStatus() : array {
11641164
* @SubsonicAPI
11651165
*/
11661166
protected function getNowPlaying() : array {
1167-
// TODO: not supported yet
1168-
return ['nowPlaying' => ['entry' => []]];
1167+
// Note: This is documented to return latest play of all users on the server but we don't want to
1168+
// provide access to other people's data => Always return just this user's data.
1169+
$recent = $this->trackBusinessLayer->findRecentPlay($this->user(), 1);
1170+
1171+
if (!empty($recent)) {
1172+
$playTime = new \DateTime($recent[0]->getLastPlayed());
1173+
$now = new \DateTime();
1174+
$recent = $this->tracksToApi($recent);
1175+
$recent[0]['username'] = $this->user();
1176+
$recent[0]['minutesAgo'] = (int)(($now->getTimestamp() - $playTime->getTimestamp()) / 60);
1177+
$recent[0]['playerId'] = 0; // dummy
1178+
}
1179+
1180+
return ['nowPlaying' => ['entry' => $recent]];
11691181
}
11701182

11711183
/**

0 commit comments

Comments
 (0)