Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -155,6 +155,7 @@ async function getAudioMP3Url(videoUrl) {
|
|
| 155 |
const audioFormat = ytdl.chooseFormat(info.formats, { filter: 'audioonly', quality: 'highestaudio' });
|
| 156 |
const path_audio = path.join(tempDir, generateRandomName(10) + '.mp3');
|
| 157 |
let uploadResult;
|
|
|
|
| 158 |
|
| 159 |
await new Promise((resolve, reject) => {
|
| 160 |
ffmpeg()
|
|
@@ -164,15 +165,19 @@ async function getAudioMP3Url(videoUrl) {
|
|
| 164 |
.outputOptions('-ab 128k')
|
| 165 |
.outputOptions('-ar 44100')
|
| 166 |
.on('end', async () => {
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
})
|
| 177 |
.on('error', (err) => {
|
| 178 |
console.error('FFmpeg conversion error:', err);
|
|
@@ -185,7 +190,7 @@ async function getAudioMP3Url(videoUrl) {
|
|
| 185 |
status: 200,
|
| 186 |
title: info.videoDetails.title,
|
| 187 |
result: {
|
| 188 |
-
url_path:
|
| 189 |
path: convert.path
|
| 190 |
}
|
| 191 |
};
|
|
@@ -246,4 +251,4 @@ pingEvery5Hours();
|
|
| 246 |
|
| 247 |
app.listen(PORT, () => {
|
| 248 |
console.log(`Server is running on port ${PORT}`);
|
| 249 |
-
});
|
|
|
|
| 155 |
const audioFormat = ytdl.chooseFormat(info.formats, { filter: 'audioonly', quality: 'highestaudio' });
|
| 156 |
const path_audio = path.join(tempDir, generateRandomName(10) + '.mp3');
|
| 157 |
let uploadResult;
|
| 158 |
+
let convert;
|
| 159 |
|
| 160 |
await new Promise((resolve, reject) => {
|
| 161 |
ffmpeg()
|
|
|
|
| 165 |
.outputOptions('-ab 128k')
|
| 166 |
.outputOptions('-ar 44100')
|
| 167 |
.on('end', async () => {
|
| 168 |
+
try {
|
| 169 |
+
const buffer = fs.readFileSync(path_audio);
|
| 170 |
+
const id_video = await GetId(videoUrl);
|
| 171 |
+
const hd_thumbnail = await getHDThumbnailUrl(id_video);
|
| 172 |
+
convert = await addAudioTags(buffer, info.videoDetails.title, info.videoDetails.ownerChannelName, 2024, hd_thumbnail);
|
| 173 |
+
const buffer2 = fs.readFileSync(convert.path);
|
| 174 |
+
|
| 175 |
+
fs.unlinkSync(path_audio);
|
| 176 |
+
|
| 177 |
+
resolve();
|
| 178 |
+
} catch (error) {
|
| 179 |
+
reject(error);
|
| 180 |
+
}
|
| 181 |
})
|
| 182 |
.on('error', (err) => {
|
| 183 |
console.error('FFmpeg conversion error:', err);
|
|
|
|
| 190 |
status: 200,
|
| 191 |
title: info.videoDetails.title,
|
| 192 |
result: {
|
| 193 |
+
url_path: `https://${process.env.SPACE_HOST}/temp/${path.basename(convert.path)}`,
|
| 194 |
path: convert.path
|
| 195 |
}
|
| 196 |
};
|
|
|
|
| 251 |
|
| 252 |
app.listen(PORT, () => {
|
| 253 |
console.log(`Server is running on port ${PORT}`);
|
| 254 |
+
});
|