Added mimetype verification option to media source to ensure server returned a plausible file. Added additional fallbacks to Jules Jordan poster scraper for Amateur Allure.
This commit is contained in:
20
src/media.js
20
src/media.js
@@ -99,6 +99,9 @@ function toBaseSource(rawSource) {
|
||||
baseSource.stream = rawSource.stream;
|
||||
}
|
||||
|
||||
// reject source if response mimetype does not match specified type
|
||||
if (rawSource.verifyType) baseSource.verifyType = rawSource.verifyType;
|
||||
|
||||
if (rawSource.referer) baseSource.referer = rawSource.referer;
|
||||
if (rawSource.host) baseSource.host = rawSource.host;
|
||||
if (rawSource.attempts) baseSource.attempts = rawSource.attempts;
|
||||
@@ -441,6 +444,8 @@ streamQueue.define('fetchStreamSource', async ({ source, tempFileTarget, hashStr
|
||||
});
|
||||
|
||||
async function fetchSource(source, baseMedia) {
|
||||
const maxAttempts = source.attempts || 3;
|
||||
|
||||
logger.silly(`Fetching media from ${source.src}`);
|
||||
// attempts
|
||||
|
||||
@@ -470,6 +475,10 @@ async function fetchSource(source, baseMedia) {
|
||||
const [type, subtype] = mimetype.split('/');
|
||||
const extension = mime.getExtension(mimetype);
|
||||
|
||||
if (source.verifyType && source.verifyType !== type) {
|
||||
throw Object.assign(new Error(`Type '${type}' does not match type '${source.verifyType}' specified by source`), { code: 'VERIFY_TYPE' });
|
||||
}
|
||||
|
||||
return {
|
||||
...source,
|
||||
file: {
|
||||
@@ -486,14 +495,15 @@ async function fetchSource(source, baseMedia) {
|
||||
};
|
||||
} catch (error) {
|
||||
hasher.end();
|
||||
const maxAttempts = source.attempts || 3;
|
||||
|
||||
logger.warn(`Failed attempt ${attempts}/${maxAttempts} to fetch ${source.src}: ${error.message}`);
|
||||
if (error.code !== 'VERIFY_TYPE') {
|
||||
logger.warn(`Failed attempt ${attempts}/${maxAttempts} to fetch ${source.src}: ${error.message}`);
|
||||
|
||||
if (attempts < maxAttempts) {
|
||||
await Promise.delay(1000);
|
||||
if (attempts < maxAttempts) {
|
||||
await Promise.delay(1000);
|
||||
|
||||
return attempt(attempts + 1);
|
||||
return attempt(attempts + 1);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Failed to fetch ${source.src}: ${error.message}`);
|
||||
|
||||
@@ -160,10 +160,22 @@ function scrapeAll(scenes, site, entryIdFromTitle) {
|
||||
{
|
||||
src: prefixedSrc.replace(/.jpg$/, '-full.jpg'),
|
||||
referer: site.url,
|
||||
verifyType: 'image', // sometimes returns 200 OK with text/html instead of 403
|
||||
},
|
||||
{
|
||||
src: prefixedSrc.replace(/-1x.jpg$/, '-4x.jpg'),
|
||||
referer: site.url,
|
||||
verifyType: 'image',
|
||||
},
|
||||
{
|
||||
src: prefixedSrc.replace(/-1x.jpg$/, '-2x.jpg'),
|
||||
referer: site.url,
|
||||
verifyType: 'image',
|
||||
},
|
||||
{
|
||||
src: prefixedSrc,
|
||||
referer: site.url,
|
||||
verifyType: 'image',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user