feat: Episode page

This commit is contained in:
Aleksi Lassila
2024-04-23 18:24:05 +03:00
parent 423d8d9af4
commit 5ece8dd6f5
17 changed files with 303 additions and 57 deletions

View File

@@ -5,6 +5,7 @@ import type { Api } from '../api.interface';
import { appState } from '../../stores/app-state.store';
import type { DeviceProfile } from './playback-profiles';
import axios from 'axios';
import { log } from '../../utils';
export type JellyfinItem = components['schemas']['BaseItemDto'];
@@ -82,7 +83,13 @@ export class JellyfinApi implements Api<paths> {
hasTmdbId: true,
recursive: true,
includeItemTypes: ['Movie', 'Series'],
fields: ['ProviderIds', 'Genres', 'DateLastMediaAdded', 'DateCreated']
fields: [
'ProviderIds',
'Genres',
'DateLastMediaAdded',
'DateCreated',
'MediaSources'
]
}
}
})
@@ -265,6 +272,39 @@ export class JellyfinApi implements Api<paths> {
// }
// }).then((r) => r.data?.Items || []);
episodesCache: JellyfinItem[] = [];
getEpisode = async (
seriesId: string,
season: number,
episode: number,
refreshCache = false
): Promise<JellyfinItem | undefined> =>
this.getClient()
.GET('/Users/{userId}/Items', {
params: {
path: {
userId: this.getUserId()
},
query: {
// @ts-ignore
seriesId,
parentIndexNumber: season,
indexNumber: episode,
recursive: true,
includeItemTypes: ['Episode'],
fields: ['ProviderIds', 'Genres', 'DateLastMediaAdded', 'DateCreated', 'MediaSources']
}
}
})
.then((r) =>
r.data?.Items?.find(
(i) =>
i?.ParentIndexNumber === season &&
i?.IndexNumber === episode &&
i?.SeriesId === seriesId
)
);
getJellyfinEpisodes = async (parentId = '') =>
this.getClient()
?.GET('/Users/{userId}/Items', {
@@ -415,28 +455,33 @@ export class JellyfinApi implements Api<paths> {
}
});
setJellyfinItemWatched = async (jellyfinId: string) =>
this.getClient()?.POST('/Users/{userId}/PlayedItems/{itemId}', {
params: {
path: {
userId: this.getUserId(),
itemId: jellyfinId
},
query: {
datePlayed: new Date().toISOString()
markAsWatched = async (jellyfinId: string) =>
this.getClient()
?.POST('/Users/{userId}/PlayedItems/{itemId}', {
params: {
path: {
userId: this.getUserId(),
itemId: jellyfinId
},
query: {
datePlayed: new Date().toISOString()
}
}
}
});
})
setJellyfinItemUnwatched = async (jellyfinId: string) =>
this.getClient()?.DELETE('/Users/{userId}/PlayedItems/{itemId}', {
params: {
path: {
userId: this.getUserId(),
itemId: jellyfinId
.then((res) => res.response.status === 200);
markAsUnwatched = async (jellyfinId: string) =>
this.getClient()
?.DELETE('/Users/{userId}/PlayedItems/{itemId}', {
params: {
path: {
userId: this.getUserId(),
itemId: jellyfinId
}
}
}
});
})
.then((res) => res.response.status === 200);
getJellyfinHealth = async (
baseUrl: string | undefined = undefined,

View File

@@ -15,12 +15,14 @@ export type TmdbSeries2 =
operations['tv-series-details']['responses']['200']['content']['application/json'];
export type TmdbSeason =
operations['tv-season-details']['responses']['200']['content']['application/json'];
export type TmdbEpisode = NonNullable<TmdbSeason['episodes']>[0];
export type TmdbSeasonEpisode = NonNullable<TmdbSeason['episodes']>[0];
export type TmdbPerson =
operations['person-details']['responses']['200']['content']['application/json'];
export type TmdbCredit =
| NonNullable<TmdbSeriesFull2['aggregate_credits']['cast']>[0]
| NonNullable<TmdbMovieFull2['credits']['cast']>[0];
export type TmdbEpisode =
operations['tv-episode-details']['responses']['200']['content']['application/json'];
export interface TmdbPersonFull extends TmdbPerson {
images: operations['person-images']['responses']['200']['content']['application/json'];
@@ -176,6 +178,26 @@ export class TmdbApi implements Api<paths> {
}
}).then((res) => res.data?.results || []);
getEpisode = (
seriesId: number,
season: number,
episode: number
): Promise<TmdbEpisode | undefined> =>
this.getClient()
.GET('/3/tv/{series_id}/season/{season_number}/episode/{episode_number}', {
params: {
path: {
series_id: seriesId,
season_number: season,
episode_number: episode
},
query: {
append_to_response: 'credits,external_ids,images'
}
}
})
.then((res) => res.data);
// OTHER
}