(sock, message, args, context)
| 20 | description: 'Download image or video from Alamy URL', |
| 21 | usage: '.alamy <Alamy URL>', |
| 22 | async handler(sock, message, args, context) { |
| 23 | const chatId = context.chatId || message.key.remoteJid; |
| 24 | const url = args?.[0]?.trim(); |
| 25 | if (!url) { |
| 26 | return await sock.sendMessage(chatId, { text: '❌ Please provide an Alamy URL.\nExample: .alamy https://www.alamy.com/video/beautiful-lake...' }, { quoted: message }); |
| 27 | } |
| 28 | try { |
| 29 | const apiUrl = `https://discardapi.dpdns.org/api/dl/alamy?apikey=guru&url=${encodeURIComponent(url)}`; |
| 30 | const { data } = await axios.get(apiUrl, { timeout: 10000 }); |
| 31 | if (!data?.status || !data.result?.length) { |
| 32 | return await sock.sendMessage(chatId, { text: '❌ Failed to fetch media from the provided Alamy URL.' }, { quoted: message }); |
| 33 | } |
| 34 | const isValidUrl = (u) => u && u.startsWith('http'); |
| 35 | let sent = false; |
| 36 | for (const item of data.result) { |
| 37 | if (isValidUrl(item.video)) { |
| 38 | await sock.sendMessage(chatId, { video: { url: item.video }, caption: '🎬 *Alamy Video*' }, { quoted: message }); |
| 39 | sent = true; |
| 40 | } |
| 41 | if (isValidUrl(item.image)) { |
| 42 | await sock.sendMessage(chatId, { image: { url: item.image }, caption: '🖼️ *Alamy Image*' }, { quoted: message }); |
| 43 | sent = true; |
| 44 | } |
| 45 | } |
| 46 | if (!sent) { |
| 47 | await sock.sendMessage(chatId, { text: '❌ No valid media found in the Alamy URL.' }, { quoted: message }); |
| 48 | } |
| 49 | } |
| 50 | catch (error) { |
| 51 | console.error('Alamy download plugin error:', error); |
| 52 | if (error.code === 'ECONNABORTED') { |
| 53 | await sock.sendMessage(chatId, { text: '❌ Request timed out. The API may be slow or unreachable.' }, { quoted: message }); |
| 54 | } |
| 55 | else { |
| 56 | await sock.sendMessage(chatId, { text: '❌ Failed to download media from Alamy URL.' }, { quoted: message }); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | }; |
| 61 | /***************************************************************************** |
| 62 | * * |
nothing calls this directly
no test coverage detected