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

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:56 +02:00
parent e950a9ac54
commit 91550406fe
4 changed files with 30 additions and 21 deletions

View File

@ -76,6 +76,7 @@ function fetchSavePosts(userPosts, ep) {
async function initApp() {
try {
klsjdflkjs
const userPosts = await getCompleteUserPosts();
const ep = new exiftool.ExiftoolProcess(exiftoolBin);
@ -87,8 +88,12 @@ 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}'.`);
}
} catch (error) {
if (args.debug) {
console.log('\x1b[31m%s\x1b[0m', error.stack);
} else {
console.log('\x1b[31m%s\x1b[0m', error.message);
}
}
return true;
}

View File

@ -1,74 +1,78 @@
'use strict';
const urlPattern = require('url-pattern');
const UrlPattern = require('url-pattern');
const hosts = [{
method: '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',
label: 'reddit',
pattern: new urlPattern('http(s)\\://i.redd.it/:id.:ext')
pattern: new UrlPattern('http(s)\\://i.redd.it/:id.:ext'),
}, {
method: 'redditImage',
label: 'reddit',
pattern: new urlPattern('http(s)\\://i.reddituploads.com/:id(?*)')
pattern: new UrlPattern('http(s)\\://i.reddituploads.com/:id(?*)'),
}, {
method: 'redditVideo',
label: 'reddit',
pattern: new urlPattern('http(s)\\://v.redd.it/:id')
pattern: new UrlPattern('http(s)\\://v.redd.it/:id'),
}, {
method: 'imgurImage',
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',
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',
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',
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',
label: 'vidble',
pattern: new urlPattern('http(s)\\://(www.)vidble.com/album/:id')
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/album/:id'),
}, {
method: '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',
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',
label: 'eroshare',
pattern: new urlPattern('http(s)\\://eroshare.com/:id(#)(:query)')
pattern: new UrlPattern('http(s)\\://eroshare.com/:id(#)(:query)'),
}, {
method: 'eroshareItem',
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) {
return hosts.reduce((acc, host) => {
if(acc) {
if (acc) {
return acc;
}
const match = host.pattern.match(url.replace(/(https?:\/\/)|(\/)+/g, '$1$2')); // remove double slashes
if(match) {
if (match) {
return Object.assign(match, {
url: url,
url,
method: host.method,
label: host.label
label: host.label,
});
}

View File

@ -9,7 +9,7 @@ async function imgurAlbum(post) {
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}'`);
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];

View File

@ -7,7 +7,7 @@ async function imgurImage(post) {
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}'`);
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];