make some of the code prettier

This commit is contained in:
murdle 2026-02-17 16:31:06 +02:00
parent f5130a4e37
commit eb990070ed
7 changed files with 13 additions and 16 deletions

View File

@ -10,14 +10,17 @@ playback.get(
zValidator("param", VideoFindSchema), zValidator("param", VideoFindSchema),
async (c) => { async (c) => {
const { id } = c.req.valid("param"); const { id } = c.req.valid("param");
const data = await innertube.getStreamingData(id, { const data = await innertube.getStreamingData(id, {
type: "video+audio", type: "video+audio",
quality: "best", quality: "best",
format: "mp4", format: "mp4",
client: "TV", client: "TV",
}); });
if (!data.url) return c.status(400);
return c.redirect(data.url, 307); return data.url
? c.redirect(data.url, 307)
: c.status(400);
} }
) )

View File

@ -3,7 +3,7 @@ import innertube from "../lib/innertube.js";
import { zValidator } from "@hono/zod-validator"; import { zValidator } from "@hono/zod-validator";
import { VideoSearchSchema } from "../models/VideoSearchSchema.js"; import { VideoSearchSchema } from "../models/VideoSearchSchema.js";
import search from "../templates/search.js"; import search from "../templates/search.js";
import { parseVideos } from "../lib/utils/video.js"; import { parseVideo } from "../lib/utils/video.js";
import { YTNodes } from "youtubei.js"; import { YTNodes } from "youtubei.js";
const video = new Hono(); const video = new Hono();
@ -30,27 +30,25 @@ video.get(
let currentPage = 1; let currentPage = 1;
while (currentPage <= page) { while (currentPage <= page && searchQuery.has_continuation) {
const videos = searchQuery.results.filter( const videos = searchQuery.results.filter(
(node): node is YTNodes.Video => node.type === "Video" (node): node is YTNodes.Video => node.type === "Video"
); );
allVideos.push(...videos); allVideos.push(...videos);
if (!searchQuery.has_continuation) break;
if (currentPage === page) break; if (currentPage === page) break;
searchQuery = await searchQuery.getContinuation(); searchQuery = await searchQuery.getContinuation();
currentPage++; currentPage++;
} }
// * build next page URL // * build next page url
const nextUrl = new URL(c.req.url); const nextUrl = new URL(c.req.url);
nextUrl.searchParams.set("start-index", String(page + 1)); nextUrl.searchParams.set("start-index", String(page + 1));
return c.html( return c.html(
search( search(
parseVideos(allVideos), allVideos.map(video => parseVideo(video)),
searchQuery.has_continuation ? nextUrl.toString() : "" searchQuery.has_continuation ? nextUrl.toString() : ""
) )
); );

View File

@ -1,9 +1,9 @@
import "dotenv/config"
import { Hono } from "hono" import { Hono } from "hono"
import { logger } from "hono/logger" import { logger } from "hono/logger"
import { serve } from "@hono/node-server" import { serve } from "@hono/node-server"
import { serveStatic } from "@hono/node-server/serve-static" import { serveStatic } from "@hono/node-server/serve-static"
import { config } from "./lib/config.js" import { config } from "./lib/config.js"
import "dotenv/config"
import video from "./api/video.js" import video from "./api/video.js"
import playback from "./api/playback.js" import playback from "./api/playback.js"

View File

@ -2,10 +2,9 @@ import { z } from "zod";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
const cookiesPath = path.resolve(process.cwd(), "cookies.txt");
let cookies: string | null = null; let cookies: string | null = null;
const cookiesPath = path.resolve(process.cwd(), "cookies.txt");
if (fs.existsSync(cookiesPath)) { if (fs.existsSync(cookiesPath)) {
cookies = fs.readFileSync(cookiesPath, "utf8").trim(); cookies = fs.readFileSync(cookiesPath, "utf8").trim();
} }

View File

@ -20,4 +20,5 @@ const innertube = await Innertube.create({
client_type: ClientType.WEB, client_type: ClientType.WEB,
...(config.COOKIES ? { cookie: config.COOKIES } : {}) ...(config.COOKIES ? { cookie: config.COOKIES } : {})
}); });
export default innertube export default innertube

View File

@ -17,8 +17,8 @@ export function parseFeedVideo(
// * extract author info // * extract author info
const authorPart = metadataRows[0]?.metadata_parts?.[0]?.text; const authorPart = metadataRows[0]?.metadata_parts?.[0]?.text;
const authorName = authorPart?.text ?? "";
const authorId = authorPart?.endpoint?.payload?.browseId ?? ""; const authorId = authorPart?.endpoint?.payload?.browseId ?? "";
const authorName = authorPart?.text ?? "";
// * extract view count and published date // * extract view count and published date
const viewText = metadataRows[1]?.metadata_parts?.[0]?.text?.text ?? "0"; const viewText = metadataRows[1]?.metadata_parts?.[0]?.text?.text ?? "0";

View File

@ -13,10 +13,6 @@ export interface Video {
created: string; created: string;
} }
export function parseVideos(videos: YTNodes.Video[]): Video[] {
return videos.map(video => parseVideo(video));
}
export function parseVideo(video: YTNodes.Video): Video { export function parseVideo(video: YTNodes.Video): Video {
const authorId = video.author?.id && video.author.id !== "N/A" const authorId = video.author?.id && video.author.id !== "N/A"
? video.author.id ? video.author.id