Support implicit video media

This commit is contained in:
3nprob 2021-10-07 18:40:47 +09:00
parent 56a2f6b266
commit 8bf7d4f792
1 changed files with 18 additions and 4 deletions

View File

@ -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;
}
}
}