feat: support download tweet pic and video

This commit is contained in:
DIYgod
2021-05-16 04:55:23 +08:00
parent 37f9ca31eb
commit 96ba48879d
+15 -1
View File
@@ -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);