From 3d54944067c808bce4f5505a913b20e240208c27 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 11 Sep 2024 05:16:53 +0200 Subject: [PATCH] Added draft Eroshare archive support. Methods return date objects instead of Unix timestamp strings. --- curate.js | 2 +- methods/eroshare.js | 37 +++++++++++++++++++------------------ methods/gfycat.js | 2 +- methods/imgurAlbum.js | 6 +++--- methods/imgurImage.js | 6 +++--- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/curate.js b/curate.js index 98349e6..bc07ec8 100644 --- a/curate.js +++ b/curate.js @@ -12,7 +12,7 @@ function curate(submissions) { user: submission.author.name, permalink: submission.permalink, url: submission.url, - datetime: submission.created_utc * 1000, + datetime: new Date(submission.created_utc * 1000), subreddit: submission.subreddit.display_name, host: dissectLink(submission.url) }; diff --git a/methods/eroshare.js b/methods/eroshare.js index dee277e..4d1680e 100644 --- a/methods/eroshare.js +++ b/methods/eroshare.js @@ -3,7 +3,6 @@ const util = require('util'); const config = require('config'); const fetch = require('node-fetch'); -const cheerio = require('cheerio'); function eroshare(post) { return fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${post.host.id}`).then(res => { @@ -13,26 +12,28 @@ function eroshare(post) { return Promise.reject(`Unable to recover Eroshare video '${post.host.id}' :(`); }).then(res => { - const $ = cheerio.load(res); + const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1)); - $('video').forEach(video => { - console.log(video); - }); - - /* return { - album: null, - items: [{ - id: res.gfyItem.gfyName, - url: res.gfyItem.webmUrl, - title: res.gfyItem.title, - description: res.gfyItem.description, - type: 'video/webm', - datetime: res.gfyItem.createDate * 1000, - original: res.gfyItem - }] + album: { + id: data.slug, + title: data.title, + datetime: new Date(data.created_at) + }, + items: data.items.map(item => { + return { + id: item.slug, + url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4, + title: data.title, + description: item.description, + type: item.type === 'Image' ? 'image/jpeg' : 'video/mp4', + datetime: new Date(data.created_at), + width: data.width, + height: data.height, + original: item + }; + }) }; - */ }).catch(error => { console.log('\x1b[33m%s\x1b[0m', error); }); diff --git a/methods/gfycat.js b/methods/gfycat.js index 84696cf..1746276 100644 --- a/methods/gfycat.js +++ b/methods/gfycat.js @@ -14,7 +14,7 @@ function gfycat(post) { title: res.gfyItem.title, description: res.gfyItem.description, type: 'video/webm', - datetime: res.gfyItem.createDate * 1000, + datetime: new Date(res.gfyItem.createDate * 1000), original: res.gfyItem }] }; diff --git a/methods/imgurAlbum.js b/methods/imgurAlbum.js index 18ddfb6..ee49479 100644 --- a/methods/imgurAlbum.js +++ b/methods/imgurAlbum.js @@ -16,16 +16,16 @@ function imgurAlbum(post) { url: res.data.link, title: res.data.title, description: res.data.description, - datetime: res.data.datetime * 1000, + datetime: new Date(res.data.datetime * 1000), original: res.data }, items: res.data.images.map(item => ({ id: item.id, - url: item.link, + url: item.animated ? item.mp4 : item.link, title: item.title, description: item.description, + type: item.animated ? 'video/mp4' : item.type, datetime: item.datetime * 1000, - type: item.type, original: item })) }; diff --git a/methods/imgurImage.js b/methods/imgurImage.js index 920f8bf..a27c8c9 100644 --- a/methods/imgurImage.js +++ b/methods/imgurImage.js @@ -14,11 +14,11 @@ function imgurImage(post) { album: null, items: [{ id: res.data.id, - url: res.data.link, + url: res.data.animated ? res.data.mp4 : res.data.link, title: res.data.title, description: res.data.description, - type: res.data.type, - datetime: res.data.datetime * 1000, + type: res.data.animated ? 'video/mp4' : res.data.type, + datetime: new Date(res.data.datetime * 1000), original: res.data }] };