No longer relying on imgur API for albums. Removed config for imgur API. Fixed ?#0 URLs not being detected for imgur.
This commit is contained in:
parent
f5382ddc37
commit
2cc15eecd0
|
@ -67,9 +67,4 @@ module.exports = {
|
||||||
scope: 'history identity mysubreddits read subscribe',
|
scope: 'history identity mysubreddits read subscribe',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
|
||||||
imgur: {
|
|
||||||
clientId: '1234567abcdefgh',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,7 @@ const hosts = [{
|
||||||
}, {
|
}, {
|
||||||
method: 'imgurAlbum',
|
method: 'imgurAlbum',
|
||||||
label: 'imgur',
|
label: 'imgur',
|
||||||
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id')
|
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id(#:focus)')
|
||||||
}, {
|
}, {
|
||||||
method: 'vidbleImage',
|
method: 'vidbleImage',
|
||||||
label: 'vidble',
|
label: 'vidble',
|
||||||
|
|
|
@ -1,46 +1,40 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const mime = require('mime-types');
|
||||||
|
|
||||||
|
async function imgurAlbum(post) {
|
||||||
|
const res = await fetch(`https://imgur.com/a/${post.host.id}`);
|
||||||
|
const html = await res.text();
|
||||||
|
|
||||||
function imgurAlbum(post) {
|
|
||||||
return fetch(`https://api.imgur.com/3/album/${post.host.id}`, {
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
|
|
||||||
}
|
|
||||||
}).then(res => res.json()).then(res => {
|
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
throw new Error(`Could not fetch info for imgur album '${post.host.id}': '${res.data.error}'`);
|
throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.data.error}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const extract = config.library.album.extractSingleItem && res.data.images.length === 1;
|
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
|
||||||
|
const data = JSON.parse(dataString);
|
||||||
|
|
||||||
if(extract) {
|
const extract = config.library.album.extractSingleItem && data.album_images.images.length === 1;
|
||||||
console.log('\x1b[36m%s\x1b[0m', `Extracting single item from album '${post.title}' - ${res.data.link}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
album: extract ? null : {
|
album: extract ? null : {
|
||||||
id: res.data.id,
|
id: data.id,
|
||||||
url: res.data.link,
|
url: `https://imgur.com/a/${post.host.id}`,
|
||||||
title: res.data.title,
|
title: data.title,
|
||||||
description: res.data.description,
|
description: data.description,
|
||||||
datetime: new Date(res.data.datetime * 1000),
|
datetime: new Date(data.datetime),
|
||||||
original: res.data
|
|
||||||
},
|
},
|
||||||
items: res.data.images.map(item => ({
|
items: data.album_images.images.map(item => ({
|
||||||
extracted: extract,
|
extracted: extract,
|
||||||
id: item.id,
|
id: item.hash,
|
||||||
url: item.animated ? item.mp4 : item.link,
|
url: data.animated ? `https://i.imgur.com/${item.hash}.mp4` : `https://i.imgur.com/${item.hash}${item.ext}`,
|
||||||
title: item.title || (extract ? res.data.title : null),
|
title: item.title || (extract ? data.title : null),
|
||||||
description: item.description || (extract ? res.data.description : null),
|
description: item.description || (extract ? data.description : null),
|
||||||
type: item.animated ? 'video/mp4' : item.type,
|
type: item.animated ? 'video/mp4' : mime.lookup(item.ext.split('?')[0]),
|
||||||
datetime: new Date(item.datetime * 1000),
|
datetime: new Date(item.datetime),
|
||||||
original: item
|
})),
|
||||||
}))
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = imgurAlbum;
|
module.exports = imgurAlbum;
|
||||||
|
|
|
@ -13,7 +13,7 @@ async function imgurImage(post) {
|
||||||
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
|
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
|
||||||
const data = JSON.parse(dataString);
|
const data = JSON.parse(dataString);
|
||||||
|
|
||||||
const item = {
|
return {
|
||||||
album: null,
|
album: null,
|
||||||
items: [{
|
items: [{
|
||||||
id: data.hash,
|
id: data.hash,
|
||||||
|
@ -24,8 +24,6 @@ async function imgurImage(post) {
|
||||||
datetime: new Date(data.timestamp || data.datetime),
|
datetime: new Date(data.timestamp || data.datetime),
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = imgurImage;
|
module.exports = imgurImage;
|
||||||
|
|
Loading…
Reference in New Issue