2024-09-11 03:16:57 +00:00
|
|
|
'use strict';
|
2024-09-11 03:16:55 +00:00
|
|
|
|
|
|
|
const config = require('config');
|
|
|
|
const fetch = require('node-fetch');
|
2024-09-11 03:16:57 +00:00
|
|
|
const UrlPattern = require('url-pattern');
|
2024-09-11 03:16:55 +00:00
|
|
|
const cheerio = require('cheerio');
|
|
|
|
const mime = require('mime-types');
|
|
|
|
|
2024-09-11 03:16:58 +00:00
|
|
|
const logger = require('../logger')(__filename);
|
|
|
|
|
2024-09-11 03:16:57 +00:00
|
|
|
const pattern = new UrlPattern('https\\://(www.)vidble.com/:id(_med)(.:ext)');
|
|
|
|
|
|
|
|
async function vidbleAlbum(host, post) {
|
|
|
|
const res = await fetch(`https://www.vidble.com/album/${host.id}`);
|
|
|
|
|
|
|
|
if (res.status !== 200) {
|
|
|
|
throw new Error(`Could not fetch info for vidble album '${host.id}': '${res.error}'`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const html = await res.text();
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
|
|
|
|
const title = $('h2').text();
|
|
|
|
const imgUrls = $('img.img2').toArray().map(img => `https://vidble.com${img.attribs.src || img.attribs['data-original']}`);
|
|
|
|
const extract = config.library.extractSingleAlbumItem && imgUrls.length === 1;
|
|
|
|
|
|
|
|
if (extract) {
|
2024-09-11 03:16:58 +00:00
|
|
|
logger.verbose(`Extracting single item from album '${post.title}' - ${res.link}`);
|
2024-09-11 03:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
album: extract ? null : {
|
|
|
|
id: host.id,
|
|
|
|
url: post ? post.url : null,
|
|
|
|
title: post ? post.title : title,
|
|
|
|
datetime: post ? post.datetime : null,
|
|
|
|
},
|
|
|
|
items: imgUrls.map((url) => {
|
|
|
|
const components = pattern.match(url);
|
|
|
|
const id = components.id.replace('_med', '');
|
|
|
|
const mimetype = mime.lookup(components.ext);
|
|
|
|
|
|
|
|
return {
|
|
|
|
extracted: extract,
|
|
|
|
id,
|
|
|
|
url: `https://vidble.com/${id}.${components.ext}`,
|
|
|
|
type: mimetype,
|
2024-09-11 03:16:58 +00:00
|
|
|
datetime: post ? post.datetime : null,
|
2024-09-11 03:16:57 +00:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
2024-09-11 03:16:55 +00:00
|
|
|
|
|
|
|
module.exports = vidbleAlbum;
|