ripunzel/src/methods/vidbleVideo.js

38 lines
982 B
JavaScript

'use strict';
const fetch = require('node-fetch');
const cheerio = require('cheerio');
async function vidbleVideo(host, post) {
const res = await fetch(`https://www.vidble.com/watch?v=${host.id}`);
if (res.status !== 200) {
throw new Error(`Could not fetch info for vidble video '${host.id}': '${res.error}'`);
}
const html = await res.text();
const $ = cheerio.load(html);
const resource = $('video source');
const source = resource.attr('src');
const type = resource.attr('type');
if (!source || !type) {
throw new Error(`Failed to retrieve (likely removed) vidble video '${host.id}'`);
}
return {
album: null,
items: [{
id: host.id,
url: `https://vidble.com/${source}`,
title: post ? post.title : null,
datetime: post ? post.datetime : null,
type,
original: post || null,
}],
};
}
module.exports = vidbleVideo;