mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-31 19:59:31 -05:00
Compare commits
2 Commits
renovate/d
...
preview-fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
461ed7e5d3 | ||
|
|
308f60ac46 |
@@ -33,11 +33,32 @@ import { EventSubscriber } from 'typeorm';
|
|||||||
export class MediaRequestSubscriber
|
export class MediaRequestSubscriber
|
||||||
implements EntitySubscriberInterface<MediaRequest>
|
implements EntitySubscriberInterface<MediaRequest>
|
||||||
{
|
{
|
||||||
private async notifyAvailableMovie(entity: MediaRequest) {
|
private async notifyAvailableMovie(
|
||||||
if (
|
entity: MediaRequest,
|
||||||
entity.media[entity.is4k ? 'status4k' : 'status'] ===
|
event?: UpdateEvent<MediaRequest>
|
||||||
MediaStatus.AVAILABLE
|
|
||||||
) {
|
) {
|
||||||
|
// Get fresh media state using event manager
|
||||||
|
let latestMedia: Media | null = null;
|
||||||
|
if (event?.manager) {
|
||||||
|
latestMedia = await event.manager.findOne(Media, {
|
||||||
|
where: { id: entity.media.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!latestMedia) {
|
||||||
|
const mediaRepository = getRepository(Media);
|
||||||
|
latestMedia = await mediaRepository.findOne({
|
||||||
|
where: { id: entity.media.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check availability using fresh media state
|
||||||
|
if (
|
||||||
|
!latestMedia ||
|
||||||
|
latestMedia[entity.is4k ? 'status4k' : 'status'] !== MediaStatus.AVAILABLE
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const tmdb = new TheMovieDb();
|
const tmdb = new TheMovieDb();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -58,7 +79,7 @@ export class MediaRequestSubscriber
|
|||||||
separator: /\s/,
|
separator: /\s/,
|
||||||
omission: '…',
|
omission: '…',
|
||||||
}),
|
}),
|
||||||
media: entity.media,
|
media: latestMedia,
|
||||||
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
|
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
|
||||||
request: entity,
|
request: entity,
|
||||||
});
|
});
|
||||||
@@ -70,15 +91,35 @@ export class MediaRequestSubscriber
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async notifyAvailableSeries(
|
||||||
|
entity: MediaRequest,
|
||||||
|
event?: UpdateEvent<MediaRequest>
|
||||||
|
) {
|
||||||
|
// Get fresh media state with seasons using event manager
|
||||||
|
let latestMedia: Media | null = null;
|
||||||
|
if (event?.manager) {
|
||||||
|
latestMedia = await event.manager.findOne(Media, {
|
||||||
|
where: { id: entity.media.id },
|
||||||
|
relations: { seasons: true },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!latestMedia) {
|
||||||
|
const mediaRepository = getRepository(Media);
|
||||||
|
latestMedia = await mediaRepository.findOne({
|
||||||
|
where: { id: entity.media.id },
|
||||||
|
relations: { seasons: true },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async notifyAvailableSeries(entity: MediaRequest) {
|
if (!latestMedia) {
|
||||||
// Find all seasons in the related media entity
|
return;
|
||||||
// and see if they are available, then we can check
|
}
|
||||||
// if the request contains the same seasons
|
|
||||||
|
// Check availability using fresh media state
|
||||||
const requestedSeasons =
|
const requestedSeasons =
|
||||||
entity.seasons?.map((entitySeason) => entitySeason.seasonNumber) ?? [];
|
entity.seasons?.map((entitySeason) => entitySeason.seasonNumber) ?? [];
|
||||||
const availableSeasons = entity.media.seasons.filter(
|
const availableSeasons = latestMedia.seasons.filter(
|
||||||
(season) =>
|
(season) =>
|
||||||
season[entity.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE &&
|
season[entity.is4k ? 'status4k' : 'status'] === MediaStatus.AVAILABLE &&
|
||||||
requestedSeasons.includes(season.seasonNumber)
|
requestedSeasons.includes(season.seasonNumber)
|
||||||
@@ -87,7 +128,10 @@ export class MediaRequestSubscriber
|
|||||||
availableSeasons.length > 0 &&
|
availableSeasons.length > 0 &&
|
||||||
availableSeasons.length === requestedSeasons.length;
|
availableSeasons.length === requestedSeasons.length;
|
||||||
|
|
||||||
if (isMediaAvailable) {
|
if (!isMediaAvailable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const tmdb = new TheMovieDb();
|
const tmdb = new TheMovieDb();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -107,7 +151,7 @@ export class MediaRequestSubscriber
|
|||||||
notifySystem: true,
|
notifySystem: true,
|
||||||
notifyUser: entity.requestedBy,
|
notifyUser: entity.requestedBy,
|
||||||
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
|
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
|
||||||
media: entity.media,
|
media: latestMedia,
|
||||||
extra: [
|
extra: [
|
||||||
{
|
{
|
||||||
name: 'Requested Seasons',
|
name: 'Requested Seasons',
|
||||||
@@ -126,7 +170,6 @@ export class MediaRequestSubscriber
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public async sendToRadarr(entity: MediaRequest): Promise<void> {
|
public async sendToRadarr(entity: MediaRequest): Promise<void> {
|
||||||
if (
|
if (
|
||||||
@@ -782,10 +825,10 @@ export class MediaRequestSubscriber
|
|||||||
|
|
||||||
if (event.entity.status === MediaRequestStatus.COMPLETED) {
|
if (event.entity.status === MediaRequestStatus.COMPLETED) {
|
||||||
if (event.entity.media.mediaType === MediaType.MOVIE) {
|
if (event.entity.media.mediaType === MediaType.MOVIE) {
|
||||||
this.notifyAvailableMovie(event.entity as MediaRequest);
|
this.notifyAvailableMovie(event.entity as MediaRequest, event);
|
||||||
}
|
}
|
||||||
if (event.entity.media.mediaType === MediaType.TV) {
|
if (event.entity.media.mediaType === MediaType.TV) {
|
||||||
this.notifyAvailableSeries(event.entity as MediaRequest);
|
this.notifyAvailableSeries(event.entity as MediaRequest, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user