From c21ca0df0ce7c7c722a1f0b736016ccf6d5c4773 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:57 +0200 Subject: [PATCH] Fixed gfycat fetching. --- src/methods/erome.js | 32 ++++++++++++++++++++++++++++++++ src/methods/gfycat.js | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/methods/erome.js diff --git a/src/methods/erome.js b/src/methods/erome.js new file mode 100644 index 0000000..c2a93b5 --- /dev/null +++ b/src/methods/erome.js @@ -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; diff --git a/src/methods/gfycat.js b/src/methods/gfycat.js index 4383d92..5972ae6 100644 --- a/src/methods/gfycat.js +++ b/src/methods/gfycat.js @@ -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) {