frostpv 1.0.19 → 1.0.20

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.
package/index.js CHANGED
@@ -6,6 +6,8 @@ const FormData = require("form-data");
6
6
  const crypto = require("crypto");
7
7
  const { igdl, ttdl, fbdown, mediafire, capcut, gdrive, pinterest, twitter } = require("btch-downloader");
8
8
  const { TwitterDL } = require("twitter-downloader");
9
+ const instagramCustom = require('./instagramcustom');
10
+ const tiktokCustom = require('./tiktokcustom');
9
11
  const btch = require("btch-downloader");
10
12
  const btchOld = require("btch-downloader-old");
11
13
 
@@ -293,6 +295,13 @@ async function tryFallbackDownload(url, maxRetries = 3) {
293
295
  switch (platform) {
294
296
  case "instagram": {
295
297
  const methods = [
298
+ async () => {
299
+ try {
300
+ return await instagramCustom(url);
301
+ } catch (e) {
302
+ throw new Error(`instagramCustom failed: ${e.message}`);
303
+ }
304
+ },
296
305
  async () => {
297
306
  const data = await igdl(url);
298
307
  if (data && Array.isArray(data) && data[0] && data[0].url) {
@@ -354,6 +363,13 @@ async function tryFallbackDownload(url, maxRetries = 3) {
354
363
  case "tiktok": {
355
364
 
356
365
  const methods = [
366
+ async () => {
367
+ try {
368
+ return await tiktokCustom(url);
369
+ } catch (e) {
370
+ throw new Error(`tiktokCustom failed: ${e.message}`);
371
+ }
372
+ },
357
373
  async () => {
358
374
  const data = await ttdl(url);
359
375
  if (data && data.video && data.video[0]) {
@@ -0,0 +1,55 @@
1
+ const axios = require('axios');
2
+ const cheerio = require('cheerio');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ // This module exposes a function that accepts an Instagram URL and
7
+ // returns a direct video download URL (string) when possible.
8
+ module.exports = async function instagramCustom(instaUrl) {
9
+ try {
10
+ if (!instaUrl || typeof instaUrl !== 'string') throw new Error('Invalid URL');
11
+
12
+ const response = await axios.post(
13
+ 'https://instadown.org/wp-json/visolix/api/download',
14
+ {
15
+ url: instaUrl,
16
+ format: "",
17
+ captcha_response: null
18
+ },
19
+ {
20
+ headers: {
21
+ 'accept': '*/*',
22
+ 'content-type': 'application/json',
23
+ 'x-visolix-nonce': 'fed490c4ea',
24
+ 'Referer': 'https://instadown.org/fr/'
25
+ },
26
+ timeout: 15000
27
+ }
28
+ );
29
+
30
+ if (!response || !response.data) throw new Error('No response from instadown');
31
+ if (!response.data.status) throw new Error('instadown returned an error');
32
+
33
+ const $ = cheerio.load(response.data.data || '');
34
+ // The button/link typically has class 'visolix-item-download'
35
+ let downloadUrl = $('.visolix-item-download').attr('href');
36
+
37
+ // fallback: look for any <a href="...mp4"> in the HTML
38
+ if (!downloadUrl) {
39
+ const anchors = $('a');
40
+ anchors.each((i, el) => {
41
+ const href = $(el).attr('href');
42
+ if (href && href.match(/\.(mp4|m3u8)(\?|$)/i)) {
43
+ downloadUrl = href;
44
+ return false;
45
+ }
46
+ });
47
+ }
48
+
49
+ if (!downloadUrl) throw new Error('Download link not found');
50
+
51
+ return downloadUrl;
52
+ } catch (err) {
53
+ throw new Error(`instagramCustom failed: ${err.message}`);
54
+ }
55
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frostpv",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "downloads",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "fs": "^0.0.1-security",
24
24
  "path": "^0.12.7",
25
25
  "twitter-downloader": "^1.1.8",
26
- "uuid": "^11.1.0"
26
+ "uuid": "^11.1.0",
27
+ "cheerio": "^1.1.2"
27
28
  }
28
29
  }
@@ -0,0 +1,114 @@
1
+ const axios = require('axios');
2
+
3
+ function extractTikTokVideoId(input) {
4
+ if (!input || typeof input !== 'string') return null;
5
+
6
+ const trimmed = input.trim();
7
+
8
+ if (/^\d{5,}$/.test(trimmed)) return trimmed;
9
+
10
+ const match1 = trimmed.match(/\/video\/(\d{5,})/);
11
+ if (match1 && match1[1]) return match1[1];
12
+
13
+ const match2 = trimmed.match(/[?&]item_id=(\d{5,})/);
14
+ if (match2 && match2[1]) return match2[1];
15
+
16
+ const match3 = trimmed.match(/(\d{10,})/);
17
+ if (match3 && match3[1]) return match3[1];
18
+
19
+ return null;
20
+ }
21
+
22
+ function findFirstMediaUrl(value) {
23
+ if (!value) return null;
24
+ if (typeof value === 'string') {
25
+ if (/^https?:\/\//i.test(value)) return value;
26
+ return null;
27
+ }
28
+ if (Array.isArray(value)) {
29
+ for (const v of value) {
30
+ const found = findFirstMediaUrl(v);
31
+ if (found) return found;
32
+ }
33
+ return null;
34
+ }
35
+ if (typeof value === 'object') {
36
+ const candidates = [
37
+ value.url,
38
+ value.play,
39
+ value.playUrl,
40
+ value.play_url,
41
+ value.download,
42
+ value.downloadUrl,
43
+ value.download_url,
44
+ value.video,
45
+ value.videoUrl,
46
+ value.video_url,
47
+ value.wmplay,
48
+ value.wmPlay,
49
+ value.hdplay,
50
+ value.hdPlay,
51
+ value.hd
52
+ ];
53
+
54
+ for (const c of candidates) {
55
+ const found = findFirstMediaUrl(c);
56
+ if (found) return found;
57
+ }
58
+
59
+ for (const key of Object.keys(value)) {
60
+ const found = findFirstMediaUrl(value[key]);
61
+ if (found) return found;
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+
67
+ module.exports = async function tiktokCustom(tiktokUrlOrId) {
68
+ try {
69
+ const id = extractTikTokVideoId(tiktokUrlOrId);
70
+ if (!id) throw new Error('Invalid TikTok URL/ID');
71
+
72
+ const apiUrl = `https://api.twitterpicker.com/tiktok/mediav2?id=${encodeURIComponent(id)}`;
73
+
74
+ const headers = {
75
+ 'accept': '*/*',
76
+ 'accept-language': 'fr-FR,fr;q=0.6',
77
+ 'origin': 'https://tiktokdownloader.com',
78
+ 'priority': 'u=1, i',
79
+ 'sec-ch-ua': '"Not(A:Brand";v="8", "Chromium";v="144", "Brave";v="144"',
80
+ 'sec-ch-ua-mobile': '?0',
81
+ 'sec-ch-ua-platform': '"Windows"',
82
+ 'sec-fetch-dest': 'empty',
83
+ 'sec-fetch-mode': 'cors',
84
+ 'sec-fetch-site': 'cross-site',
85
+ 'sec-gpc': '1',
86
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'
87
+ };
88
+
89
+ const response = await axios.get(apiUrl, { headers, timeout: 15000 });
90
+ const data = response && response.data ? response.data : null;
91
+ if (!data) throw new Error('No response from twitterpicker');
92
+
93
+
94
+
95
+ // Prefer no-watermark video URL when available
96
+ if (data.video_no_watermark && typeof data.video_no_watermark === 'object') {
97
+ const directNoWm = data.video_no_watermark.url;
98
+ if (typeof directNoWm === 'string' && /^https?:\/\//i.test(directNoWm)) return directNoWm;
99
+
100
+ if (Array.isArray(data.video_no_watermark_alternatives)) {
101
+ for (const alt of data.video_no_watermark_alternatives) {
102
+ if (alt && typeof alt.url === 'string' && /^https?:\/\//i.test(alt.url)) return alt.url;
103
+ }
104
+ }
105
+ }
106
+
107
+ const mediaUrl = findFirstMediaUrl(data);
108
+ if (!mediaUrl) throw new Error('Media URL not found');
109
+
110
+ return mediaUrl;
111
+ } catch (err) {
112
+ throw new Error(`tiktokCustom failed: ${err.message}`);
113
+ }
114
+ };