From 5165e8612d89853c69e4c3e6c567fd585fcef386 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:55 +0200 Subject: [PATCH] Added vidble image support. --- src/methods/redditImage.js | 2 +- src/methods/redditPreview.js | 4 +--- src/methods/vidbleImage.js | 26 +++++++++++++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/methods/redditImage.js b/src/methods/redditImage.js index 2642914..e37159f 100644 --- a/src/methods/redditImage.js +++ b/src/methods/redditImage.js @@ -12,7 +12,7 @@ function redditImage(post) { url: post.url, title: post.title, datetime: post.datetime, - type: mime.lookup(post.url), + type: mime.lookup(post.url.split('/.')[0]), original: post }] }); diff --git a/src/methods/redditPreview.js b/src/methods/redditPreview.js index 811e1eb..657e730 100644 --- a/src/methods/redditPreview.js +++ b/src/methods/redditPreview.js @@ -17,14 +17,12 @@ function redditPreview(post) { original: post } : null, items: post.preview.map(image => { - console.log(mime.lookup(image.url)); - return { id: post.host.id || post.id, url: image.url, title: post.title, datetime: post.datetime, - type: mime.lookup(image.url), + type: mime.lookup(image.url.split('?')[0]), preview: true, original: post }; diff --git a/src/methods/vidbleImage.js b/src/methods/vidbleImage.js index 8d66b8f..e817cc9 100644 --- a/src/methods/vidbleImage.js +++ b/src/methods/vidbleImage.js @@ -5,21 +5,29 @@ const config = require('config'); const path = require('path'); const fetch = require('node-fetch'); const $ = require('cheerio'); +const mime = require('mime-types'); function vidbleImage(post) { - return fetch(`https://vidble.com/${post.host.id}`).then(res => res.text()).then(res => { - console.log(res, $('img')); - + return fetch(`https://vidble.com/${post.host.id}`).then(res => { if(res.status !== 200) { - throw new Error(`Could not fetch info for vidble album '${post.host.id}': '${res.data.error}'`); + throw new Error(`Could not fetch info for vidble album '${post.host.id}': '${res.error}'`); } - const extract = config.library.album.extractSingleItem && res.data.images.length === 1; - - if(extract) { - console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${post.title}' - ${res.data.link}`); - } + return res.text(); + }).then(res => { + const resource = $('img', res).attr('src'); + return { + album: null, + items: [{ + id: post.host.id, + url: `https://vidble.com/${resource}`, + title: post.title, + datetime: post.datetime, + type: mime.lookup(resource), + original: post + }] + }; }); };