No longer using imgur API for individual images. Only saving EXIF data to JPEGs. Always using global exiftool instance.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:56 +02:00
parent b05ae06b00
commit dbc4c45601
4 changed files with 37 additions and 47 deletions

View File

@ -28,6 +28,10 @@ async function getStreams(item, post) {
} }
async function addMeta(filepath, item, post, user, ep) { async function addMeta(filepath, item, post, user, ep) {
if (item.type !== 'image/jpeg') {
return false;
}
const meta = Object.entries(config.library.meta).reduce((acc, [key, value]) => { const meta = Object.entries(config.library.meta).reduce((acc, [key, value]) => {
const interpolatedValue = interpolate(value, user, post, item); const interpolatedValue = interpolate(value, user, post, item);
@ -35,8 +39,10 @@ async function addMeta(filepath, item, post, user, ep) {
}, {}); }, {});
if (Object.keys(meta).length > 0) { if (Object.keys(meta).length > 0) {
await saveMeta(filepath, meta, ep); return saveMeta(filepath, meta, ep);
} }
return false;
} }
function getFilepath(item, post, user) { function getFilepath(item, post, user) {

View File

@ -36,7 +36,7 @@ function imgurAlbum(post) {
title: item.title || (extract ? res.data.title : null), title: item.title || (extract ? res.data.title : null),
description: item.description || (extract ? res.data.description : null), description: item.description || (extract ? res.data.description : null),
type: item.animated ? 'video/mp4' : item.type, type: item.animated ? 'video/mp4' : item.type,
datetime: item.datetime * 1000, datetime: new Date(item.datetime * 1000),
original: item original: item
})) }))
}; };

View File

@ -1,32 +1,31 @@
'use strict'; 'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
function imgurImage(post) { async function imgurImage(post) {
return fetch(`https://api.imgur.com/3/image/${post.host.id}`, { const res = await fetch(`https://imgur.com/${post.host.id}`);
headers: { const html = await res.text();
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
} if (res.status !== 200) {
}).then(res => res.json()).then(res => {
if(res.status !== 200) {
throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`); throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`);
} }
return { const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
const data = JSON.parse(dataString);
const item = {
album: null, album: null,
items: [{ items: [{
id: res.data.id, id: data.hash,
url: res.data.animated ? res.data.mp4 : res.data.link, url: data.animated ? `https://i.imgur.com/${post.host.id}.mp4` : `https://i.imgur.com/${post.host.id}${data.ext}`,
title: res.data.title, title: data.title,
description: res.data.description, description: data.description,
type: res.data.animated ? 'video/mp4' : res.data.type, type: data.animated ? 'video/mp4' : data.mimetype,
datetime: new Date(res.data.datetime * 1000), datetime: new Date(data.timestamp || data.datetime),
original: res.data }],
}]
}; };
});
}; return item;
}
module.exports = imgurImage; module.exports = imgurImage;

View File

@ -1,24 +1,9 @@
'use strict'; 'use strict';
const exiftool = require('node-exiftool'); async function saveMeta(filepath, meta, ep) {
const exiftoolBin = require('dist-exiftool'); await ep.writeMetadata(filepath, meta, ['overwrite_original']);
function saveMeta(filepath, meta, globalExifTool) {
const ep = globalExifTool || new exiftool.ExiftoolProcess(exiftoolBin);
return Promise.resolve().then(() => {
if(!globalExifTool) {
return ep.open();
}
}).then(() => {
return ep.writeMetadata(filepath, meta, ['overwrite_original']);
}).then(() => {
console.log('\x1b[36m%s\x1b[0m', `Wrote metadata to '${filepath}'`); console.log('\x1b[36m%s\x1b[0m', `Wrote metadata to '${filepath}'`);
}).then(() => { }
if(!globalExifTool) {
return ep.close();
}
});
};
module.exports = saveMeta; module.exports = saveMeta;