frostpv 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +66 -264
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -4,11 +4,10 @@ const path = require("path");
4
4
  const os = require("os");
5
5
  const FormData = require("form-data");
6
6
  const crypto = require("crypto");
7
- const { igdl, ttdl, fbdown, mediafire, capcut, youtube, gdrive, pinterest, twitter } = require("btch-downloader");
7
+ const { igdl, ttdl, fbdown, mediafire, capcut, gdrive, pinterest, twitter } = require("btch-downloader");
8
8
  const { TwitterDL } = require("twitter-downloader");
9
9
  const btch = require("btch-downloader");
10
10
  const btchOld = require("btch-downloader-old");
11
- const ytdl = require("@distube/ytdl-core");
12
11
 
13
12
 
14
13
  const Tiktok = require("@tobyg74/tiktok-api-dl");
@@ -26,7 +25,7 @@ const TEMP_DIR = path.join(os.tmpdir(), "downloader-dl-bot");
26
25
  try { fs.mkdirSync(TEMP_DIR, { recursive: true }); } catch (_) { }
27
26
  const OUTPUT_RETENTION_MIN = Number(process.env.OUTPUT_RETENTION_MIN || 5);
28
27
 
29
- const GOFILE_API = "Vs4e2PL8n65ExPz6wgDlqSY8kcEBRrzN";
28
+ const GOFILE_API = "1eNR6qXgKMn6GGl4oRcfOlQnxrgSrNSL";
30
29
  const GOFILE_UPLOAD_URL = "https://upload.gofile.io/uploadfile";
31
30
  const SIZE_LIMIT_MB = 10;
32
31
  const SIZE_LIMIT_BYTES = SIZE_LIMIT_MB * 1024 * 1024;
