32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
const Koa = require('koa');
|
|
var router = require("koa-router");
|
|
const moment = require('moment');
|
|
const crypto = require('crypto');
|
|
|
|
const app = new Koa();
|
|
const _ = new router()
|
|
|
|
_.get('/qingting/', manageRedirect)
|
|
_.get('/qingting/:channel_id', manageRedirect)
|
|
|
|
async function manageRedirect(ctx) {
|
|
let channel_id = ctx.params.channel_id || 388
|
|
let url = getUrl(channel_id)
|
|
console.log(url)
|
|
ctx.response.redirect(url);
|
|
}
|
|
|
|
function getUrl(channel_id) {
|
|
const channel_path = `/live/${channel_id}/64k.mp3`
|
|
const encode_channel_path = encodeURIComponent(channel_path)
|
|
const time = encodeURIComponent(moment().add(1, "hours").unix().toString(16))
|
|
const app_id = encodeURIComponent('web')
|
|
var sign_path = "app_id=".concat(app_id, "&path=").concat(encode_channel_path, "&ts=").concat(time)
|
|
var sign = crypto.createHmac("md5", "Lwrpu$K5oP").update(sign_path).digest("hex").toString();
|
|
var path = `https://lhttp.qingting.fm${channel_path}?app_id=${app_id}&ts=${time}&sign=${sign}`
|
|
return path
|
|
}
|
|
|
|
app.use(_.routes())
|
|
app.listen(80);
|