No longer using imgur API for individual images. Only saving EXIF data to JPEGs. Always using global exiftool instance.
This commit is contained in:
parent
b05ae06b00
commit
dbc4c45601
|
@ -28,6 +28,10 @@ async function getStreams(item, post) {
|
|||
}
|
||||
|
||||
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 interpolatedValue = interpolate(value, user, post, item);
|
||||
|
||||
|
@ -35,8 +39,10 @@ async function addMeta(filepath, item, post, user, ep) {
|
|||
}, {});
|
||||
|
||||
if (Object.keys(meta).length > 0) {
|
||||
await saveMeta(filepath, meta, ep);
|
||||
return saveMeta(filepath, meta, ep);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getFilepath(item, post, user) {
|
||||
|
|
|
@ -36,7 +36,7 @@ function imgurAlbum(post) {
|
|||
title: item.title || (extract ? res.data.title : null),
|
||||
description: item.description || (extract ? res.data.description : null),
|
||||
type: item.animated ? 'video/mp4' : item.type,
|
||||
datetime: item.datetime * 1000,
|
||||
datetime: new Date(item.datetime * 1000),
|
||||
original: item
|
||||
}))
|
||||
};
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
'use strict';
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function imgurImage(post) {
|
||||
return fetch(`https://api.imgur.com/3/image/${post.host.id}`, {
|
||||
headers: {
|
||||
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
||||
}
|
||||
}).then(res => res.json()).then(res => {
|
||||
if(res.status !== 200) {
|
||||
async function imgurImage(post) {
|
||||
const res = await fetch(`https://imgur.com/${post.host.id}`);
|
||||
const html = await res.text();
|
||||
|
||||
if (res.status !== 200) {
|
||||
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,
|
||||
items: [{
|
||||
id: res.data.id,
|
||||
url: res.data.animated ? res.data.mp4 : res.data.link,
|
||||
title: res.data.title,
|
||||
description: res.data.description,
|
||||
type: res.data.animated ? 'video/mp4' : res.data.type,
|
||||
datetime: new Date(res.data.datetime * 1000),
|
||||
original: res.data
|
||||
}]
|
||||
id: data.hash,
|
||||
url: data.animated ? `https://i.imgur.com/${post.host.id}.mp4` : `https://i.imgur.com/${post.host.id}${data.ext}`,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
type: data.animated ? 'video/mp4' : data.mimetype,
|
||||
datetime: new Date(data.timestamp || data.datetime),
|
||||
}],
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
module.exports = imgurImage;
|
||||
|
|
|
@ -1,24 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
const exiftool = require('node-exiftool');
|
||||
const exiftoolBin = require('dist-exiftool');
|
||||
async function saveMeta(filepath, meta, ep) {
|
||||
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}'`);
|
||||
}).then(() => {
|
||||
if(!globalExifTool) {
|
||||
return ep.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = saveMeta;
|
||||
|
|
Loading…
Reference in New Issue