save filename as a hash

This commit is contained in:
Soph :3 2025-07-12 11:37:52 +03:00
parent 8785b14464
commit 745b92660c

View file

@ -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}"`,
},
});