Added vidble image support.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:55 +02:00
parent 2c58947548
commit 5165e8612d
3 changed files with 19 additions and 13 deletions

View File

@ -12,7 +12,7 @@ function redditImage(post) {
url: post.url, url: post.url,
title: post.title, title: post.title,
datetime: post.datetime, datetime: post.datetime,
type: mime.lookup(post.url), type: mime.lookup(post.url.split('/.')[0]),
original: post original: post
}] }]
}); });

View File

@ -17,14 +17,12 @@ function redditPreview(post) {
original: post original: post
} : null, } : null,
items: post.preview.map(image => { items: post.preview.map(image => {
console.log(mime.lookup(image.url));
return { return {
id: post.host.id || post.id, id: post.host.id || post.id,
url: image.url, url: image.url,
title: post.title, title: post.title,
datetime: post.datetime, datetime: post.datetime,
type: mime.lookup(image.url), type: mime.lookup(image.url.split('?')[0]),
preview: true, preview: true,
original: post original: post
}; };

View File

@ -5,21 +5,29 @@ const config = require('config');
const path = require('path'); const path = require('path');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const $ = require('cheerio'); const $ = require('cheerio');
const mime = require('mime-types');
function vidbleImage(post) { function vidbleImage(post) {
return fetch(`https://vidble.com/${post.host.id}`).then(res => res.text()).then(res => { return fetch(`https://vidble.com/${post.host.id}`).then(res => {
console.log(res, $('img'));
if(res.status !== 200) { 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; return res.text();
}).then(res => {
if(extract) { const resource = $('img', res).attr('src');
console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${post.title}' - ${res.data.link}`);
}
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
}]
};
}); });
}; };