@@ -44,10 +43,6 @@ const videoPlatforms = [
44
43
  "https://fb.watch",
45
44
  "https://www.fb.watch",
46
45
  "https://fb.com",
47
- "https://www.youtube.com",
48
- "https://youtube.com",
49
- "https://www.youtu.be",
50
- "https://youtu.be",
51
46
  "https://www.fb.com",
52
47
  "https://web.facebook.com",
53
48
  "https://www.mediafire.com",
@@ -89,7 +84,6 @@ const defaultConfig = {
89
84
  autocrop: false,
90
85
  limitSizeMB: null,
91
86
  rotation: null,
92
- YTBmaxduration: 1200,
93
87
  outputFormat: null,
94
88
  };
95
89
 
@@ -184,13 +178,19 @@ async function uploadToGoFileIfNeeded(filePath) {
184
178
  return { type: "local", value: filePath };
185
179
  }
186
180
 
181
+ const uploadUrl = "https://upload.gofile.io/uploadfile";
182
+
187
183
  const form = new FormData();
188
- form.append("file", fs.createReadStream(filePath), path.basename(filePath));
184
+ form.append("file", fs.createReadStream(filePath), {
185
+ filename: path.basename(filePath),
186
+ knownLength: fileSizeInBytes
187
+ });
189
188
 
190
- const response = await axios.post(GOFILE_UPLOAD_URL, form, {
189
+ const response = await axios.post(uploadUrl, form, {
191
190
  headers: {
192
191
  ...form.getHeaders(),
193
192
  "Authorization": `Bearer ${GOFILE_API}`,
193
+ "Content-Length": form.getLengthSync()
194
194
  },
195
195
  maxContentLength: Infinity,
196
196
  maxBodyLength: Infinity
@@ -199,6 +199,7 @@ async function uploadToGoFileIfNeeded(filePath) {
199
199
  if (response.data && response.data.status === "ok") {
200
200
  const downloadLink = response.data.data?.downloadPage;
201
201
  if (downloadLink) {
202
+ await safeUnlinkWithRetry(filePath);
202
203
  return { type: "gofile", value: downloadLink };
203
204
  } else {
204
205
  throw new Error("GoFile API response OK, but download link not found.");
@@ -277,7 +278,7 @@ function getPlatformType(url) {
277
278
  if (lowerUrl.includes("facebook.com") || lowerUrl.includes("fb.watch") || lowerUrl.includes("fb.com")) return "facebook";
278
279
  if (lowerUrl.includes("mediafire.com")) return "mediafire";
279
280
  if (lowerUrl.includes("x.com") || lowerUrl.includes("twitter.com")) return "twitter";
280
- if (lowerUrl.includes("youtube.com") || lowerUrl.includes("youtu.be") || lowerUrl.includes("www.youtube.com")) return "youtube";
281
+ if (lowerUrl.includes("youtube.com") || lowerUrl.includes("you112t12u.be") || lowerUrl.includes("m.y11outu314be.com")) return "youtu1354be";
281
282
 
282
283
  return "unknown";
283
284
  }
@@ -755,80 +756,61 @@ const MediaDownloader = async (url, options = {}) => {
755
756
  throw new Error(`URL not supported: ${blacklisted.reason}`);
756
757
  }
757
758
 
758
- await deleteTempVideos(); // Clean up previous temp files
759
-
760
- if (url.includes('youtube') || url.includes('youtu.be')) {
761
- let cookies = options.YTBcookies || (options.YTBcookie ? [options.YTBcookie] : []);
762
-
763
- // Automatically load external cookies if none provided
764
- if (cookies.length === 0) {
765
- cookies = loadExternalCookies();
766
- }
767
-
768
- if (cookies.length === 0) {
769
- throw new Error("YouTube download requires a session. Please Provide a valid session in 'session_data.json'.");
770
- }
771
-
772
- // Determine if audio-only is requested
773
- const isAudioOnly = options.outputFormat === 'mp3' || options.downloadAudio === true || config.downloadAudio === true;
774
-
775
- const videofile = await downloadYoutubeVideo(url, config, cookies, config.YTBmaxduration, isAudioOnly);
776
- if (videofile) {
777
- const result = await uploadToGoFileIfNeeded(videofile);
778
- return result;
779
- } else {
780
- throw new Error("URL not supported. Please provide a video URL from a valid platform.");
781
- }
759
+ // Verificar se o link está na lista de plataformas suportadas
760
+ if (!isVideoLink(url)) {
761
+ throw new Error("This URL is not from a supported platform. Supported platforms: Instagram, X(Twitter), TikTok, Facebook");
782
762
  }
783
763
 
784
- else if (url.includes("http")) {
785
- const blacklisted = blacklistLink(url);
786
- if (blacklisted) {
787
- throw new Error(`URL not supported: ${blacklisted.reason}`);
788
- }
764
+ // Verificar se é YouTube e lançar erro customizado
765
+ const platform = getPlatformType(url);
766
+ if (platform === "youtube") {
767
+ throw new Error("This URL is not from a supported platform. Supported platforms: Instagram, X(Twitter), TikTok, Facebook");
768
+ }
789
769
 
790
- // Verificar se o link está na lista de plataformas suportadas
791
- if (!isVideoLink(url)) {
792
- throw new Error("This URL is not from a supported platform. Supported platforms: Instagram, X(Twitter), TikTok, Facebook");
793
- }
770
+ await cleanupTempFiles(); // Clean up previous temp files
794
771
 
795
- let downloadedFilePath = null;
772
+ let downloadedFilePath = null;
796
773
 
774
+ try {
775
+ // Try primary download method
797
776
  try {
798
- // Try primary download method
799
- try {
800
- downloadedFilePath = await downloadSmartVideo(url, config);
801
- } catch (error) {
802
- const platform = getPlatformType(url);
777
+ downloadedFilePath = await downloadSmartVideo(url, config);
778
+ } catch (error) {
779
+ const platform = getPlatformType(url);
803
780
 
804
- try {
805
- const fallbackUrl = await tryFallbackDownload(url);
781
+ // YouTube doesn't use fallback method - it has its own specific implementation
782
+ if (platform === "youtube") {
783
+ throw new Error(`YouTube download failed: ${error.message}`);
784
+ }
806
785
 
807
- // Validate fallback URL
808
- const isValid = await validateVideoUrl(fallbackUrl, platform);
809
- if (!isValid) {
810
- throw new Error("Fallback URL validation failed");
811
- }
786
+ try {
787
+ const fallbackUrl = await tryFallbackDownload(url);
812
788
 
813
- downloadedFilePath = await downloadDirectVideo(fallbackUrl, config);
814
- } catch (fallbackError) {
815
- throw new Error(`Failed to download video with both methods: ${fallbackError.message}`);
789
+ // Validate fallback URL
790
+ const isValid = await validateVideoUrl(fallbackUrl, platform);
791
+ if (!isValid) {
792
+ throw new Error("Fallback URL validation failed");
816
793
  }
794
+
795
+ downloadedFilePath = await downloadDirectVideo(fallbackUrl, config);
796
+ } catch (fallbackError) {
797
+ throw new Error(`Failed to download video with both methods: ${fallbackError.message}`);
817
798
  }
799
+ }
818
800
 
819
- if (downloadedFilePath) {
820
- const result = await uploadToGoFileIfNeeded(downloadedFilePath);
821
- return result;
822
- } else {
823
- throw new Error("Failed to obtain downloaded file path.");
801
+ if (downloadedFilePath) {
802
+ if (config.noGofile) {
803
+ return { type: "local", value: downloadedFilePath };
824
804
  }
825
- } catch (error) {
826
- // Clean up any remaining temp files on error
827
- await cleanupTempFiles();
828
- throw new Error(`Error in downloader videos: ${error.message}`);
805
+ const result = await uploadToGoFileIfNeeded(downloadedFilePath);
806
+ return result;
807
+ } else {
808
+ throw new Error("Failed to obtain downloaded file path.");
829
809
  }
830
- } else {
831
- throw new Error("Please specify a video URL from Instagram, facebook or TikTok...");
810
+ } catch (error) {
811
+ // Clean up any remaining temp files on error
812
+ await cleanupTempFiles();
813
+ throw new Error(`Error in downloader videos: ${error.message}`);
832
814
  }
833
815
  };
834
816
 
@@ -1197,188 +1179,9 @@ async function rotateVideo(fileName, rotation) {
1197
1179
 
1198
1180
  // Function to extract URL from string
1199
1181
  function extractUrlFromString(text) {
1200
- const urlRegex = /(https?:\/\/[^\s]+)/g;
1182
+ const urlRegex = /(https?:\/\/[^\s]+)/;
1201
1183
  const match = text.match(urlRegex);
1202
- return match ? match[0] : text;
1203
- }
1204
-
1205
- async function downloadYoutubeVideo(url, config, cookies, YTBmaxduration, isAudioOnly = false) {
1206
- let lastError = null;
1207
-
1208
- for (let i = 0; i < Math.min(cookies.length, 6); i++) {
1209
- const currentCookie = cookies[i];
1210
- try {
1211
- const parsedCookies = parseCookies(currentCookie);
1212
-
1213
- if (parsedCookies.length === 0) {
1214
- continue;
1215
- }
1216
-
1217
- const agent = ytdl.createAgent(parsedCookies);
1218
- const info = await ytdl.getInfo(url, { agent });
1219
-
1220
- const durationSeconds = parseInt(info.videoDetails.lengthSeconds, 10);
1221
- if (durationSeconds > YTBmaxduration) {
1222
- throw new Error(`❌ The video is longer than ${YTBmaxduration} seconds. Aborting.`);
1223
- }
1224
-
1225
- let bestFormat;
1226
- if (isAudioOnly) {
1227
- // Filter for audio-only formats
1228
- const audioFormats = info.formats.filter(f => !f.hasVideo && f.hasAudio);
1229
- bestFormat = audioFormats.sort((a, b) => (b.audioBitrate || 0) - (a.audioBitrate || 0))[0];
1230
-
1231
- if (!bestFormat) {
1232
- // Fallback: any format with audio
1233
- bestFormat = info.formats.filter(f => f.hasAudio).sort((a, b) => (b.audioBitrate || 0) - (a.audioBitrate || 0))[0];
1234
- }
1235
- if (!bestFormat) {
1236
- throw new Error('❌ No suitable audio format found.');
1237
- }
1238
- } else {
1239
- // Filter for formats that have both audio and video (muxed)
1240
- // We prioritize higher quality but limit to 1080p if possible
1241
- let formats = info.formats.filter(format => {
1242
- return format.hasAudio && format.hasVideo && (!format.height || format.height <= 1080);
1243
- });
1244
-
1245
- if (formats.length === 0) {
1246
- // If no 1080p muxed formats, take any muxed format
1247
- formats = info.formats.filter(format => format.hasAudio && format.hasVideo);
1248
- }
1249
-
1250
- if (formats.length === 0) {
1251
- throw new Error('❌ No suitable video format found with both audio and video.');
1252
- }
1253
-
1254
- // Sort by resolution (height) descending to get best quality
1255
- bestFormat = formats.sort((a, b) => (b.height || 0) - (a.height || 0))[0];
1256
- }
1257
-
1258
- const ext = isAudioOnly ? 'mp3' : 'mp4';
1259
- // Create minimal unique file name in output dir
1260
- let fileName = path.join(OUTPUT_DIR, `v_${uuidv4().slice(0, 4)}.${ext}`);
1261
-
1262
- const videoStream = ytdl(url, {
1263
- format: bestFormat,
1264
- agent
1265
- });
1266
-
1267
- const videoWriter = fs.createWriteStream(fileName);
1268
- videoStream.pipe(videoWriter);
1269
-
1270
- return await new Promise((resolve, reject) => {
1271
- videoWriter.on('finish', async () => {
1272
- try {
1273
- let finalFilePath = fileName;
1274
- if (!isAudioOnly) {
1275
- finalFilePath = await processDownloadedFile(fileName, config, "youtube");
1276
- }
1277
- resolve(finalFilePath);
1278
- } catch (error) {
1279
- reject(error);
1280
- }
1281
- });
1282
- videoWriter.on('error', (error) => reject(error));
1283
- });
1284
-
1285
- } catch (error) {
1286
- console.error(`Attempt with cookie ${i + 1} failed: ${error.message}`);
1287
- lastError = error;
1288
- // If the error is about duration, don't retry with other cookies
1289
- if (error.message.includes('longer than')) {
1290
- throw error;
1291
- }
1292
- continue; // Try next cookie
1293
- }
1294
- }
1295
-
1296
- throw new Error(`An error occurred while downloading the YouTube video (all ${Math.min(cookies.length, 10)} cookies failed): ${lastError?.message}`);
1297
- }
1298
-
1299
- /**
1300
- * Automatically loads cookies from cookies.json if present
1301
- * @returns {Array} Array of cookie sets (one or more accounts)
1302
- */
1303
- function loadExternalCookies() {
1304
- const cookiesPath = path.join(process.cwd(), 'session_data.json');
1305
- if (!fs.existsSync(cookiesPath)) return [];
1306
-
1307
- try {
1308
- const fileContent = fs.readFileSync(cookiesPath, 'utf8');
1309
- const parsed = JSON.parse(fileContent);
1310
- if (!Array.isArray(parsed)) return [];
1311
-
1312
- // If it's an array of objects, it's ONE account.
1313
- // If it's an array of arrays, it's MULTIPLE accounts.
1314
- if (parsed.length > 0) {
1315
- if (Array.isArray(parsed[0])) {
1316
- // Multiple accounts: return them as strings for the rotation logic
1317
- return parsed.map(acc => JSON.stringify(acc));
1318
- } else {
1319
- // Single account: return the whole JSON as a string
1320
- return [fileContent];
1321
- }
1322
- }
1323
- } catch (e) {
1324
- console.error("Error loading external cookies:", e.message);
1325
- }
1326
- return [];
1327
- }
1328
-
1329
- /**
1330
- * Parses cookies in various formats (JSON, Netscape, or Header String)
1331
- * @param {string} cookieInput
1332
- * @returns {Array} Array of cookie objects
1333
- */
1334
- function parseCookies(cookieInput) {
1335
- if (!cookieInput) return [];
1336
-
1337
- const trimmedInput = cookieInput.trim();
1338
-
1339
- // 1. Try JSON (EditThisCookie export)
1340
- try {
1341
- const parsed = JSON.parse(trimmedInput);
1342
- if (Array.isArray(parsed)) return parsed;
1343
- if (typeof parsed === 'object') return [parsed];
1344
- } catch (e) { }
1345
-
1346
- // 2. Try Netscape format (tab-separated)
1347
- if (trimmedInput.includes('\t')) {
1348
- const lines = trimmedInput.split(/\r?\n/);
1349
- const cookies = [];
1350
- for (const line of lines) {
1351
- if (!line.trim() || line.startsWith('#')) continue;
1352
- const parts = line.split('\t');
1353
- if (parts.length >= 7) {
1354
- cookies.push({
1355
- domain: parts[0],
1356
- path: parts[2],
1357
- secure: parts[3].toUpperCase() === 'TRUE',
1358
- expirationDate: parseInt(parts[4]),
1359
- name: parts[5],
1360
- value: parts[6]
1361
- });
1362
- }
1363
- }
1364
- if (cookies.length > 0) return cookies;
1365
- }
1366
-
1367
- // 3. Fallback: Cookie header string (name=value; name2=value2)
1368
- return trimmedInput.split(';').map(v => v.split('=')).reduce((acc, v) => {
1369
- if (v.length >= 2) {
1370
- const name = v[0].trim();
1371
- const value = v.slice(1).join('=').trim();
1372
- if (name && value) {
1373
- acc.push({
1374
- name: name,
1375
- value: value,
1376
- domain: '.youtube.com'
1377
- });
1378
- }
1379
- }
1380
- return acc;
1381
- }, []);
1184
+ return match ? match[0] : null;
1382
1185
  }
1383
1186
 
1384
1187
  // Function to delete temporary videos
@@ -1386,7 +1189,7 @@ async function deleteTempVideos() {
1386
1189
  try {
1387
1190
  if (!fs.existsSync(TEMP_DIR)) return;
1388
1191
  const files = fs.readdirSync(TEMP_DIR);
1389
- const tempVideoFiles = files.filter(file => /^temp_video.*\.mp4$/.test(file) || /-player-script\.js$/.test(file));
1192
+ const tempVideoFiles = files.filter(file => /^temp_video.*\.mp4$/.test(file));
1390
1193
  for (const file of tempVideoFiles) {
1391
1194
  safeUnlink(path.join(TEMP_DIR, file));
1392
1195
  }
@@ -1407,8 +1210,7 @@ async function cleanupTempFiles() {
1407
1210
  /_audio\.mp3$/.test(file) ||
1408
1211
  /_rotated\.mp4$/.test(file) ||
1409
1212
  /_cropped\.mp4$/.test(file) ||
1410
- /_compressed\.mp4$/.test(file) ||
1411
- /-player-script\.js$/.test(file)
1213
+ /_compressed\.mp4$/.test(file)
1412
1214
  );
1413
1215
  for (const file of tempFiles) {
1414
1216
  await safeUnlinkWithRetry(path.join(TEMP_DIR, file));
@@ -1648,17 +1450,17 @@ const AudioDownloader = async (url, options = {}) => {
1648
1450
  let audioFilePath = null;
1649
1451
 
1650
1452
  try {
1651
- if (url.includes('youtube') || url.includes('youtu.be')) {
1652
- let cookies = options.YTBcookies || (options.YTBcookie ? [options.YTBcookie] : []);
1653
- if (cookies.length === 0) {
1654
- cookies = loadExternalCookies();
1655
- }
1453
+ let platform = getPlatformType(url);
1454
+ if (platform === "y124outube") {
1656
1455
 
1657
- if (cookies.length === 0) {
1658
- throw new Error("YouTube download requires a cookie. Please Provide a valid cookie.");
1456
+ let fileName = "temp_audio.mp3";
1457
+ let count = 1;
1458
+ while (fs.existsSync(fileName)) {
1459
+ fileName = `temp_audio_${count}.mp3`;
1460
+ count++;
1659
1461
  }
1660
-
1661
- audioFilePath = await downloadYoutubeVideo(url, config, cookies, config.YTBmaxduration, true);
1462
+ await downloadYoutubeAudio(url, fileName);
1463
+ audioFilePath = fileName;
1662
1464
  const result = await uploadToGoFileIfNeeded(audioFilePath);
1663
1465
  return result;
1664
1466
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frostpv",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "downloads",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@
12
12
  "author": "Delta",
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
- "@distube/ytdl-core": "^4.16.12",
16
15
  "@tobyg74/tiktok-api-dl": "^1.3.7",
17
16
  "ab-downloader": "^1.0.1",
18
17
  "axios": "1.12.0",