getLastPlayedSongs now more universal and instead of /lastplayed there is /lastsong endpoint that returns one previously played song.
This commit is contained in:
parent
d7d84a7f52
commit
645e94a5d8
@ -32,13 +32,18 @@ async function getRadioStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
async function getLastSongs(count=11) {
|
||||
const { stdout, stderr } = await exec(`tail -n ${count} /var/log/icecast/playlist.log | awk -F '|' '{ print $4 }'`);
|
||||
let songs = stdout.trim().split("\n");
|
||||
songs.pop();
|
||||
for (let i = 0; i < songs.length; ++i)
|
||||
songs[i] = songs[i].split(' - ');
|
||||
return songs;
|
||||
async function getLastPlayedSongs(count=11) {
|
||||
try {
|
||||
const { stdout, _ } = await exec(`tail -n ${count} /var/log/icecast/playlist.log | awk -F '|' 'NR<${count} { print $4 }'`);
|
||||
let songs = stdout.trim().split("\n");
|
||||
for (let i = 0; i < songs.length; ++i) {
|
||||
let song = songs[i].split(' - ');
|
||||
songs[i] = { "artist": song[0], "title": song[1] };
|
||||
}
|
||||
return songs;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function setRoutes() {
|
||||
@ -48,7 +53,7 @@ function setRoutes() {
|
||||
description: "Internet-radio broadcasting from under my desk.",
|
||||
main_site: util.getServiceByHost(ctx.header.host),
|
||||
radio_status: await getRadioStatus(),
|
||||
last_songs: await getLastSongs()
|
||||
last_songs: await getLastPlayedSongs()
|
||||
});
|
||||
})
|
||||
.get('/filelist', async ctx => {
|
||||
@ -64,8 +69,8 @@ function setRoutes() {
|
||||
.get('/stats', async ctx => {
|
||||
ctx.body = await getRadioStatus();
|
||||
})
|
||||
.get('/lastplayed', async ctx => {
|
||||
ctx.body = await getLastSongs();
|
||||
.get('/lastsong', async ctx => {
|
||||
ctx.body = await getLastPlayedSongs(2);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user