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

View File

@ -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
}))
};

View File

@ -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) {
throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`);
}
async function imgurImage(post) {
const res = await fetch(`https://imgur.com/${post.host.id}`);
const html = await res.text();
return {
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
}]
};
});
};
if (res.status !== 200) {
throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`);
}
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
const data = JSON.parse(dataString);
const item = {
album: null,
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;

View File

@ -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();
}
});
};
console.log('\x1b[36m%s\x1b[0m', `Wrote metadata to '${filepath}'`);
}
module.exports = saveMeta;