downloader-pinterest
#fsumbs7javascript ยท 207 baris ยท 29553 dilihat
/**
* ๐ Plugins Pinterest Image & Video (Unified with NIXCODE UI)
*
* Terintegrasi dengan Multi-API Fallback (Cadangan API)
* UI by NIXCODE (Carousel & Buttons)
**/
import axios from 'axios'
import fetch from 'node-fetch'
import { exec } from 'child_process'
import fs from 'fs'
import { promisify } from 'util'
import { Button, Carousel } from '../lib/nixcode.js' // Pastikan path ini sesuai dengan folder lib kamu
const execAsync = promisify(exec)
// ==========================================
// FUNGSI MULTI-API UNTUK PINTEREST IMAGE
// ==========================================
async function fetchPinterestImages(query) {
const apis = [
// 1. Deline API
async () => {
let { data } = await axios.get(`https://api.deline.web.id/search/pinterest?q=${encodeURIComponent(query)}`)
if (!data?.data || data.data.length === 0) throw new Error()
return data.data.map(item => ({ title: item.caption, url: item.image, source: item.source }))
},
// 2. Jerex API
async () => {
let { data } = await axios.get(`https://api.jerexd.my.id/api/search/pin?apikey=jere_4tnutoduhbpz&q=${encodeURIComponent(query)}&limit=15`)
if (!data?.result || data.result.length === 0) throw new Error()
return data.result.map(url => ({ title: `Hasil Pinterest: ${query}`, url: url, source: url }))
},
// 3. Nexray API
async () => {
let { data } = await axios.get(`https://api.nexray.eu.cc/search/pinterest?q=${encodeURIComponent(query)}`)
if (!data?.result || data.result.length === 0) throw new Error()
return data.result.map(url => ({ title: `Hasil Pinterest: ${query}`, url: url, source: url }))
},
// 4. Zecho API
async () => {
let { data } = await axios.get(`https://zechoxyz.offc.biz.id/search/pinterest?apikey=jekk&q=${encodeURIComponent(query)}`)
if (!data?.result || data.result.length === 0) throw new Error()
return data.result.map(url => ({ title: `Hasil Pinterest: ${query}`, url: url, source: url }))
},
// 5. R-Bots API
async () => {
let { data } = await axios.get(`https://r-bots-free-apis.co08.art/api/pinterest?q=${encodeURIComponent(query)}`)
if (!data?.result || data.result.length === 0) throw new Error()
return data.result.map(url => ({ title: `Hasil Pinterest: ${query}`, url: url, source: url }))
}
]
for (let fetchApi of apis) {
try {
let result = await fetchApi()
if (result && result.length > 0) return result
} catch (e) {
continue // Jika gagal, lanjut ke API berikutnya
}
}
return [] // Mengembalikan array kosong jika semua API gagal
}
// ==========================================
// HANDLER UTAMA
// ==========================================
let handler = async (m, { conn, text, usedPrefix, command }) => {
if (!text) return m.reply(`Mau cari apa, Bang?\n\nContoh:\n*${usedPrefix + command} kucing*`)
// ----------------------------------------------------
// FITUR 1: PINTEREST VIDEO DOWNLOADER (.pinvid)
// ----------------------------------------------------
if (/^(pinvid|pinterestvideo)$/i.test(command)) {
await m.react('๐')
try {
let videoFound = false
let videoUrl = ''
let videoDetails = {}
// Coba API 1: Jerex API (Video Search)
try {
let jerexRes = await axios.get(`https://api.jerexd.my.id/api/downloader/pinvid?apikey=jere_4tnutoduhbpz&query=${encodeURIComponent(text)}&limit=1`)
if (jerexRes.data?.result && jerexRes.data.result.length > 0) {
videoUrl = jerexRes.data.result[0].url || jerexRes.data.result[0]
videoFound = true
}
} catch (e) {
// Jika gagal, lanjut ke Codeteam API
}
// Coba API 2: Codeteam API (Search Video) - Jika Jerex gagal
if (!videoFound) {
let codeTeamRes = await fetch(`https://api.codeteam.web.id/api/v1/pinterest-search?query=${encodeURIComponent(text + ' video')}`)
let result = await codeTeamRes.json()
if (result.status === 'success' && result.data && result.data.length > 0) {
const videoItems = result.data.filter(item => item.videoUrl && item.videoUrl !== 'gak ada')
if (videoItems.length > 0) {
const randomVideo = videoItems[Math.floor(Math.random() * videoItems.length)]
videoUrl = randomVideo.videoUrl
videoDetails = randomVideo
videoFound = true
}
}
}
if (!videoFound) return m.reply('โ *Maaf, video tidak ditemukan untuk query tersebut.*')
// Jika videonya format m3u8 (HLS stream), gunakan FFmpeg
if (videoUrl.includes('.m3u8')) {
const tempDir = './tmp'
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true })
const timestamp = Date.now()
const outputPath = `${tempDir}/pinvid_${timestamp}.mp4`
const ffmpegCmd = `ffmpeg -y -loglevel error -i "${videoUrl}" -c copy -bsf:a aac_adtstoasc "${outputPath}"`
await execAsync(ffmpegCmd)
let captionVid = `๐ *PINTEREST VIDEO*\n\n_Query: ${text}_`
if (videoDetails.title) captionVid += `\n*Judul:* ${videoDetails.title}`
await conn.sendMessage(m.chat, {
video: fs.readFileSync(outputPath),
caption: captionVid,
mimetype: 'video/mp4'
}, { quoted: m })
fs.unlinkSync(outputPath) // Hapus file temporary
}
// Jika videonya direct mp4
else {
await conn.sendMessage(m.chat, {
video: { url: videoUrl },
caption: `๐ *PINTEREST VIDEO*\n\n_Query: ${text}_`
}, { quoted: m })
}
await m.react('โ
')
} catch (error) {
console.error('Error Video Pinterest:', error)
await m.react('โ')
m.reply('โ *Terjadi kesalahan saat memproses video.*')
}
return
}
// ----------------------------------------------------
// FITUR 2: PINTEREST IMAGE SEARCH DENGAN CAROUSEL UI (.pinterest)
// ----------------------------------------------------
await m.react('๐')
try {
let results = await fetchPinterestImages(text)
if (results.length === 0) {
await m.react('โ')
return m.reply('โ Gambar tidak ditemukan atau semua API sedang limit/error.')
}
// Ambil maksimal 10 gambar untuk Carousel
let selected = results.slice(0, 10)
let namebot = global.namebot || 'Erine-MD'
// Buat Carousel Induk
let carousel = new Carousel(conn)
.setBody(`๐ *PINTEREST SEARCH*\n\nQuery: _${text}_`)
.setFooter('Geser untuk melihat hasil lainnya โก๏ธ')
// Masukkan kartu ke dalam Carousel
for (let [idx, item] of selected.entries()) {
let titleText = item.title && item.title.trim() ? item.title : `Gambar - ${idx + 1}`
if (titleText.length > 25) titleText = titleText.substring(0, 25) + '...' // Batasi judul agar rapi di UI
let card = await new Button(conn)
.setTitle(titleText)
.setBody('Hasil pencarian Pinterest')
.setFooter(`ยฉ ${namebot}`)
.setImage(item.url)
// Tombol 1: URL ke sumber gambar
.addUrl('๐ Buka Sumber', item.source || item.url)
// Tombol 2: Memicu command .pinvid dengan query yang sama
.addReply('๐ฌ Mau Ambil Video Nya?', `${usedPrefix}pinvid ${text}`)
.toCard() // Convert ke format card carousel
carousel.addCard(card)
}
// Kirim Carousel
await carousel.send(m.chat, { quoted: m })
await m.react('โ
')
} catch (e) {
console.error('Error Image Pinterest:', e)
await m.react('โ')
m.reply('โ Gagal mengambil hasil Pinterest. Coba lagi nanti.')
}
}
// Konfigurasi Command
handler.command = ['pingeser', 'pinterest', 'pinges', 'pin', 'pinterestvideo', 'pinvid']
handler.help = ['pinterest <query>', 'pinvid <query>']
handler.tags = ['internet']
handler.register = true
handler.limit = true
export default handler