Compare commits

...

2 Commits

Author SHA1 Message Date
ThePendulum 135fb372f5 1.27.2 2023-06-05 04:11:37 +02:00
ThePendulum da8ffc0025 Fixed RedGIFs gallery support. 2023-06-05 04:11:34 +02:00
5 changed files with 24 additions and 13 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "ripunzel", "name": "ripunzel",
"version": "1.27.1", "version": "1.27.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ripunzel", "name": "ripunzel",
"version": "1.27.1", "version": "1.27.2",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"array.prototype.flatten": "^1.2.1", "array.prototype.flatten": "^1.2.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "ripunzel", "name": "ripunzel",
"version": "1.27.1", "version": "1.27.2",
"description": "Web content archiving tool, with versatile filename patterns and extensive options for reddit user profiles.", "description": "Web content archiving tool, with versatile filename patterns and extensive options for reddit user profiles.",
"main": "app.js", "main": "app.js",
"scripts": { "scripts": {

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 = {