Fixed gfycat fetching.

This commit is contained in:
ThePendulum 2018-12-26 15:47:45 +01:00
parent 8ed5812d44
commit 727a25e61b
2 changed files with 33 additions and 1 deletions

32
src/methods/erome.js Normal file
View File

@ -0,0 +1,32 @@
'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const base = 'https://www.erome.com/';
function erome(post) {
return fetch(`${base}a/${post.host.id}`).then(res => {
if(res.ok) {
return res.text();
}
throw new Error(`Unable to retrieve info for Erome album '${post.host.id}' :(`);
}).then(res => {
const $ = cheerio.load(res);
const videoUrls = $('video').toArray().map(videoEl => {
const sourceHd = $(videoEl).find('source[label="HD"]');
const sourceSd = $(videoEl).find('source[label="SD"]');
console.log(sourceHd.attr('src'));
return sourceHd ? base + sourceHd.attr('src') : base + sourceSd.attr('src');
});
console.log(videoUrls);
});
};
module.exports = erome;

View File

@ -3,7 +3,7 @@
const fetch = require('node-fetch');
async function gfycat(post) {
const res = await fetch(`https://gfycat.com/cajax/get/${post.host.id}`);
const res = await fetch(`https://api.gfycat.com/v1/gfycats/${post.host.id}`);
const data = await res.json();
if (data.error) {