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', method: 'redgifs',
label: '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', method: 'erome',

View File

@ -177,7 +177,7 @@ async function fetchSaveDirectContent(content, host, ep) {
} }
const filepath = getFilepath(item, content, host, null, null); 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) { if (item.mux) {
await mux(filepath, sourcePaths, item); await mux(filepath, sourcePaths, item);

View File

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