save filename as a hash
This commit is contained in:
parent
8785b14464
commit
745b92660c
1 changed files with 6 additions and 5 deletions
11
index.ts
11
index.ts
|
|
@ -4,7 +4,6 @@ const joypixels = require("emoji-toolkit");
|
||||||
import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, readFile } from 'fs'
|
import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync, readFile } from 'fs'
|
||||||
import { $ } from 'bun';
|
import { $ } from 'bun';
|
||||||
import ytSearch from 'yt-search';
|
import ytSearch from 'yt-search';
|
||||||
|
|
||||||
let ytdlpPath = "yt-dlp"
|
let ytdlpPath = "yt-dlp"
|
||||||
if(existsSync("./yt-dlp")) {
|
if(existsSync("./yt-dlp")) {
|
||||||
ytdlpPath = "./yt-dlp"
|
ytdlpPath = "./yt-dlp"
|
||||||
|
|
@ -24,20 +23,22 @@ app.post("/youtube", async (c) => {
|
||||||
let title = body.title;
|
let title = body.title;
|
||||||
let artist = body.artist;
|
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 searchResult = await ytSearch(`${artist} ${title}`);
|
||||||
const video = searchResult.videos[0];
|
const video = searchResult.videos[0];
|
||||||
if (!video) throw new Error("No video found");
|
if (!video) throw new Error("No video found");
|
||||||
console.log(video)
|
console.log(video)
|
||||||
await $`${ytdlpPath} --audio-format opus -x ${video.url} -o test`;
|
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")
|
rmSync("test.opus")
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.body(readFileSync(`cache/${title} - ${artist}.dfpwm`), {
|
return c.body(readFileSync(filename), {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'audio/vnd.dfpwm',
|
'Content-Type': 'audio/vnd.dfpwm',
|
||||||
'Content-Disposition': `attachment; filename="${title} - ${artist}.dfpwm"`,
|
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue