From 8bf7d4f7923b0aeff00e880ece624df3a9006a2b Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Thu, 7 Oct 2021 18:40:47 +0900 Subject: [PATCH] Support implicit video media --- inc/processPostMedia.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/inc/processPostMedia.js b/inc/processPostMedia.js index 18e4b9a..1834b2f 100644 --- a/inc/processPostMedia.js +++ b/inc/processPostMedia.js @@ -130,12 +130,26 @@ module.exports = function() { */ if(!post_media && !has_gif && !post.gallery_data && post.url != '') { try { - let u = new URL(post.url) + let url = replaceDomains(post.url) + const u = new URL(url) if(config.valid_media_domains.includes(u.hostname)) { - let ext = u.pathname.split('.')[1] - if(ext === 'jpg' || ext === 'png') { + const ext = u.pathname.split('.')[1] + if(['jpg', 'png', 'jpeg', 'gif'].includes(ext)) { obj.images = { - source: await downloadAndSave(post.url) + source: await downloadAndSave(url) + } + } + else if(['gifv', 'mp4'].includes(ext)) { + if (obj.domain === 'i.imgur.com') { + url = url.replace(/\.gifv$/, '.mp4'); + } + obj.has_media = true + obj.media = { + source: await downloadAndSave(url) + } + if (post.preview && post.preview.images) { + obj.media.height = post.preview.images[0].source.height; + obj.media.width = post.preview.images[0].source.width; } } }