diff --git a/src/lib/jellyfin/jellyfin.ts b/src/lib/jellyfin/jellyfin.ts index bbfdf80..a4a7850 100644 --- a/src/lib/jellyfin/jellyfin.ts +++ b/src/lib/jellyfin/jellyfin.ts @@ -15,19 +15,23 @@ export const JellyfinApi = createClient({ }); export const getJellyfinContinueWatching = () => - request(() => - JellyfinApi.get('/Users/{userId}/Items/Resume', { - params: { - path: { - userId: JELLYFIN_USER_ID - }, - query: { - limit: 8, - mediaTypes: ['Video'] - } + JellyfinApi.get('/Users/{userId}/Items/Resume', { + params: { + path: { + userId: JELLYFIN_USER_ID + }, + query: { + limit: 8, + mediaTypes: ['Video'], + fields: ['ProviderIds'] } - }).then((r) => r.data?.Items) - ); + } + }).then((r) => { + console.log(r.data); + return r.data?.Items; + }); + +export const requestJellyfinContinueWatching = () => request(getJellyfinContinueWatching); export const getJellyfinItemByTmdbId = () => request((tmdbId: string) => diff --git a/src/lib/tmdb-api.ts b/src/lib/tmdb-api.ts index 64fb682..d355127 100644 --- a/src/lib/tmdb-api.ts +++ b/src/lib/tmdb-api.ts @@ -28,6 +28,9 @@ export const fetchTmdbMovieVideos = async (tmdbId: string): Promise => export const fetchTmdbMovieImages = async (tmdbId: string): Promise => await TmdbApi.get('/movie/' + tmdbId + '/images').then((res) => res.data); +export const fetchTmdbMovieCredits = async (tmdbId: string): Promise => + await TmdbApi.get('/movie/' + tmdbId + '/credits').then((res) => res.data.cast); + export interface TmdbMovieFull extends TmdbMovie { videos: Video[]; images: { diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..bda6b41 --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,35 @@ +import { fetchTmdbMovie, TmdbApi } from '$lib/tmdb-api'; +import type { TmdbMovie } from '$lib/tmdb-api'; +import { getJellyfinContinueWatching } from '$lib/jellyfin/jellyfin'; +import type { PageServerLoad } from './$types'; + +export const load = (async () => { + const showcases = await TmdbApi.get('/movie/popular').then((res): TmdbMovie[] => + res.data.results.slice(0, 5) + ); + + const continueWatching = getJellyfinContinueWatching().then(async (items) => { + const itemsFiltered = items?.filter((i) => i.ProviderIds?.Tmdb); + if (!itemsFiltered?.length) return; + + console.log(itemsFiltered.map((i) => i.RunTimeTicks)); + + const firstMovie = await fetchTmdbMovie(String(itemsFiltered[0].ProviderIds?.Tmdb)); + + return { + items: itemsFiltered?.map((i) => ({ + tmdbId: i.ProviderIds?.Tmdb, + progress: i.UserData?.PlayedPercentage, + length: (i.RunTimeTicks || 0) / 10_000_000 / 60 + })), + backdrop: firstMovie.backdrop_path + }; + }); + + return { + showcases, + streamed: { + continueWatching + } + }; +}) satisfies PageServerLoad; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 779cdb0..d2bf6db 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,33 +1,62 @@ - - - +
+ {#if movies[index]} + {#await Promise.all(movies) then awaitedMovies} + + + + {/await} + {/if} +
-{#if !data?.showcases?.length} -
Loading
-{:else} -
-
-

Continue Watching

-
- {#each data.showcases.splice(0, 5) as item (item.id)} - - {/each} +{#await data.streamed.continueWatching then continueWatching} + {#if continueWatching?.items?.length} +
+
+

Continue Watching

+
+ {#each continueWatching.items.slice(0, 5) as item (item.tmdbId)} + + {/each} +
-
-{/if} + {/if} +{/await} diff --git a/src/routes/+page.ts b/src/routes/+page.ts deleted file mode 100644 index 0348c85..0000000 --- a/src/routes/+page.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { PageLoad } from './$types'; -import { fetchFullMovieDetails, TmdbApi } from '$lib/tmdb-api'; -import { RadarrApi } from '$lib/radarr/radarr'; - -export const load = (async () => { - const movies = await TmdbApi.get('/movie/popular').then((res) => res.data.results.slice(0, 5)); - - const showcases = await Promise.all(movies.map((m: any) => fetchFullMovieDetails(m.id))); - return { showcases }; -}) satisfies PageLoad; diff --git a/src/routes/ResourceDetailsControls.svelte b/src/routes/ResourceDetailsControls.svelte index 7b8f444..f0aba0c 100644 --- a/src/routes/ResourceDetailsControls.svelte +++ b/src/routes/ResourceDetailsControls.svelte @@ -1,22 +1,31 @@
-
+ -
+ +
- - - - - + {#each Array.from({ length }, (_, i) => i) as i} + {#if i === index} + + {:else} + + {/if} + {/each}
-
+ -
+
diff --git a/src/routes/components/SmallPoster/SmallPoster.svelte b/src/routes/components/Poster/Poster.svelte similarity index 89% rename from src/routes/components/SmallPoster/SmallPoster.svelte rename to src/routes/components/Poster/Poster.svelte index af21bb6..8de6893 100644 --- a/src/routes/components/SmallPoster/SmallPoster.svelte +++ b/src/routes/components/Poster/Poster.svelte @@ -1,10 +1,13 @@ -
-