Browse Source

bitchute: redo with oembed URL

master
vampirefrog 2 years ago
parent
commit
43e144000f
  1. 53
      bitchute.js

53
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(/<span class="video-views"><i class="far fa-eye"><\/i> ([0-9]+)<\/span>/);
let duration = html.match(/<span class="video-duration">([0-9:]+)<\/span>/);
let title = html.match(/<h1 id="video-title" class="page-title">(.*?)<\/h1>/);
let channel = html.match(/<p class="video-card-channel"><a href="([^"]+)" class="spa">(.*?)<\/a><\/p>/);
let publishDate = html.match(/<div class="video-publish-date">\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(/<span class="video-views"><i class="far fa-eye"><\/i> ([0-9]+)<\/span>/);
let publishDate = html.match(/<div class="video-publish-date">\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);
});
}
}

Loading…
Cancel
Save