From eeb947d3117864abfcd3cc5a7496ab2a61751f86 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 28 Aug 2023 02:53:35 +0200 Subject: [PATCH] Catching media store fail unlink error to prevent batch failure. --- assets/components/releases/banner.vue | 1 + src/media.js | 14 +++++++++----- src/scrapers/radical.js | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/assets/components/releases/banner.vue b/assets/components/releases/banner.vue index afee58e5..aea9dd97 100755 --- a/assets/components/releases/banner.vue +++ b/assets/components/releases/banner.vue @@ -172,6 +172,7 @@ function photos() { const photosWithClipPosters = (this.release.photos || []).concat(this.release.caps || []).concat(this.release.scenesPhotos || []).concat(uniqueClipPosters); if (this.release.trailer || (this.release.teaser && this.release.teaser.mime !== 'image/gif')) { + // if (this.release.trailer) { // poster will be on trailer video return photosWithClipPosters; } diff --git a/src/media.js b/src/media.js index ffc91fbc..b8d95bf9 100755 --- a/src/media.js +++ b/src/media.js @@ -426,11 +426,11 @@ async function writeImage(image, media, info, filepath, isProcessed) { async function writeThumbnail(image, thumbpath) { return image + .jpeg({ quality: config.media.thumbnailQuality }) .resize({ height: config.media.thumbnailSize, withoutEnlargement: true, }) - .jpeg({ quality: config.media.thumbnailQuality }) .rotate() .toFile(path.join(config.media.path, thumbpath)); } @@ -463,7 +463,7 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil fsPromises.mkdir(path.join(config.media.path, lazydir), { recursive: true }), ]); - const image = sharp(media.file.path, { pages: -1 }); + const image = sharp(media.file.path, { pages: ['trailer', 'teaser'].includes(media.role) ? -1 : 1 }); // don't store posters as animation const isProcessed = media.meta.subtype !== 'jpeg' || media.process; const [info, stats] = await Promise.all([ @@ -490,8 +490,8 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil await writeImage(image, media, info, filepath, isProcessed); await Promise.all([ - writeThumbnail(image, thumbpath), - writeLazy(image, lazypath), + writeThumbnail(image, thumbpath, info), + writeLazy(image, lazypath, info), ]); /* @@ -603,7 +603,11 @@ async function storeFile(media, options) { } catch (error) { logger.warn(`Failed to store ${media.src}: ${error.message}`); - await fsPromises.unlink(media.file.path); + try { + await fsPromises.unlink(media.file.path); + } catch (unlinkError) { + logger.warn(`Failed to unlink ${media.file.path} from ${media.src}: ${unlinkError.message}`); + } return null; } diff --git a/src/scrapers/radical.js b/src/scrapers/radical.js index ea12d4bb..16a8bd95 100755 --- a/src/scrapers/radical.js +++ b/src/scrapers/radical.js @@ -1,13 +1,14 @@ 'use strict'; const unprint = require('unprint'); +const mime = require('mime'); const http = require('../utils/http'); const qu = require('../utils/qu'); const slugify = require('../utils/slugify'); const { lbsToKg, feetInchesToCm } = require('../utils/convert'); -const teaserOrder = ['large', 'small', 'mobile']; +const teaserOrder = ['large', 'small', 'mobile', 'mp4', 'jpg']; function scrapeSceneMetadata(data, channel) { const release = {}; @@ -71,7 +72,16 @@ function scrapeSceneApi(data, channel, parameters) { avatar: actor.thumb, })) || data.models; - release.poster = data.trailer_screencap || data.thumb; + release.poster = data.trailer_screencap; + + if (mime.getType(data.thumb) !== 'image/gif') { + release.teaser = data.thumb; + } else { + release.poster = [ + release.poster, + data.thumb, + ]; + } release.photos = [ ...data.previews?.full || [],