Improved handling of failed video stream fetching. Added proper Little Caprice album URL retrieval.

This commit is contained in:
DebaucheryLibrarian 2026-02-02 02:44:51 +01:00
parent 7f2b1e03ff
commit 27bf48eb05
2 changed files with 49 additions and 19 deletions

View File

@ -672,22 +672,31 @@ async function fetchHttpSource(source, tempFileTarget, hashStream) {
streamQueue.define('fetchStreamSource', async ({ source, tempFileTarget, hashStream }) => { streamQueue.define('fetchStreamSource', async ({ source, tempFileTarget, hashStream }) => {
const meta = { mimetype: 'video/mp4' }; const meta = { mimetype: 'video/mp4' };
const video = ffmpeg(source.stream) const command = ffmpeg(source.stream)
.format('mp4') .format('mp4')
.outputOptions(['-movflags frag_keyframe+empty_moov']) .outputOptions(['-movflags frag_keyframe+empty_moov'])
.on('start', (cmd) => logger.verbose(`Fetching stream from ${source.stream} with "${cmd}"`)) .on('start', (cmd) => logger.verbose(`Fetching stream from ${source.stream} with "${cmd}"`));
.on('error', (error) => {
const video = command.pipe();
await Promise.all([
stream.promises.pipeline(video, hashStream, tempFileTarget),
new Promise((resolve, reject) => {
command.on('error', (error) => {
logger.error(`Failed to fetch stream from ${source.stream}: ${error.message}`); logger.error(`Failed to fetch stream from ${source.stream}: ${error.message}`);
hashStream.end(); hashStream.end();
tempFileTarget.end(); tempFileTarget.end();
})
.pipe();
// await pipeline(video, hashStream, tempFileTarget); reject(error);
await stream.promises.pipeline(video, hashStream, tempFileTarget); });
command.on('end', () => {
logger.verbose(`Finished fetching stream from ${source.stream}`); logger.verbose(`Finished fetching stream from ${source.stream}`);
resolve();
});
}),
]);
return meta; return meta;
}, { }, {

View File

@ -82,14 +82,37 @@ async function fetchLatest(channel) {
return res.status; return res.status;
} }
async function attachPhotos(url, release) { async function fetchAlbumUrl(sceneUrl) {
if (url) { // Upjax-Action query is redundant, but imitates original request
const res = await unprint.get(url); const res = await unprint.get(`${sceneUrl}?endpoint_request_timestamp=${Math.floor(Date.now() / 1000)}&Upjax-Action=lcd.project.actions`, {
headers: {
Referer: sceneUrl,
'Upjax-Action': 'lcd.project.actions',
'Upjax-Method': 'GET',
},
});
if (res.ok) {
const albumUrl = res.data.js?.match(/"(https.*?)"/)?.[1];
if (albumUrl) {
return albumUrl;
}
}
return null;
}
async function attachPhotos(sceneUrl, release) {
const albumUrl = await fetchAlbumUrl(sceneUrl);
if (albumUrl) {
const res = await unprint.get(albumUrl);
if (res.ok) { if (res.ok) {
release.photos = res.context.query.imgs('.gallery img').map((imgUrl) => ({ // eslint-disable-line no-param-reassign release.photos = res.context.query.imgs('.gallery img').map((imgUrl) => ({ // eslint-disable-line no-param-reassign
src: imgUrl, src: imgUrl,
referer: url, referer: sceneUrl,
})); }));
release.photoCount = res.context.query.number('.image-amount'); // eslint-disable-line no-param-reassign release.photoCount = res.context.query.number('.image-amount'); // eslint-disable-line no-param-reassign
@ -126,7 +149,7 @@ async function scrapeScene({ query }, { url, include }) {
}; };
if (include.photos) { if (include.photos) {
await attachPhotos(url.replace(/(\/)?$/, '-2$1'), release); await attachPhotos(url, release);
} }
const trailerFrame = query.url('.video iframe', { attribute: 'src' }); const trailerFrame = query.url('.video iframe', { attribute: 'src' });
@ -134,14 +157,12 @@ async function scrapeScene({ query }, { url, include }) {
if (trailerId) { if (trailerId) {
release.trailer = { release.trailer = {
stream: `https://trailer.littlecaprice-dreams.com/${trailerId}/1920x1080/video.m3u8`, stream: `https://trailer.littlecaprice-dreams.com/${trailerId}/playlist.m3u8`,
quality: 1080, quality: 1080,
referer: url, referer: url,
}; };
} }
console.log(release.trailer);
const channelSlug = slugify(query.content('.project-tags a[href*="collection/"]'), ''); const channelSlug = slugify(query.content('.project-tags a[href*="collection/"]'), '');
release.channel = channelMap[channelSlug] || channelSlug; release.channel = channelMap[channelSlug] || channelSlug;