mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 12:38:26 +01:00
libpoketube version 1.1!
This commit is contained in:
parent
9d64d2e8f3
commit
f5111a45d3
1 changed files with 10 additions and 62 deletions
68
server.js
68
server.js
|
@ -30,8 +30,8 @@ const fetch = require("node-fetch");
|
||||||
const { toJson } = require("xml2json");
|
const { toJson } = require("xml2json");
|
||||||
|
|
||||||
// libpoketube
|
// libpoketube
|
||||||
const fetcher = require("./src/libpoketube/libpoketube-fetcher.js");
|
const { fetcher, core, wiki, musicInfo } = require("./src/libpoketube/loader.js")
|
||||||
const api = require("./src/libpoketube/libpoketube-core.js");
|
const { IsJsonString, convert, getFirstLine, capitalizeFirstLetter, turntomins } = require("./src/libpoketube/ptutils/libpt-coreutils.js");
|
||||||
|
|
||||||
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
|
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
|
||||||
|
|
||||||
|
@ -41,9 +41,6 @@ var useragent = require("express-useragent");
|
||||||
// hash
|
// hash
|
||||||
const sha384 = require("js-sha512").sha384;
|
const sha384 = require("js-sha512").sha384;
|
||||||
|
|
||||||
const musicInfo = require("music-info");
|
|
||||||
const wiki = require("wikipedia");
|
|
||||||
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var https = require("https");
|
var https = require("https");
|
||||||
|
|
||||||
|
@ -86,49 +83,6 @@ const config = {
|
||||||
t_url: "https://t.poketube.fun/", // def matomo url
|
t_url: "https://t.poketube.fun/", // def matomo url
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////// FUNCTIONS /////////////
|
|
||||||
|
|
||||||
function IsJsonString(str) {
|
|
||||||
try {
|
|
||||||
JSON.parse(str);
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function convert(value) {
|
|
||||||
return new Intl.NumberFormat("en-GB", {
|
|
||||||
notation: "compact",
|
|
||||||
}).format(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFirstLine(text) {
|
|
||||||
var index = text.indexOf("<br> ");
|
|
||||||
if (index === -1) index = undefined;
|
|
||||||
return text.substring(0, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
function capitalizeFirstLetter(string) {
|
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function turntomins(time) {
|
|
||||||
var minutes = Math.floor(time / 60);
|
|
||||||
|
|
||||||
var seconds = time - minutes * 60;
|
|
||||||
|
|
||||||
function str_pad_left(string, pad, length) {
|
|
||||||
return (new Array(length + 1).join(pad) + string).slice(-length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var finalTime =
|
|
||||||
str_pad_left(minutes, "0", 2) + ":" + str_pad_left(seconds, "0", 2);
|
|
||||||
|
|
||||||
return finalTime;
|
|
||||||
}
|
|
||||||
/////////////////////////////////
|
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
|
@ -195,7 +149,7 @@ app.get("/watch", async function (req, res) {
|
||||||
const jj = await info.text();
|
const jj = await info.text();
|
||||||
const ip = JSON.parse(jj);
|
const ip = JSON.parse(jj);
|
||||||
|
|
||||||
api.video(v).then((data) => {
|
core.video(v).then((data) => {
|
||||||
const k = data.video;
|
const k = data.video;
|
||||||
const json = data.json;
|
const json = data.json;
|
||||||
const engagement = data.engagement;
|
const engagement = data.engagement;
|
||||||
|
@ -204,7 +158,7 @@ app.get("/watch", async function (req, res) {
|
||||||
|
|
||||||
if (!data.comments) inv_comments = "Disabled";
|
if (!data.comments) inv_comments = "Disabled";
|
||||||
|
|
||||||
if (!api.video(v).b) {
|
if (!core.video(v).b) {
|
||||||
var nnn = "";
|
var nnn = "";
|
||||||
var badges = "";
|
var badges = "";
|
||||||
var comments = "";
|
var comments = "";
|
||||||
|
@ -529,8 +483,6 @@ app.get("/js/:id", (req, res) => {
|
||||||
res.sendFile(__dirname + `/js/${req.params.id}`);
|
res.sendFile(__dirname + `/js/${req.params.id}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////// API /////////////
|
///////////// API /////////////
|
||||||
|
|
||||||
app.get("/embed/:v", async function (req, res) {
|
app.get("/embed/:v", async function (req, res) {
|
||||||
|
@ -624,20 +576,16 @@ app.get("/api/redirect", async (req, res) => {
|
||||||
res.redirect(red_url);
|
res.redirect(red_url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get("/api/v1/:endpoint/:id", async (req, res) => {
|
app.get("/api/v1/:endpoint/:id", async (req, res) => {
|
||||||
|
var inv_api_fetch = await fetch(
|
||||||
var inv_api_fetch = await fetch(`${config.invapi}/${req.params.endpoint}/${req.params.id}`).then((res) =>
|
`${config.invapi}/${req.params.endpoint}/${req.params.id}`
|
||||||
res.text()
|
).then((res) => res.text());
|
||||||
);
|
|
||||||
|
|
||||||
var inv_api_fetch = await JSON.parse(inv_api_fetch);
|
var inv_api_fetch = await JSON.parse(inv_api_fetch);
|
||||||
|
|
||||||
res.send(inv_api_fetch)
|
res.send(inv_api_fetch);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get("/api/opensearch", async (req, res) => {
|
app.get("/api/opensearch", async (req, res) => {
|
||||||
res.sendFile(__dirname + `/opensearch.xml`);
|
res.sendFile(__dirname + `/opensearch.xml`);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue