@soyaxell09/zenbot-scraper 1.1.4 → 1.1.6

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/README.md CHANGED
@@ -35,7 +35,9 @@ src/
35
35
  ├── tools/ → Traductor, Clima, QR, Lyrics, ATTP...
36
36
  └── nsfw/ → XNXX, PornHub, XVideos, XHamster, Rule34
37
37
  ```
38
- ```
38
+
39
+ ---
40
+
39
41
  ## ⚙️ Requisitos
40
42
 
41
43
  - Node.js `>= 18.0.0`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soyaxell09/zenbot-scraper",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Scrapers de descarga y búsqueda para bots de WhatsApp — YouTube, TikTok, Instagram, Facebook, Twitter, Pinterest, MediaFire, GitHub, APK, Google Drive, XNXX, PornHub, XVideos, XHamster, Rule34, Screenshot y más.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -8,6 +8,8 @@
8
8
  export { ytInfo, ytDownload, ytSearch, getFileSize } from './scrapers/youtube.js'
9
9
  export { youtubeDownload } from './scrapers/youtubev2.js'
10
10
  export { tiktokInfo, tiktokDownload } from './scrapers/tiktok.js'
11
+ export { snaptikDownload } from './scrapers/snaptik.js'
12
+ export { deezerSearch, deezerTrack } from './scrapers/deezer.js'
11
13
  export { igDownload, igReelDownload, igStalk, igStories } from './scrapers/instagram.js'
12
14
  export { threadsDownload } from './scrapers/threads.js'
13
15
  export { spotidownTrack } from './scrapers/spotidown.js'
@@ -21,6 +23,7 @@ export { googleSearch } from './searc
21
23
  export { giphy, gifNext, giphyBuffer } from './search/giphy.js'
22
24
  export { pinsearch, pinimg, pinvid } from './search/pinterest.js'
23
25
  export { stickerSearch } from './search/stickersearch.js'
26
+ export { deezerSearch2, deezerSearchAlbum, deezerSearchArtist, deezerAlbumTracks, deezerArtistTopTracks } from './search/deezersearch.js'
24
27
  export { animeImage } from './search/anime.js'
25
28
  export { wallpaperSearch } from './search/wallpaper.js'
26
29
  export { tiktokStalk } from './tools/tiktokstalk.js'
