Spaces:
Paused
Paused
Update lib/skrep.js
Browse files- lib/skrep.js +68 -63
lib/skrep.js
CHANGED
|
@@ -6,61 +6,57 @@ const { exec } = require("child_process");
|
|
| 6 |
|
| 7 |
async function ttt(link) {
|
| 8 |
try {
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
{ url: data.data.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
const slideResult = await createSlideshow(outputDir, videoPath, audioPath);
|
| 55 |
-
if (slideResult) {
|
| 56 |
-
res.video.push({ resolusi: "Slide", url: `https://beta.wzblueline.xyz/cdn/${FNvd}` });
|
| 57 |
-
}
|
| 58 |
}
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
}
|
| 65 |
|
| 66 |
async function downloadAudio(audioUrl, outputFile) {
|
|
@@ -101,18 +97,23 @@ async function downloadImages(imageUrls, outputDir) {
|
|
| 101 |
|
| 102 |
async function getAudioDuration(audioFile) {
|
| 103 |
return new Promise((resolve, reject) => {
|
| 104 |
-
exec(
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
| 109 |
-
|
| 110 |
-
});
|
| 111 |
});
|
| 112 |
}
|
| 113 |
|
| 114 |
async function createSlideshow(imagesDir, outputVideo, audioFile) {
|
| 115 |
-
const imageFiles = fs
|
|
|
|
|
|
|
| 116 |
const totalImages = imageFiles.length;
|
| 117 |
|
| 118 |
if (totalImages === 0) {
|
|
@@ -121,9 +122,14 @@ async function createSlideshow(imagesDir, outputVideo, audioFile) {
|
|
| 121 |
}
|
| 122 |
|
| 123 |
try {
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
const frameDuration = audioDuration / totalImages;
|
| 126 |
-
const tempDirv = `./
|
| 127 |
console.log(`π Durasi audio: ${audioDuration}s`);
|
| 128 |
console.log(`πΌ Durasi per gambar: ${frameDuration}s`);
|
| 129 |
|
|
@@ -149,7 +155,6 @@ async function createSlideshow(imagesDir, outputVideo, audioFile) {
|
|
| 149 |
}
|
| 150 |
|
| 151 |
console.log("β
Video dengan audio selesai dibuat.");
|
| 152 |
-
|
| 153 |
console.log("π§Ή Folder gambar sementara dihapus.");
|
| 154 |
resolve(outputVideo); // β
Return path video hasil!
|
| 155 |
});
|
|
|
|
| 6 |
|
| 7 |
async function ttt(link) {
|
| 8 |
try {
|
| 9 |
+
const form = new FormData();
|
| 10 |
+
form.append("url", link);
|
| 11 |
+
form.append("count", "12");
|
| 12 |
+
form.append("cursor", "0");
|
| 13 |
+
form.append("web", "1");
|
| 14 |
+
form.append("hd", "1");
|
| 15 |
+
|
| 16 |
+
const { data } = await axios.post("https://www.tikwm.com/api/", form);
|
| 17 |
+
|
| 18 |
+
if (data.code === 0 && data.msg === "success") {
|
| 19 |
+
const baseUrl = "https://www.tikwm.com";
|
| 20 |
+
data.data.cover = baseUrl + data.data.cover;
|
| 21 |
+
data.data.play = baseUrl + data.data.play;
|
| 22 |
+
data.data.wmplay = baseUrl + data.data.wmplay;
|
| 23 |
+
data.data.hdplay = baseUrl + data.data.hdplay;
|
| 24 |
+
data.data.music = baseUrl + data.data.music;
|
| 25 |
+
data.data.author.avatar = baseUrl + data.data.author.avatar;
|
| 26 |
+
}
|
| 27 |
|
| 28 |
+
const res = {
|
| 29 |
+
status: 200,
|
| 30 |
+
type: "tiktok",
|
| 31 |
+
title: data.data?.title || null,
|
| 32 |
+
desc: null,
|
| 33 |
+
thumbnail: data.data.cover,
|
| 34 |
+
video: [{ url: data.data.hdplay }, { url: data.data.play }],
|
| 35 |
+
music: [{ url: data.data.music }],
|
| 36 |
+
image: data.data.images,
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
if (res.images) {
|
| 40 |
+
const outputDir = "./tmp";
|
| 41 |
+
await downloadImages(res.images, outputDir);
|
| 42 |
+
|
| 43 |
+
const FNvd = tt_video_${Date.now()}.mp4;
|
| 44 |
+
const FNad = tt_audio_${Date.now()}.mp3;
|
| 45 |
+
const videoPath = ${outputDir}/${FNvd};
|
| 46 |
+
const audioPath = ${outputDir}/${FNad};
|
| 47 |
+
|
| 48 |
+
// β
Unduh audio sebelum dipakai
|
| 49 |
+
await downloadAudio(res.music[0].url, audioPath);
|
| 50 |
+
|
| 51 |
+
const slideResult = await createSlideshow(outputDir, videoPath, audioPath);
|
| 52 |
+
if (slideResult) {
|
| 53 |
+
res.video.push({ resolusi: "Slideshow", url: `https://fullperr-hutatools.hf.space/tmp/${FNvd}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
+
}
|
| 56 |
+
return res;
|
| 57 |
+
} catch (e) {
|
| 58 |
+
return { status: 500, message: e.message };
|
| 59 |
+
}
|
| 60 |
}
|
| 61 |
|
| 62 |
async function downloadAudio(audioUrl, outputFile) {
|
|
|
|
| 97 |
|
| 98 |
async function getAudioDuration(audioFile) {
|
| 99 |
return new Promise((resolve, reject) => {
|
| 100 |
+
exec(
|
| 101 |
+
`ffprobe -i ${audioFile} -show_entries format=duration -v quiet -of csv="p=0"`,
|
| 102 |
+
(error, stdout) => {
|
| 103 |
+
if (error) {
|
| 104 |
+
reject("β Gagal mendapatkan durasi audio.");
|
| 105 |
+
return;
|
| 106 |
+
}
|
| 107 |
+
resolve(parseFloat(stdout.trim()));
|
| 108 |
}
|
| 109 |
+
);
|
|
|
|
| 110 |
});
|
| 111 |
}
|
| 112 |
|
| 113 |
async function createSlideshow(imagesDir, outputVideo, audioFile) {
|
| 114 |
+
const imageFiles = fs
|
| 115 |
+
.readdirSync(imagesDir)
|
| 116 |
+
.filter((file) => file.endsWith(".jpg"));
|
| 117 |
const totalImages = imageFiles.length;
|
| 118 |
|
| 119 |
if (totalImages === 0) {
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
try {
|
| 125 |
+
let audioDuration = await getAudioDuration(audioFile);
|
| 126 |
+
if (audioDuration > 25) {
|
| 127 |
+
console.log("β³ Audio lebih dari 25 detik, membatasi ke 25 detik.");
|
| 128 |
+
audioDuration = 25;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
const frameDuration = audioDuration / totalImages;
|
| 132 |
+
const tempDirv = `./tmp/temp_video_${Date.now()}.mp4`;
|
| 133 |
console.log(`π Durasi audio: ${audioDuration}s`);
|
| 134 |
console.log(`πΌ Durasi per gambar: ${frameDuration}s`);
|
| 135 |
|
|
|
|
| 155 |
}
|
| 156 |
|
| 157 |
console.log("β
Video dengan audio selesai dibuat.");
|
|
|
|
| 158 |
console.log("π§Ή Folder gambar sementara dihapus.");
|
| 159 |
resolve(outputVideo); // β
Return path video hasil!
|
| 160 |
});
|