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

This commit is contained in:
ThePendulum 2018-07-05 02:00:45 +02:00
parent 5dce74588b
commit f5382ddc37
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}`
}
}).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}'`);
}
return { if (res.status !== 200) {
album: null, throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`);
items: [{ }
id: res.data.id,
url: res.data.animated ? res.data.mp4 : res.data.link, const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
title: res.data.title, const data = JSON.parse(dataString);
description: res.data.description,
type: res.data.animated ? 'video/mp4' : res.data.type, const item = {
datetime: new Date(res.data.datetime * 1000), album: null,
original: res.data items: [{
}] 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; 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) { console.log('\x1b[36m%s\x1b[0m', `Wrote metadata to '${filepath}'`);
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; module.exports = saveMeta;