From 43e144000ff4a6e7ecb1a3d4f223cf2f878c8c52 Mon Sep 17 00:00:00 2001 From: vampirefrog Date: Wed, 10 Feb 2021 22:03:49 +0200 Subject: [PATCH] bitchute: redo with oembed URL --- bitchute.js | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/bitchute.js b/bitchute.js index 825e1cd..376b4c5 100644 --- a/bitchute.js +++ b/bitchute.js @@ -25,32 +25,45 @@ class BitChute extends SongProvider { } getInfo(url, cb) { - url = this.getCanonicalUrl(url); - - fetch(url) - .then((response) => { return response.text(); } ) - .then((html) => { - let views = html.match(/<\/i> ([0-9]+)<\/span>/); - let duration = html.match(/([0-9:]+)<\/span>/); - let title = html.match(/

(.*?)<\/h1>/); - let channel = html.match(/

(.*?)<\/a><\/p>/); - let publishDate = html.match(/

\s*First published at (.*?)\s*<\/div>/); - let thumbnail = html.match(/poster="([^"]+)"/); + let canonicalUrl = this.getCanonicalUrl(url); + + let oembedUrl = 'https://www.bitchute.com/oembed/?url='+encodeURIComponent(canonicalUrl)+'&format=json'; + + // the OEmbed URL works even when the video is banned in my country + fetch(oembedUrl) + .then((response) => { return response.json(); } ) + .then((json) => { var ret = { platform: 'bitchute', - url: url, - title: title && title[1] || null, - thumbnail: thumbnail && thumbnail[1] || null, + title: json.title, + url: canonicalUrl, + author: json.author_name, + author_url: json.author_url, + thumbnail: json.thumbnail_url, duration: null, - publishDate: publishDate && publishDate[1] || null, - views: views && parseInt(views[1]) || null, - channelUrl: channel && channel[1] || null, - channel: channel && channel[2] || null, + width: parseInt(json.width), + height: parseInt(json.height), }; - cb(null, ret); + // try to complete the info that the OEmbed URL doesn't give us + // this info might be unavailable in my country + // so if there's a problem we resolve with just the OEmbed data + fetch(canonicalUrl) + .then((response) => { return response.text(); }) + .then((html) => { + let views = html.match(/<\/i> ([0-9]+)<\/span>/); + let publishDate = html.match(/
\s*First published at (.*?)\s*<\/div>/); + ret.views = views && parseInt(views[1]) || null, + ret.publishDate = publishDate && publishDate[1] || null, + cb(null, ret); + }) + .catch((e) => { + cb(null, ret); + }); }) - .catch((e) => { cb('Error reading Bitchute Info: '+e); }); + .catch((e) => { + cb('Error reading Bitchute Info: '+e); + }); } }