fullpwerr commited on
Commit
bf41958
Β·
verified Β·
1 Parent(s): 1e7520b

Update lib/skrep.js

Browse files
Files changed (1) hide show
  1. 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
- 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: [
35
- { url: data.data.hdplay },
36
- { url: data.data.play },
37
- ],
38
- music: [{ url: data.data.music }],
39
- image: data.data.images,
40
- };
41
-
42
- /*if (res.images) {
43
- const outputDir = "./cdn";
44
- await downloadImages(res.images, outputDir);
45
-
46
- const FNvd = `tt_video_${Date.now()}.mp4`;
47
- const FNad = `tt_audio_${Date.now()}.mp3`;
48
- const videoPath = `${outputDir}/${FNvd}`;
49
- const audioPath = `${outputDir}/${FNad}`;
50
-
51
- // βœ… Unduh audio sebelum dipakai
52
- await downloadAudio(res.music[0].url, audioPath);
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
- return res;
61
- } catch (e) {
62
- return { status: 500, message: e.message}
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(`ffprobe -i ${audioFile} -show_entries format=duration -v quiet -of csv="p=0"`, (error, stdout) => {
105
- if (error) {
106
- reject("❌ Gagal mendapatkan durasi audio.");
107
- return;
 
 
 
 
108
  }
109
- resolve(parseFloat(stdout.trim()));
110
- });
111
  });
112
  }
113
 
114
  async function createSlideshow(imagesDir, outputVideo, audioFile) {
115
- const imageFiles = fs.readdirSync(imagesDir).filter(file => file.endsWith(".jpg"));
 
 
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
- const audioDuration = await getAudioDuration(audioFile);
 
 
 
 
 
125
  const frameDuration = audioDuration / totalImages;
126
- const tempDirv = `./cdn/temp_video_${Date.now()}.mp4`
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
  });