import express from 'express'; | |
import { TiktokDownloader, XnxxDownloader } from '../lib/scrapper.js'; | |
import { | |
facebookdl, | |
savefrom, | |
mediafiredl, | |
snapsave, | |
tiktokdl, | |
youtubedl, | |
sfilemobi, | |
sfilemobiSearch | |
} from '../lib/all.js'; | |
import { authenticateApiKey, apiLimiter } from '../middleware/midware.js'; | |
const AllDlRoutes = express.Router(); | |
async function downloadMedia(media) { | |
const downloadResults = {}; | |
try { | |
/* | |
if (media.video && media.video['720p']) { | |
const videoQuality = '720p'; | |
const videoDownloadUrl = await media.video[videoQuality].download(); | |
downloadResults.video = { | |
quality: videoQuality, | |
url: videoDownloadUrl | |
}; | |
} else { | |
console.error("720p video quality is not available."); | |
}*/ | |
if (media.audio && Object.keys(media.audio).length > 0) { | |
const audioQuality = Object.keys(media.audio)[0]; | |
const audioDownloadUrl = await media.audio[audioQuality].download(); | |
downloadResults.audio = { | |
quality: audioQuality, | |
url: audioDownloadUrl | |
}; | |
} | |
return downloadResults; | |
} catch (error) { | |
console.error("Error downloading media:", error); | |
throw new Error("Failed to download media"); | |
} | |
} | |
/** | |
* @swagger | |
* /api/v1/dl/sfilemobi-search: | |
* get: | |
* summary: Sfilemobi Search Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: q | |
* required: true | |
* description: The URL of the TikTok video to be processed | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid URL) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/sfilemobi-search', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const q = req.query.q; | |
if (!q) { | |
return res.status(400).json({ error: "URL parameter is required." }); | |
} | |
const results = await sfilemobiSearch(q); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/sfilemobi: | |
* get: | |
* summary: Sfilemobi Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: The URL of the TikTok video to be processed | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid URL) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/sfilemobi', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "URL parameter is required." }); | |
} | |
const results = await sfilemobi(url); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/tiktok: | |
* get: | |
* summary: Tiktok Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: The URL of the TikTok video to be processed | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid URL) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/tiktok', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "URL parameter is required." }); | |
} | |
const results = await TiktokDownloader(url); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/tiktok-v2: | |
* get: | |
* summary: Tiktok V2 Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: The URL of the TikTok video to be processed | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid URL) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/tiktok-v2', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "URL parameter is required." }); | |
} | |
const results = await tiktokdl(url); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/fb: | |
* get: | |
* summary: FB Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: null | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid url) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/fb', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "url parameter is required." }); | |
} | |
const results = await facebookdl(url); | |
for (const video of results.video) { | |
video.url = await video.download(); | |
} | |
for (const audio of results.audio) { | |
audio.url = await audio.download(); | |
} | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/snapsave: | |
* get: | |
* summary: SnapSave Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: null | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid url) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/snapsave', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "url parameter is required." }); | |
} | |
const results = await snapsave(url); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/savefrom: | |
* get: | |
* summary: Savefrom Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: url | |
* required: true | |
* description: null | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid url) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/savefrom', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const url = req.query.url; | |
if (!url) { | |
return res.status(400).json({ error: "url parameter is required." }); | |
} | |
const results = await savefrom(url); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
/** | |
* @swagger | |
* /api/v1/dl/xnxx: | |
* get: | |
* summary: Xnxx Downloader | |
* tags: [ALL-Downloader] | |
* parameters: | |
* - in: query | |
* name: q | |
* required: true | |
* description: The search of the Xnxx video to be processed | |
* schema: | |
* type: string | |
* - in: header | |
* name: x-api-key | |
* required: true | |
* description: API key for authentication | |
* schema: | |
* type: string | |
* responses: | |
* 200: | |
* description: Success | |
* 400: | |
* description: Bad Request (e.g., missing or invalid q) | |
* 401: | |
* description: Unauthorized (e.g., missing or invalid API key) | |
* 500: | |
* description: Internal Server Error | |
*/ | |
AllDlRoutes.get('/api/v1/dl/xnxx', authenticateApiKey, apiLimiter, async (req, res) => { | |
try { | |
const q = req.query.q; | |
if (!q) { | |
return res.status(400).json({ error: "q parameter is required." }); | |
} | |
const results = await XnxxDownloader(q); | |
res.json({ results }); | |
} catch (error) { | |
res.status(500).json({ error: error.message }); | |
} | |
}); | |
export { AllDlRoutes }; |