Accounting for actualid_d.jpg imgur pattern. Added debug argument to print full stack trace on error.

This commit is contained in:
ThePendulum 2018-07-05 23:27:11 +02:00
parent 2cc15eecd0
commit 160ee9711d
4 changed files with 30 additions and 21 deletions

View File

@ -76,6 +76,7 @@ function fetchSavePosts(userPosts, ep) {
async function initApp() { async function initApp() {
try { try {
klsjdflkjs
const userPosts = await getCompleteUserPosts(); const userPosts = await getCompleteUserPosts();
const ep = new exiftool.ExiftoolProcess(exiftoolBin); const ep = new exiftool.ExiftoolProcess(exiftoolBin);
@ -87,7 +88,11 @@ async function initApp() {
console.log(`[${format(new Date(), 'YYYY-MM-DD HH:mm:ss')}] Watch-mode enabled, checking again for new posts according to crontab '${config.fetch.watch.schedule}'.`); console.log(`[${format(new Date(), 'YYYY-MM-DD HH:mm:ss')}] Watch-mode enabled, checking again for new posts according to crontab '${config.fetch.watch.schedule}'.`);
} }
} catch (error) { } catch (error) {
console.log('\x1b[31m%s\x1b[0m', error.message); if (args.debug) {
console.log('\x1b[31m%s\x1b[0m', error.stack);
} else {
console.log('\x1b[31m%s\x1b[0m', error.message);
}
} }
return true; return true;

View File

@ -1,74 +1,78 @@
'use strict'; 'use strict';
const urlPattern = require('url-pattern'); const UrlPattern = require('url-pattern');
const hosts = [{ const hosts = [{
method: 'self', method: 'self',
label: 'self', label: 'self',
pattern: new urlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/') pattern: new UrlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/'),
}, { }, {
method: 'redditImage', method: 'redditImage',
label: 'reddit', label: 'reddit',
pattern: new urlPattern('http(s)\\://i.redd.it/:id.:ext') pattern: new UrlPattern('http(s)\\://i.redd.it/:id.:ext'),
}, { }, {
method: 'redditImage', method: 'redditImage',
label: 'reddit', label: 'reddit',
pattern: new urlPattern('http(s)\\://i.reddituploads.com/:id(?*)') pattern: new UrlPattern('http(s)\\://i.reddituploads.com/:id(?*)'),
}, { }, {
method: 'redditVideo', method: 'redditVideo',
label: 'reddit', label: 'reddit',
pattern: new urlPattern('http(s)\\://v.redd.it/:id') pattern: new UrlPattern('http(s)\\://v.redd.it/:id'),
}, { }, {
method: 'imgurImage', method: 'imgurImage',
label: 'imgur', label: 'imgur',
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:id(.:ext)(?*)') pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/:id_d(.:ext)(?*)'),
}, {
method: 'imgurImage',
label: 'imgur',
pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/:id(.:ext)(?*)'),
}, { }, {
method: 'imgurAlbum', method: 'imgurAlbum',
label: 'imgur', label: 'imgur',
pattern: new urlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id(#:focus)') pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id(#:focus)'),
}, { }, {
method: 'vidbleImage', method: 'vidbleImage',
label: 'vidble', label: 'vidble',
pattern: new urlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)') pattern: new UrlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)'),
}, { }, {
method: 'vidbleVideo', method: 'vidbleVideo',
label: 'vidble', label: 'vidble',
pattern: new urlPattern('http(s)\\://(www.)vidble.com/watch?v=:id') pattern: new UrlPattern('http(s)\\://(www.)vidble.com/watch?v=:id'),
}, { }, {
method: 'vidbleAlbum', method: 'vidbleAlbum',
label: 'vidble', label: 'vidble',
pattern: new urlPattern('http(s)\\://(www.)vidble.com/album/:id') pattern: new UrlPattern('http(s)\\://(www.)vidble.com/album/:id'),
}, { }, {
method: 'gfycat', method: 'gfycat',
label: 'gfycat', label: 'gfycat',
pattern: new urlPattern('http(s)\\://(:server.)gfycat.com/:id(-size_restricted.gif)') pattern: new UrlPattern('http(s)\\://(:server.)gfycat.com/:id(-size_restricted.gif)'),
}, { }, {
method: 'gfycat', method: 'gfycat',
label: 'gfycat', label: 'gfycat',
pattern: new urlPattern('http(s)\\://(:server.)gfycat.com/(gifs/detail/):id(.:ext)') pattern: new UrlPattern('http(s)\\://(:server.)gfycat.com/(gifs/detail/):id(.:ext)'),
}, { }, {
method: 'eroshareAlbum', method: 'eroshareAlbum',
label: 'eroshare', label: 'eroshare',
pattern: new urlPattern('http(s)\\://eroshare.com/:id(#)(:query)') pattern: new UrlPattern('http(s)\\://eroshare.com/:id(#)(:query)'),
}, { }, {
method: 'eroshareItem', method: 'eroshareItem',
label: 'eroshare', label: 'eroshare',
pattern: new urlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)') pattern: new UrlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)'),
}]; }];
module.exports = function dissectLink(url) { module.exports = function dissectLink(url) {
return hosts.reduce((acc, host) => { return hosts.reduce((acc, host) => {
if(acc) { if (acc) {
return acc; return acc;
} }
const match = host.pattern.match(url.replace(/(https?:\/\/)|(\/)+/g, '$1$2')); // remove double slashes const match = host.pattern.match(url.replace(/(https?:\/\/)|(\/)+/g, '$1$2')); // remove double slashes
if(match) { if (match) {
return Object.assign(match, { return Object.assign(match, {
url: url, url,
method: host.method, method: host.method,
label: host.label label: host.label,
}); });
} }

View File

@ -9,7 +9,7 @@ async function imgurAlbum(post) {
const html = await res.text(); const html = await res.text();
if (res.status !== 200) { 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.statusText}'`);
} }
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1]; const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];

View File

@ -7,7 +7,7 @@ async function imgurImage(post) {
const html = await res.text(); const html = await res.text();
if (res.status !== 200) { 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.statusText}'`);
} }
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1]; const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];