From 745b92660c43886227bf3b68e1586fc468254b0a Mon Sep 17 00:00:00 2001 From: yourfriendoss Date: Sat, 12 Jul 2025 11:37:52 +0300 Subject: [PATCH] save filename as a hash --- index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 14db130..490ec32 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,6 @@ const joypixels = require("emoji-toolkit"); import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, readFile } from 'fs' import { $ } from 'bun'; import ytSearch from 'yt-search'; - let ytdlpPath = "yt-dlp" if(existsSync("./yt-dlp")) { ytdlpPath = "./yt-dlp" @@ -24,20 +23,22 @@ app.post("/youtube", async (c) => { let title = body.title; let artist = body.artist; - if(!existsSync("cache/" + title + " - " + artist + ".dfpwm")) { + let filename = "cache/"+Bun.hash(title+"-"+artist)+".dfpwm" + + if(!existsSync(filename)) { const searchResult = await ytSearch(`${artist} ${title}`); const video = searchResult.videos[0]; if (!video) throw new Error("No video found"); console.log(video) await $`${ytdlpPath} --audio-format opus -x ${video.url} -o test`; - await $`ffmpeg -i test.opus -af "highpass=f=60, lowpass=f=15000, dynaudnorm" -ar 48000 -ac 1 -f dfpwm "cache/${title} - ${artist}.dfpwm"`; + await $`ffmpeg -i test.opus -af "highpass=f=60, lowpass=f=15000, dynaudnorm" -ar 48000 -ac 1 -f dfpwm "${filename}"`; rmSync("test.opus") } - return c.body(readFileSync(`cache/${title} - ${artist}.dfpwm`), { + return c.body(readFileSync(filename), { headers: { 'Content-Type': 'audio/vnd.dfpwm', - 'Content-Disposition': `attachment; filename="${title} - ${artist}.dfpwm"`, + 'Content-Disposition': `attachment; filename="${filename}"`, }, });