@@ -0,0 +1,98 @@
1
+ /*
2
+ * © Created by AxelDev09 🔥
3
+ * GitHub: https://github.com/AxelDev09
4
+ * Instagram: @axeldev09
5
+ * Deja los créditos we 🗣️
6
+ */
7
+
8
+ import axios from 'axios'
9
+
10
+ const UA = 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
11
+ const BASE = 'https://flacdownloader.com'
12
+ const APIBASE = `${BASE}/flac`
13
+ const KEY = 'l@p*gute)77=g5clebcp4lz#=x%(*rwg+ku0_)bh=&%6wg!a'
14
+
15
+ const HEADERS = {
16
+ 'User-Agent': UA,
17
+ 'Referer': `${BASE}/`,
18
+ }
19
+
20
+ export async function deezerSearch(query, limit = 10) {
21
+ const { data } = await axios.get(`${APIBASE}/search`, {
22
+ params: { query },
23
+ headers: HEADERS,
24
+ timeout: 12000,
25
+ })
26
+
27
+ return (data.data || []).slice(0, limit).map(t => ({
28
+ id: t.id,
29
+ title: t.title,
30
+ duration: t.duration,
31
+ preview: t.preview,
32
+ explicit: t.explicit_lyrics,
33
+ link: t.link,
34
+ artist: {
35
+ id: t.artist?.id,
36
+ name: t.artist?.name,
37
+ picture: t.artist?.picture_medium,
38
+ },
39
+ album: {
40
+ id: t.album?.id,
41
+ title: t.album?.title,
42
+ cover: t.album?.cover_medium,
43
+ cover_xl: t.album?.cover_xl,
44
+ },
45
+ }))
46
+ }
47
+
48
+ export async function deezerDownload(trackId, format = 'flac') {
49
+ const { data: tokenData } = await axios.get(`${APIBASE}/download-token`, {
50
+ params: { t: trackId, f: format },
51
+ headers: { ...HEADERS, 'X-Download-Access': KEY },
52
+ timeout: 10000,
53
+ })
54
+
55
+ const { token, expires } = tokenData
56
+
57
+ const dlRes = await axios.get(`${APIBASE}/download`, {
58
+ params: {
59
+ t: trackId,
60
+ f: format,
61
+ token,
62
+ expires,
63
+ },
64
+ headers: HEADERS,
65
+ responseType: 'arraybuffer',
66
+ timeout: 60000,
67
+ })
68
+
69
+ const ext = format.toLowerCase().includes('flac') ? 'flac' : 'mp3'
70
+ const mimeType = ext === 'flac' ? 'audio/flac' : 'audio/mpeg'
71
+
72
+ return {
73
+ buffer: Buffer.from(dlRes.data),
74
+ ext,
75
+ mimeType,
76
+ size: parseInt(dlRes.headers['content-length'] || '0', 10),
77
+ }
78
+ }
79
+
80
+ export async function deezerTrack(query, format = 'mp3') {
81
+ const results = await deezerSearch(query, 1)
82
+ if (!results.length) throw new Error('No se encontraron resultados.')
83
+
84
+ const track = results[0]
85
+ const download = await deezerDownload(track.id, format)
86
+
87
+ return {
88
+ title: track.title,
89
+ artist: track.artist.name,
90
+ album: track.album.title,
91
+ duration: track.duration,
92
+ cover: track.album.cover_xl,
93
+ preview: track.preview,
94
+ link: track.link,
95
+ explicit: track.explicit,
96
+ download,
97
+ }
98
+ }
@@ -0,0 +1,15 @@
1
+ export { ytInfo, ytDownload, ytSearch, getFileSize } from './youtube.js'
2
+ export { youtubeDownload } from './youtubev2.js'
3
+ export { tiktokInfo, tiktokDownload } from './tiktok.js'
4
+ export { tiktokSearch } from './tiktok.js'
5
+ export { snaptikDownload } from './snaptik.js'
6
+ export { deezerSearch, deezerTrack } from './deezer.js'
7
+ export { fbDownload } from './facebook.js'
8
+ export { tweetInfo, tweetDownload } from './twitter.js'
9
+ export { mediafireInfo } from './mediafire.js'
10
+ export { githubInfo, githubRelease, githubContents, githubSearch } from './github.js'
11
+ export { apkSearch, apkInfo } from './apk.js'
12
+ export { gdriveInfo, gdriveDownload } from './gdrive.js'
13
+ export { igDownload, igReelDownload, igStalk, igStories } from './instagram.js'
14
+ export { threadsDownload } from './threads.js'
15
+ export { spotidownTrack } from './spotidown.js'
@@ -0,0 +1,137 @@
1
+ /*
2
+ * © Created by AxelDev09 🔥
3
+ * GitHub: https://github.com/AxelDev09
4
+ * Instagram: @axeldev09
5
+ * Deja los créditos we 🗣️
6
+ */
7
+
8
+ import axios from 'axios'
9
+ import * as cheerio from 'cheerio'
10
+ import { createContext, runInContext } from 'vm'
11
+
12
+ const UA = 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
13
+ const BASE = 'https://snaptik.app'
14
+ const HEADERS = { 'User-Agent': UA }
15
+
16
+ function decodeObfuscated(jsCode) {
17
+ const patched = jsCode
18
+ .replace(/eval\(function\(h,u,n,t,e,r\)/, 'decoded=(function(h,u,n,t,e,r)')
19
+ .replace(/\}\)\s*$/, '})')
20
+ try {
21
+ const ctx = createContext({ decoded: '' })
22
+ runInContext(patched, ctx, { timeout: 5000 })
23
+ return ctx.decoded || ''
24
+ } catch { return '' }
25
+ }
26
+
27
+ function extractInnerHTML(decoded) {
28
+ const marker = 'innerHTML = "'
29
+ const idx = decoded.indexOf(marker)
30
+ if (idx === -1) return ''
31
+ const start = idx + marker.length
32
+ const end = decoded.indexOf('"; $(', start)
33
+ if (end === -1) return ''
34
+ return decoded.slice(start, end)
35
+ .replace(/\\"/g, '"')
36
+ .replace(/\\n/g, '\n')
37
+ .replace(/\\\//g, '/')
38
+ }
39
+
40
+ export async function snaptikDownload(url) {
41
+ if (!url?.trim()) throw new Error('Se requiere una URL de TikTok')
42
+
43
+ const r0 = await axios.get(`${BASE}/en2`, {
44
+ headers: HEADERS,
45
+ timeout: 12000,
46
+ })
47
+ const $0 = cheerio.load(r0.data)
48
+ const token = $0('input[name="token"]').val() || ''
49
+ const cookies = r0.headers['set-cookie']?.map(c => c.split(';')[0]).join('; ') || ''
50
+
51
+ if (!token) throw new Error('No se pudo obtener el token de snaptik')
52
+
53
+ const params = new URLSearchParams({ url, token, lang: 'en2' })
54
+ const { data } = await axios.post(`${BASE}/abc2.php`, params, {
55
+ headers: {
56
+ ...HEADERS,
57
+ 'Content-Type': 'application/x-www-form-urlencoded',
58
+ 'Referer': `${BASE}/en2`,
59
+ 'Origin': BASE,
60
+ 'Cookie': cookies,
61
+ },
62
+ timeout: 15000,
63
+ })
64
+
65
+ const raw = typeof data === 'string' ? data : JSON.stringify(data)
66
+ const decoded = decodeObfuscated(raw)
67
+
68
+ if (!decoded) throw new Error('No se pudo decodificar el response de snaptik')
69
+
70
+ if (decoded.includes('showAlert')) {
71
+ const msgMatch = decoded.match(/showAlert\("([^"]+)"/)
72
+ throw new Error(msgMatch?.[1] || 'Error en snaptik al procesar la URL')
73
+ }
74
+
75
+ const html = extractInnerHTML(decoded)
76
+ if (!html) throw new Error('No se encontró HTML de descarga en el response')
77
+
78
+ const $ = cheerio.load(html)
79
+
80
+ const title = $('.video-title').text().trim()
81
+ const thumbnail = $('#thumbnail').attr('src') || $('img.avatar').attr('src') || ''
82
+
83
+ const btnToken = $('button.btn-render').attr('data-token') || ''
84
+ if (btnToken) {
85
+ let imageUrls = []
86
+ try {
87
+ const payload = btnToken.split('.')[1] || ''
88
+ const json = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'))
89
+ imageUrls = json.image_urls || []
90
+ } catch {}
91
+
92
+ if (!imageUrls.length) {
93
+ $('img').each((_, el) => {
94
+ const src = $(el).attr('src') || ''
95
+ if (src.includes('tiktokcdn') && !src.includes('avatar')) {
96
+ imageUrls.push(src)
97
+ }
98
+ })
99
+ imageUrls = [...new Set(imageUrls)]
100
+ }
101
+
102
+ const downloadUrls = []
103
+ $('a[href*="rapidcdn"]').each((_, el) => {
104
+ const href = $(el).attr('href') || ''
105
+ if (href) downloadUrls.push(href)
106
+ })
107
+
108
+ if (imageUrls.length || downloadUrls.length) {
109
+ return {
110
+ title,
111
+ thumbnail,
112
+ type: 'images',
113
+ images: imageUrls,
114
+ imagesWm: downloadUrls,
115
+ source: 'snaptik',
116
+ }
117
+ }
118
+ }
119
+
120
+ const sdUrl = $('a.download-file').first().attr('href') || ''
121
+ const hdApiUrl = $('button[data-tokenhd]').attr('data-tokenhd') || ''
122
+ const hdBackup = $('button[data-backup]').attr('data-backup') || ''
123
+
124
+ if (!sdUrl) throw new Error('No se encontró URL de descarga')
125
+
126
+ return {
127
+ title,
128
+ thumbnail,
129
+ type: 'video',
130
+ download: {
131
+ sd: sdUrl,
132
+ hd: hdBackup || null,
133
+ hdApi: hdApiUrl || null,
134
+ },
135
+ source: 'snaptik',
136
+ }
137
+ }
@@ -0,0 +1,128 @@
1
+ /*
2
+ * © Created by AxelDev09 🔥
3
+ * GitHub: https://github.com/AxelDev09
4
+ * Instagram: @axeldev09
5
+ * Deja los créditos we 🗣️
6
+ */
7
+
8
+ import axios from 'axios'
9
+
10
+ const UA = 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
11
+ const BASE = 'https://api.deezer.com'
12
+
13
+ async function get(endpoint, params = {}) {
14
+ const { data } = await axios.get(`${BASE}${endpoint}`, {
15
+ params,
16
+ headers: { 'User-Agent': UA },
17
+ timeout: 12000,
18
+ })
19
+ if (data?.error) throw new Error(data.error.message || 'Error en Deezer API')
20
+ return data
21
+ }
22
+
23
+ function formatDuration(ms) {
24
+ if (!ms) return null
25
+ const s = Math.floor(ms / 1000)
26
+ const m = Math.floor(s / 60)
27
+ const sec = s % 60
28
+ return `${m}:${sec.toString().padStart(2, '0')}`
29
+ }
30
+
31
+ export async function deezerFind(query, limit = 10) {
32
+ if (!query?.trim()) throw new Error('Se requiere un término de búsqueda')
33
+ const data = await get('/search', { q: query, limit })
34
+ if (!data?.data?.length) throw new Error('Sin resultados')
35
+ return data.data.map(t => ({
36
+ id: t.id,
37
+ title: t.title,
38
+ artist: t.artist?.name,
39
+ artistId: t.artist?.id,
40
+ album: t.album?.title,
41
+ albumId: t.album?.id,
42
+ cover: t.album?.cover_medium,
43
+ coverHd: t.album?.cover_xl || t.album?.cover_big,
44
+ preview: t.preview,
45
+ duration: formatDuration(t.duration * 1000),
46
+ link: t.link,
47
+ rank: t.rank,
48
+ }))
49
+ }
50
+
51
+ export async function deezerSearchAlbum(query, limit = 10) {
52
+ if (!query?.trim()) throw new Error('Se requiere un término de búsqueda')
53
+ const data = await get('/search/album', { q: query, limit })
54
+ if (!data?.data?.length) throw new Error('Sin resultados')
55
+ return data.data.map(a => ({
56
+ id: a.id,
57
+ title: a.title,
58
+ artist: a.artist?.name,
59
+ artistId: a.artist?.id,
60
+ cover: a.cover_medium,
61
+ coverHd: a.cover_xl || a.cover_big,
62
+ tracks: a.nb_tracks,
63
+ releaseDate: a.release_date,
64
+ link: a.link,
65
+ }))
66
+ }
67
+
68
+ export async function deezerSearchArtist(query, limit = 10) {
69
+ if (!query?.trim()) throw new Error('Se requiere un término de búsqueda')
70
+ const data = await get('/search/artist', { q: query, limit })
71
+ if (!data?.data?.length) throw new Error('Sin resultados')
72
+ return data.data.map(a => ({
73
+ id: a.id,
74
+ name: a.name,
75
+ picture: a.picture_medium,
76
+ pictureHd: a.picture_xl || a.picture_big,
77
+ fans: a.nb_fan,
78
+ link: a.link,
79
+ }))
80
+ }
81
+
82
+ export async function deezerAlbumTracks(albumId, limit = 50) {
83
+ if (!albumId) throw new Error('Se requiere un ID de álbum')
84
+ const data = await get(`/album/${albumId}/tracks`, { limit })
85
+ if (!data?.data?.length) throw new Error('Sin tracks')
86
+ const album = await get(`/album/${albumId}`)
87
+ return {
88
+ id: album.id,
89
+ title: album.title,
90
+ artist: album.artist?.name,
91
+ cover: album.cover_medium,
92
+ coverHd: album.cover_xl || album.cover_big,
93
+ releaseDate: album.release_date,
94
+ genre: album.genres?.data?.[0]?.name || null,
95
+ tracks: data.data.map(t => ({
96
+ id: t.id,
97
+ title: t.title,
98
+ duration: formatDuration(t.duration * 1000),
99
+ preview: t.preview,
100
+ link: `https://www.deezer.com/track/${t.id}`,
101
+ }))
102
+ }
103
+ }
104
+
105
+ export async function deezerArtistTopTracks(artistId, limit = 10) {
106
+ if (!artistId) throw new Error('Se requiere un ID de artista')
107
+ const data = await get(`/artist/${artistId}/top`, { limit })
108
+ if (!data?.data?.length) throw new Error('Sin tracks')
109
+ const artist = await get(`/artist/${artistId}`)
110
+ return {
111
+ id: artist.id,
112
+ name: artist.name,
113
+ picture: artist.picture_medium,
114
+ pictureHd: artist.picture_xl || artist.picture_big,
115
+ fans: artist.nb_fan,
116
+ link: artist.link,
117
+ tracks: data.data.map(t => ({
118
+ id: t.id,
119
+ title: t.title,
120
+ album: t.album?.title,
121
+ cover: t.album?.cover_medium,
122
+ duration: formatDuration(t.duration * 1000),
123
+ preview: t.preview,
124
+ rank: t.rank,
125
+ link: `https://www.deezer.com/track/${t.id}`,
126
+ }))
127
+ }
128
+ }
@@ -9,6 +9,7 @@ export { ytSearch } from './youtube.js'
9
9
  export { googleSearch } from './google.js'
10
10
  export { giphy, gifNext, giphyBuffer } from './giphy.js'
11
11
  export { pinsearch, pinimg, pinvid } from './pinterest.js'
12
+ export { deezerFind, deezerSearchAlbum, deezerSearchArtist, deezerAlbumTracks, deezerArtistTopTracks } from './deezersearch.js'
12
13
  export { stickerSearch } from './stickersearch.js'
13
14
  export { animeImage } from './anime.js'
14
15
  export { wallpaperSearch } from './wallpaper.js'
package/src/tools/ia.js DELETED
@@ -1,74 +0,0 @@
1
- /*
2
- * © Created by AxelDev09 🔥
3
- * GitHub: https://github.com/AxelDev09
4
- * Instagram: @axeldev09
5
- * Deja los créditos we 🗣️
6
- */
7
-
8
- import axios from 'axios'
9
-
10
- const UA = 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
11
- const BASE = 'https://api.delirius.store'
12
-
13
- const headers = { 'User-Agent': UA }
14
-
15
- export async function copilot(query) {
16
- if (!query) throw new Error('query es requerido')
17
- const { data } = await axios.get(`${BASE}/ia/copilot`, {
18
- params: { query },
19
- headers,
20
- timeout: 12000,
21
- })
22
- if (!data?.text) throw new Error('Sin respuesta')
23
- return {
24
- text: data.text,
25
- citations: data.citations || [],
26
- conversationId: data.conversationId || null,
27
- }
28
- }
29
-
30
- export async function gemini(query) {
31
- if (!query) throw new Error('query es requerido')
32
- const { data } = await axios.get(`${BASE}/ia/gemini`, {
33
- params: { query },
34
- headers,
35
- timeout: 12000,
36
- })
37
- if (!data?.status || !data?.data?.result) throw new Error('Sin respuesta')
38
- return { text: data.data.result }
39
- }
40
-
41
- export async function chatgpt(query) {
42
- if (!query) throw new Error('query es requerido')
43
- const { data } = await axios.get(`${BASE}/ia/chatgpt`, {
44
- params: { q: query },
45
- headers,
46
- timeout: 12000,
47
- })
48
- if (!data?.status || !data?.data) throw new Error('Sin respuesta')
49
- return { text: data.data }
50
- }
51
-
52
- export async function gptPrompt(text, prompt = '') {
53
- if (!text) throw new Error('text es requerido')
54
- const params = { text }
55
- if (prompt) params.prompt = prompt
56
- const { data } = await axios.get(`${BASE}/ia/gptprompt`, {
57
- params,
58
- headers,
59
- timeout: 12000,
60
- })
61
- if (!data?.status || !data?.data) throw new Error('Sin respuesta')
62
- return { text: data.data }
63
- }
64
-
65
- export async function ripleai(query) {
66
- if (!query) throw new Error('query es requerido')
67
- const { data } = await axios.get(`${BASE}/ia/ripleai`, {
68
- params: { query },
69
- headers,
70
- timeout: 12000,
71
- })
72
- if (!data?.status || !data?.data?.result) throw new Error('Sin respuesta')
73
- return { text: data.data.result }
74
- }
package/test.js DELETED
@@ -1,130 +0,0 @@
1
- /*
2
- * TEST — apk.js
3
- * Corre con: node test.js
4
- */
5
-
6
- import axios from 'axios'
7
- import * as cheerio from 'cheerio'
8
- import { createWriteStream, statSync } from 'fs'
9
- import { pipeline } from 'stream/promises'
10
-
11
- const UA = 'Mozilla/5.0 (Linux; Android 11; Redmi Note 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36'
12
- const BASE = 'https://apkpure.net'
13
- const DL_BASE = 'https://d.apkpure.net'
14
- const HEADERS = { 'User-Agent': UA, 'Referer': BASE }
15
-
16
- const QUERY = 'Google Fotos'
17
- const PKG = 'org.telegram.messenger'
18
- const SAVE_PATH = '/sdcard/test-apk.apk'
19
-
20
- async function test(name, fn) {
21
- console.log(`\n── ${name} ──`)
22
- try {
23
- const r = await fn()
24
- console.log(`✅ OK`)
25
- console.log(` ${JSON.stringify(r).slice(0, 300)}`)
26
- return r
27
- } catch (e) {
28
- console.log(`❌ ERROR: ${e.message}`)
29
- return null
30
- }
31
- }
32
-
33
- console.log('='.repeat(50))
34
- console.log(' TEST — apk.js')
35
- console.log('='.repeat(50))
36
-
37
- // ── 1. Búsqueda
38
- await test(`apkSearch("${QUERY}")`, async () => {
39
- const { data } = await axios.get(`${BASE}/search?q=${encodeURIComponent(QUERY)}`, {
40
- headers: HEADERS, timeout: 15000
41
- })
42
- const $ = cheerio.load(data)
43
- const items = []
44
- $('.search-brand-container').each((_, el) => {
45
- if (items.length >= 3) return false
46
- const name = $(el).find('a.top').first().text().trim()
47
- const pkg = $(el).find('[data-dt-pkg]').attr('data-dt-pkg') || ''
48
- const appHref = $(el).find('a.top').first().attr('href') || ''
49
- const appUrl = appHref.startsWith('http') ? appHref : `${BASE}${appHref}`
50
- if (name && pkg) items.push({ name, pkg, appUrl, dlUrl: `${DL_BASE}/b/APK/${pkg}?version=latest` })
51
- })
52
- if (!items.length) throw new Error('Sin resultados — el selector puede haber cambiado')
53
- return items
54
- })
55
-
56
- // ── 2. Info del APK
57
- await test(`apkInfo("${PKG}")`, async () => {
58
- const shortName = PKG.split('.').slice(-2).join('-').toLowerCase()
59
- const { data } = await axios.get(`${BASE}/${shortName}/${PKG}/download`, {
60
- headers: HEADERS, timeout: 15000, validateStatus: () => true
61
- })
62
- const $ = cheerio.load(data)
63
- const version = $('[class*="version"]').first().text().trim()
64
- const size = $('[class*="size"]').first().text().trim()
65
- const title = $('title').text().trim()
66
- const dlLinks = []
67
- $(`a[href*="d.apkpure.net"]`).each((_, a) => {
68
- const href = $(a).attr('href') || ''
69
- if (href.includes(PKG)) dlLinks.push(href)
70
- })
71
- return { title, version, size, dlLinksCount: dlLinks.length, firstDlLink: dlLinks[0] || null }
72
- })
73
-
74
- // ── 3. HEAD — verificar URL de descarga
75
- const DL_URL = `${DL_BASE}/b/APK/${PKG}?version=latest`
76
- await test(`HEAD ${DL_URL.slice(0, 60)}...`, async () => {
77
- const res = await axios.head(DL_URL, {
78
- headers: { ...HEADERS, 'Accept': 'application/vnd.android.package-archive' },
79
- timeout: 15000, maxRedirects: 5, validateStatus: () => true
80
- })
81
- return {
82
- status: res.status,
83
- contentType: res.headers['content-type'],
84
- sizeMB: res.headers['content-length']
85
- ? (parseInt(res.headers['content-length']) / 1024 / 1024).toFixed(2) + ' MB'
86
- : 'desconocido',
87
- finalUrl: res.request?.res?.responseUrl?.slice(0, 80) || '',
88
- }
89
- })
90
-
91
- // ── 4. Descarga real → /sdcard/test-apk.apk
92
- await test(`Descarga real → ${SAVE_PATH}`, async () => {
93
- const res = await axios.get(DL_URL, {
94
- headers: { ...HEADERS, 'Accept': 'application/vnd.android.package-archive' },
95
- responseType: 'stream',
96
- timeout: 120000,
97
- maxRedirects: 10,
98
- })
99
-
100
- const ct = res.headers['content-type'] || ''
101
- const APK_TYPES = ['apk', 'octet-stream', 'zip', 'java-archive', 'android']
102
- const esApk = APK_TYPES.some(t => ct.includes(t))
103
-
104
- if (!esApk) {
105
- // Leer primeros bytes como texto para ver si es HTML de error
106
- const chunks = []
107
- for await (const chunk of res.data) {
108
- chunks.push(chunk)
109
- if (Buffer.concat(chunks).length > 300) break
110
- }
111
- const preview = Buffer.concat(chunks).toString('utf8', 0, 200)
112
- throw new Error(`Content-Type inesperado: ${ct}\nPreview: ${preview}`)
113
- }
114
-
115
- await pipeline(res.data, createWriteStream(SAVE_PATH))
116
-
117
- const { size } = statSync(SAVE_PATH)
118
- if (size < 1000) throw new Error(`Archivo guardado pero muy pequeño (${size} bytes) — probablemente un error HTML`)
119
-
120
- return {
121
- contentType: ct,
122
- sizeMB: (size / 1024 / 1024).toFixed(2) + ' MB',
123
- guardado: SAVE_PATH,
124
- valido: size > 100_000 ? '✅ APK válido' : '⚠️ Muy pequeño, verificar',
125
- }
126
- })
127
-
128
- console.log('\n' + '='.repeat(50))
129
- console.log(' Test terminado')
130
- console.log('='.repeat(50))