mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-14 05:48:57 +01:00
add im feeling lucky :3
This commit is contained in:
parent
290597aff9
commit
88447d0cb6
1 changed files with 63 additions and 14 deletions
|
@ -52,7 +52,7 @@ const ChannelTabs = {
|
||||||
streams: "c3RyZWFtcw==", // or "live"
|
streams: "c3RyZWFtcw==", // or "live"
|
||||||
channels: "Y2hhbm5lbHM=",
|
channels: "Y2hhbm5lbHM=",
|
||||||
store: "c3RvcmU=",
|
store: "c3RvcmU=",
|
||||||
released:"cmVsZWFzZWQ="
|
released: "cmVsZWFzZWQ=",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function (app, config, renderTemplate) {
|
module.exports = function (app, config, renderTemplate) {
|
||||||
|
@ -84,7 +84,6 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
res.json(ChannelTabs);
|
res.json(ChannelTabs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get("/search", async (req, res) => {
|
app.get("/search", async (req, res) => {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
const tab = req.query.tab;
|
const tab = req.query.tab;
|
||||||
|
@ -132,9 +131,13 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
try {
|
try {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
const xmlData = await fetch(`https://invid-api.poketube.fun/api/v1/search?q=${encodeURIComponent(
|
const xmlData = await fetch(
|
||||||
|
`https://invid-api.poketube.fun/api/v1/search?q=${encodeURIComponent(
|
||||||
query
|
query
|
||||||
)}&page=${encodeURIComponent(continuation)}&date=${date}&type=${type}&duration=${duration}&sort=${sort}&hl=en+gb`)
|
)}&page=${encodeURIComponent(
|
||||||
|
continuation
|
||||||
|
)}&date=${date}&type=${type}&duration=${duration}&sort=${sort}&hl=en+gb`
|
||||||
|
)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((txt) => getJson(txt));
|
.then((txt) => getJson(txt));
|
||||||
|
|
||||||
|
@ -159,12 +162,45 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/im-feeling-lucky", function (req, res) {
|
||||||
|
const query = req.query.query;
|
||||||
|
|
||||||
|
const search = require("google-it");
|
||||||
|
|
||||||
|
const getRandomLinkAndRedirect = (query, res) => {
|
||||||
|
search({ query: `${query}` }).then((results) => {
|
||||||
|
// Check if there are any results
|
||||||
|
if (results.length > 0) {
|
||||||
|
// Get a random index
|
||||||
|
const randomIndex = Math.floor(Math.random() * results.length);
|
||||||
|
|
||||||
|
// Get the random result object
|
||||||
|
const randomResult = results[randomIndex];
|
||||||
|
|
||||||
|
// Get the link from the random result
|
||||||
|
const randomLink = randomResult.link;
|
||||||
|
|
||||||
|
// Redirect to the random link
|
||||||
|
res.redirect(randomLink);
|
||||||
|
} else {
|
||||||
|
// Handle case when no results are found
|
||||||
|
res.send("No results found.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
getRandomLinkAndRedirect(query, res);
|
||||||
|
});
|
||||||
|
|
||||||
app.get("/web", async (req, res) => {
|
app.get("/web", async (req, res) => {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
const tab = req.query.tab;
|
const tab = req.query.tab;
|
||||||
|
|
||||||
const search = require("google-it");
|
const search = require("google-it");
|
||||||
|
|
||||||
|
if (req.query.lucky === 'true') {
|
||||||
|
res.redirect('/im-feeling-lucky?query=' + query)
|
||||||
|
}
|
||||||
var uaos = req.useragent.os;
|
var uaos = req.useragent.os;
|
||||||
var IsOldWindows;
|
var IsOldWindows;
|
||||||
|
|
||||||
|
@ -279,6 +315,18 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
getChannelData(channelINVUrl),
|
getChannelData(channelINVUrl),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
function getThumbnailUrl(video) {
|
||||||
|
const maxresDefaultThumbnail = video.videoThumbnails.find(
|
||||||
|
(thumbnail) => thumbnail.quality === "maxresdefault"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (maxresDefaultThumbnail) {
|
||||||
|
return `https://vid.puffyan.us/vi/${video.videoId}/maxresdefault.jpg`;
|
||||||
|
} else {
|
||||||
|
return `https://vid.puffyan.us/vi/${video.videoId}/hqdefault.jpg`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cache[ID] = {
|
cache[ID] = {
|
||||||
result: {
|
result: {
|
||||||
tj,
|
tj,
|
||||||
|
@ -317,6 +365,7 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
turntomins,
|
turntomins,
|
||||||
media_proxy_url: config.media_proxy,
|
media_proxy_url: config.media_proxy,
|
||||||
dnoreplace,
|
dnoreplace,
|
||||||
|
getThumbnailUrl,
|
||||||
continuation,
|
continuation,
|
||||||
wiki: "",
|
wiki: "",
|
||||||
getFirstLine,
|
getFirstLine,
|
||||||
|
|
Loading…
Reference in a new issue