Skip to content

Commit

Permalink
feat(job): media availability support for jellyfin/emby (#522)
Browse files Browse the repository at this point in the history
* feat(job): media availability support for jellyfin/emby

This refactors the media availability job to support jellyfin/emby for media removal automatically.
Needs further testing on 4k items (as I have not yet tested with 4k), however, non-4k items work as
intended.

fix #406, fix #193, fix #516, fix #362, fix #84

* fix(availabilitysync): use the correct 4k jellyfinMediaId

* fix: season mapping for plex

Fixes a bug introduced with this PR where media availability sync job removed the seasons from all
series even when those seasons existed
  • Loading branch information
Fallenbagel authored Feb 23, 2024
1 parent db84f65 commit 3eb1bb3
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 72 deletions.
10 changes: 9 additions & 1 deletion server/api/jellyfin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import availabilitySync from '@server/lib/availabilitySync';
import logger from '@server/logger';
import type { AxiosInstance } from 'axios';
import axios from 'axios';
Expand Down Expand Up @@ -241,14 +242,21 @@ class JellyfinAPI {
}
}

public async getItemData(id: string): Promise<JellyfinLibraryItemExtended> {
public async getItemData(
id: string
): Promise<JellyfinLibraryItemExtended | undefined> {
try {
const contents = await this.axios.get<any>(
`/Users/${this.userId}/Items/${id}`
);

return contents.data;
} catch (e) {
if (availabilitySync.running) {
if (e.response && e.response.status === 500) {
return undefined;
}
}
logger.error(
`Something went wrong while getting library content from the Jellyfin server: ${e.message}`,
{ label: 'Jellyfin API' }
Expand Down
4 changes: 2 additions & 2 deletions server/job/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MediaServerType } from '@server/constants/server';
import availabilitySync from '@server/lib/availabilitySync';
import downloadTracker from '@server/lib/downloadtracker';
import ImageProxy from '@server/lib/imageproxy';
import {
Expand Down Expand Up @@ -167,7 +168,7 @@ export const startJobs = (): void => {
});

// Checks if media is still available in plex/sonarr/radarr libs
/* scheduledJobs.push({
scheduledJobs.push({
id: 'availability-sync',
name: 'Media Availability Sync',
type: 'process',
Expand All @@ -182,7 +183,6 @@ export const startJobs = (): void => {
running: () => availabilitySync.running,
cancelFn: () => availabilitySync.cancel(),
});
*/

// Run download sync every minute
scheduledJobs.push({
Expand Down
Loading

0 comments on commit 3eb1bb3

Please sign in to comment.