Fixed RedGIFs gallery support.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:59 +02:00
parent cedecc273a
commit d1ac6d0068
3 changed files with 21 additions and 10 deletions

View File

@ -61,7 +61,7 @@ const hosts = [
{
method: 'redgifs',
label: 'redgifs',
pattern: new UrlPattern('http(s)\\://(:subdomain.)redgifs.com(/watch)/(:id-mobile)(:id)(.:ext)(?*)'),
pattern: new UrlPattern('http(s)\\://(:subdomain.)redgifs.com(/watch)(/i)/(:id-mobile)(:id)(.:ext)(?*)'),
},
{
method: 'erome',

View File

@ -177,7 +177,7 @@ async function fetchSaveDirectContent(content, host, ep) {
}
const filepath = getFilepath(item, content, host, null, null);
const sourcePaths = await save(filepath, buffers, item, null);
const sourcePaths = await save(filepath, buffers.map(({ buffer }) => buffer), item, null);
if (item.mux) {
await mux(filepath, sourcePaths, item);

View File

@ -27,10 +27,10 @@ async function fetchPredata() {
return null;
}
function scrapeGallery(data) {
function scrapeGallery(data, { predata }) {
const oldestDate = Math.min(...data.gifs.map((gif) => gif.createDate));
return {
const curated = {
album: {
id: data.id,
datetime: new Date(oldestDate * 1000),
@ -39,22 +39,33 @@ function scrapeGallery(data) {
id: gif.id,
url: gif.urls.hd,
description: gif.tags.join(', '),
type: mime.getType(gif.urls.hd),
type: mime.getType(new URL(gif.urls.hd).pathname.slice(1)),
datetime: new Date(gif.createDate * 1000),
original: gif,
})),
headers: {
'user-agent': predata.agent,
},
};
return curated;
}
async function fetchGallery(galleryId) {
const res = await fetch(`https://api.redgifs.com/v2/gallery/${galleryId}`);
async function fetchGallery(galleryId, { predata }) {
const res = await fetch(`https://api.redgifs.com/v2/gallery/${galleryId}`, {
headers: {
authorization: `Bearer ${predata.token}`,
'user-agent': predata.agent,
},
});
const data = await res.json();
if (!data.gifs) {
return null;
}
return scrapeGallery(data);
return scrapeGallery(data, { predata });
}
async function redgifsApi(host, post, { predata }) {
@ -76,7 +87,7 @@ async function redgifsApi(host, post, { predata }) {
}
if (data.id && data.gifs) {
return scrapeGallery(data);
return scrapeGallery(data, { predata });
}
if (!data.gif) {
@ -84,7 +95,7 @@ async function redgifsApi(host, post, { predata }) {
}
if (data.gif.gallery) {
return fetchGallery(data.gif.gallery);
return fetchGallery(data.gif.gallery, { predata });
}
const curated = {