Implemented functionality of getting last played songs.
This commit is contained in:
parent
76a4f42d7a
commit
f89fbc2aa9
@ -1,5 +1,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const uti = require("util");
|
||||||
|
const exec = uti.promisify(require("child_process").exec);
|
||||||
|
|
||||||
const Koa = require("koa");
|
const Koa = require("koa");
|
||||||
const koaPug = require("koa-pug");
|
const koaPug = require("koa-pug");
|
||||||
@ -30,13 +32,23 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
function setRoutes() {
|
function setRoutes() {
|
||||||
return koaRouter().get('/', async ctx => {
|
return koaRouter().get('/', async ctx => {
|
||||||
await ctx.render('index', {
|
await ctx.render('index', {
|
||||||
title: "/ Radio",
|
title: "/ Radio",
|
||||||
description: "Internet-radio broadcasting from under my desk.",
|
description: "Internet-radio broadcasting from under my desk.",
|
||||||
main_site: util.getServiceByHost(ctx.header.host),
|
main_site: util.getServiceByHost(ctx.header.host),
|
||||||
radio_status: await getRadioStatus()
|
radio_status: await getRadioStatus(),
|
||||||
|
last_songs: await getLastSongs()
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.get('/filelist', async ctx => {
|
.get('/filelist', async ctx => {
|
||||||
@ -51,6 +63,9 @@ function setRoutes() {
|
|||||||
})
|
})
|
||||||
.get('/stats', async ctx => {
|
.get('/stats', async ctx => {
|
||||||
ctx.body = await getRadioStatus();
|
ctx.body = await getRadioStatus();
|
||||||
|
})
|
||||||
|
.get('/lastplayed', async ctx => {
|
||||||
|
ctx.body = await getLastSongs();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user