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);