From 4e0fe3e6bc8689ca44adb8c06f687ba746d83fde Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:55 +0200 Subject: [PATCH] Added vidble direct video (/watch?v=) support. --- src/dissectLink.js | 4 ++++ src/methods/methods.js | 2 ++ src/methods/vidbleVideo.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/methods/vidbleVideo.js diff --git a/src/dissectLink.js b/src/dissectLink.js index 69a6bcc..13c1981 100644 --- a/src/dissectLink.js +++ b/src/dissectLink.js @@ -30,6 +30,10 @@ const hosts = [{ method: 'vidbleImage', label: 'vidble', pattern: new urlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)') +}, { + method: 'vidbleVideo', + label: 'vidble', + pattern: new urlPattern('http(s)\\://(www.)vidble.com/watch?v=:id') }, { method: 'vidbleAlbum', label: 'vidble', diff --git a/src/methods/methods.js b/src/methods/methods.js index bf111de..a31bab7 100644 --- a/src/methods/methods.js +++ b/src/methods/methods.js @@ -7,6 +7,7 @@ const redditPreview = require('./redditPreview.js'); const imgurImage = require('./imgurImage.js'); const imgurAlbum = require('./imgurAlbum.js'); const vidbleImage = require('./vidbleImage.js'); +const vidbleVideo = require('./vidbleVideo.js'); const vidbleAlbum = require('./vidbleAlbum.js'); const gfycat = require('./gfycat.js'); const eroshareAlbum = require('./eroshareAlbum.js'); @@ -20,6 +21,7 @@ module.exports = { imgurImage, imgurAlbum, vidbleImage, + vidbleVideo, vidbleAlbum, gfycat, eroshareAlbum, diff --git a/src/methods/vidbleVideo.js b/src/methods/vidbleVideo.js new file mode 100644 index 0000000..7b81706 --- /dev/null +++ b/src/methods/vidbleVideo.js @@ -0,0 +1,35 @@ + 'use strict'; + +const util = require('util'); +const config = require('config'); +const fetch = require('node-fetch'); +const cheerio = require('cheerio'); + +function vidbleVideo(post) { + return fetch(`https://www.vidble.com/watch?v=${post.host.id}`).then(res => { + if(res.status !== 200) { + throw new Error(`Could not fetch info for vidble video '${post.host.id}': '${res.error}'`); + } + + return res.text(); + }).then(res => { + const $ = cheerio.load(res); + const resource = $('video source'); + const source = resource.attr('src'); + const type = resource.attr('type'); + + return { + album: null, + items: [{ + id: post.host.id, + url: `https://vidble.com/${source}`, + title: post.title, + datetime: post.datetime, + type: type, + original: post + }] + }; + }); +}; + +module.exports = vidbleVideo;