From 96ba48879d17d012d4e1d2335bda9d3464ea2608 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 16 May 2021 04:55:23 +0800 Subject: [PATCH] feat: support download tweet pic and video --- lib/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 6428b57..0aa2db2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,6 +16,7 @@ app.use(ctx => { 'url': '', 'name': '', 'playlist': '0', + 'tweet': '', }, ctx.request.body); const result = { @@ -33,7 +34,20 @@ app.use(ctx => { result.code = 3; result.msg = 'unsupported engine'; } else { - downloader(options, result); + if (options.tweet && options.engine === 'wget') { + const match = options.tweet.match(/src="(.*?)"/g); + if (match) { + match.forEach((src, index) => { + const newOptions = JSON.parse(JSON.stringify(options)); + newOptions.url = src.replace(/src="(.*)"/, '$1'); + const format = (newOptions.url.match(/\.mp4/) ? 'mp4' : newOptions.url.match(/format=(.*?)&/)?.[1]) || 'jpg'; + newOptions.name = `${encodeURIComponent(options.url)}-${index}.${format}`; + downloader(newOptions, result); + }); + } + } else { + downloader(options, result); + } } ctx.body = JSON.stringify(result);