diff --git a/src/dissectLink.js b/src/dissectLink.js index 31e2193..061d057 100644 --- a/src/dissectLink.js +++ b/src/dissectLink.js @@ -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', diff --git a/src/fetch/content.js b/src/fetch/content.js index a1ec16d..a03d166 100644 --- a/src/fetch/content.js +++ b/src/fetch/content.js @@ -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); diff --git a/src/methods/redgifs.js b/src/methods/redgifs.js index 8fc6cf3..688cb0c 100644 --- a/src/methods/redgifs.js +++ b/src/methods/redgifs.js @@ -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 = {