added what im watching

This commit is contained in:
2026-11-03 19:32:08 +00:00
parent 7e8f329109
commit 1c2c577280
19 changed files with 255 additions and 124 deletions

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@ devenv.local.yaml
# pre-commit # pre-commit
.pre-commit-config.yaml .pre-commit-config.yaml
/.env /.env
/.session

105
.session
View File

@@ -1,105 +0,0 @@
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
doautoall SessionLoadPre
silent only
silent tabonly
cd ~/Projects/voidarc-homepage
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
set shortmess+=aoO
badd +1 svelte.config.js
badd +8 src/env.ts
badd +1 src/lib/server/jellyfin.ts
badd +6 src/routes/+page.server.ts
badd +15 vite.config.ts
badd +61 src/routes/+page.svelte
badd +5 src/routes/artwork/\[itemId]/+server.ts
badd +165 src/routes/layout.css
argglobal
%argdel
$argadd src/routes/+page.server.ts
edit src/routes/+page.svelte
let s:save_splitbelow = &splitbelow
let s:save_splitright = &splitright
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
let &splitbelow = s:save_splitbelow
let &splitright = s:save_splitright
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
exe 'vert 1resize ' . ((&columns * 103 + 104) / 208)
exe 'vert 2resize ' . ((&columns * 104 + 104) / 208)
argglobal
balt src/routes/layout.css
setlocal foldmethod=manual
setlocal foldexpr=0
setlocal foldmarker={{{,}}}
setlocal foldignore=#
setlocal foldlevel=0
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldenable
silent! normal! zE
let &fdl = &fdl
let s:l = 36 - ((29 * winheight(0) + 27) / 54)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 36
normal! 020|
wincmd w
argglobal
if bufexists(fnamemodify("src/routes/+page.server.ts", ":p")) | buffer src/routes/+page.server.ts | else | edit src/routes/+page.server.ts | endif
if &buftype ==# 'terminal'
silent file src/routes/+page.server.ts
endif
balt src/routes/layout.css
setlocal foldmethod=manual
setlocal foldexpr=0
setlocal foldmarker={{{,}}}
setlocal foldignore=#
setlocal foldlevel=0
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldenable
silent! normal! zE
let &fdl = &fdl
let s:l = 6 - ((5 * winheight(0) + 27) / 54)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 6
normal! 0
wincmd w
2wincmd w
exe 'vert 1resize ' . ((&columns * 103 + 104) / 208)
exe 'vert 2resize ' . ((&columns * 104 + 104) / 208)
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :

View File

@@ -9,7 +9,7 @@ export const nodes = [
export const server_loads = []; export const server_loads = [];
export const dictionary = { export const dictionary = {
"/": [2] "/": [~2]
}; };
export const hooks = { export const hooks = {

View File

@@ -7,7 +7,7 @@ export const options = {
csrf_trusted_origins: [], csrf_trusted_origins: [],
service_worker_options: undefined, service_worker_options: undefined,
templates: { templates: {
app: ({ head, body, assets, nonce, env }) => "<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t\t<meta name=\"text-scale\" content=\"scale\" />\n\t\t" + head + "\n\t</head>\n\t<body data-sveltekit-preload-data=\"hover\">\n\t\t<div style=\"display: contents\">" + body + "</div>\n\t</body>\n</html>\n", app: ({ head, body, assets, nonce, env }) => "<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<!-- Fonts -->\n\t\t<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n\t\t<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin />\n\t\t<link\n\t\t\thref=\"https://fonts.googleapis.com/css2?family=Squada+One&display=swap\"\n\t\t\trel=\"stylesheet\"\n\t\t/>\n\t\t<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\" />\n\t\t<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin />\n\t\t<link\n\t\t\thref=\"https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700&display=swap\"\n\t\t\trel=\"stylesheet\"\n\t\t/>\n\n\t\t<!-- Not Fonts -->\n\t\t<meta charset=\"utf-8\" />\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n\t\t<meta name=\"text-scale\" content=\"scale\" />\n\t\t" + head + "\n\t</head>\n\t<style>\n\t\t.fira-mono-regular {\n\t\t\tfont-family: 'Fira Mono', monospace;\n\t\t\tfont-weight: 400;\n\t\t\tfont-style: normal;\n\t\t}\n\n\t\t.fira-mono-medium {\n\t\t\tfont-family: 'Fira Mono', monospace;\n\t\t\tfont-weight: 500;\n\t\t\tfont-style: normal;\n\t\t}\n\n\t\t.fira-mono-bold {\n\t\t\tfont-family: 'Fira Mono', monospace;\n\t\t\tfont-weight: 700;\n\t\t\tfont-style: normal;\n\t\t}\n\t</style>\n\t<body class=\"fira-mono-regular bg-ctp-mantle text-ctp-text\" data-sveltekit-preload-data=\"hover\">\n\t\t<div style=\"display: contents\">" + body + "</div>\n\t</body>\n</html>\n",
error error
} }
}; };

View File

@@ -9,5 +9,6 @@ export const assets = [
export const routes = [ export const routes = [
{"id":"/","page":true,"endpoint":false}, {"id":"/","page":true,"endpoint":false},
{"id":"/artwork/[itemId]","page":false,"endpoint":true} {"id":"/artwork/[itemId]","page":false,"endpoint":true},
{"id":"/posters/[itemId]","page":false,"endpoint":true}
]; ];

View File

@@ -23,7 +23,9 @@ export function set_env(env) {
dynamic_private_env.JELLYFIN_PLAYLIST_ID = JELLYFIN_PLAYLIST_ID; dynamic_private_env.JELLYFIN_PLAYLIST_ID = JELLYFIN_PLAYLIST_ID;
const JELLYFIN_USER_ID = validate(variables, env.JELLYFIN_USER_ID, "JELLYFIN_USER_ID", issues); const JELLYFIN_USER_ID = validate(variables, env.JELLYFIN_USER_ID, "JELLYFIN_USER_ID", issues);
dynamic_private_env.JELLYFIN_USER_ID = JELLYFIN_USER_ID; dynamic_private_env.JELLYFIN_USER_ID = JELLYFIN_USER_ID;
const JELLYFIN_LIBRARY_ID = validate(variables, env.JELLYFIN_LIBRARY_ID, "JELLYFIN_LIBRARY_ID", issues);
dynamic_private_env.JELLYFIN_LIBRARY_ID = JELLYFIN_LIBRARY_ID;
handle_issues(issues); handle_issues(issues);
} }
set_env({JELLYFIN_URL:"http://192.168.1.180:8096",JELLYFIN_API_KEY:"2727181a933049dcbc8d63cf0bcc15f3",JELLYFIN_PLAYLIST_ID:"e3088b1ab54766ad3668bc71a574a2f7",JELLYFIN_USER_ID:"5824596713e44e8c949f529e1a081393"}); set_env({JELLYFIN_URL:"http://192.168.1.180:8096",JELLYFIN_API_KEY:"2727181a933049dcbc8d63cf0bcc15f3",JELLYFIN_PLAYLIST_ID:"e3088b1ab54766ad3668bc71a574a2f7",JELLYFIN_USER_ID:"5824596713e44e8c949f529e1a081393",JELLYFIN_LIBRARY_ID:"a656b907eb3a73532e40e44b968d0225"});

View File

@@ -4,3 +4,4 @@ export const JELLYFIN_URL = env.JELLYFIN_URL;
export const JELLYFIN_API_KEY = env.JELLYFIN_API_KEY; export const JELLYFIN_API_KEY = env.JELLYFIN_API_KEY;
export const JELLYFIN_PLAYLIST_ID = env.JELLYFIN_PLAYLIST_ID; export const JELLYFIN_PLAYLIST_ID = env.JELLYFIN_PLAYLIST_ID;
export const JELLYFIN_USER_ID = env.JELLYFIN_USER_ID; export const JELLYFIN_USER_ID = env.JELLYFIN_USER_ID;
export const JELLYFIN_LIBRARY_ID = env.JELLYFIN_LIBRARY_ID;

View File

@@ -3,5 +3,5 @@ globalThis.__sveltekit_dev = {
env: { env: {
// empty // empty
}, },
version: "1793725498340" version: "1793733574808"
}; };

View File

@@ -4,5 +4,8 @@
], ],
"/artwork/[itemId]": [ "/artwork/[itemId]": [
"src/routes/artwork/[itemId]/+server.ts" "src/routes/artwork/[itemId]/+server.ts"
],
"/posters/[itemId]": [
"src/routes/posters/[itemId]/+server.ts"
] ]
} }

View File

@@ -0,0 +1,10 @@
import type * as Kit from '@sveltejs/kit';
import { MatcherParam } from '@sveltejs/kit/params';
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
type RouteParams = { itemId: string };
type RouteId = '/posters/[itemId]';
export type EntryGenerator = () => Promise<Array<RouteParams>> | Array<RouteParams>;
export type RequestHandler = Kit.RequestHandler<RouteParams, RouteId>;
export type RequestEvent = Kit.RequestEvent<RouteParams, RouteId>;

View File

@@ -1,16 +1,20 @@
// @ts-nocheck // @ts-nocheck
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import { getLatestPlaylistSong } from '#lib/server/jellyfin'; import { getLatestPlaylistSong, getLatestWatchedSeries } from '#lib/server/jellyfin';
import { JELLYFIN_PLAYLIST_ID } from '$app/env/private'; import { JELLYFIN_PLAYLIST_ID, JELLYFIN_LIBRARY_ID } from '$app/env/private';
export const load = () => { export const load = () => {
const latestSong = getLatestPlaylistSong(globalThis.fetch, JELLYFIN_PLAYLIST_ID); const latestSong = getLatestPlaylistSong(globalThis.fetch, JELLYFIN_PLAYLIST_ID);
console.log(JELLYFIN_LIBRARY_ID);
const latestSeries = getLatestWatchedSeries(globalThis.fetch, JELLYFIN_LIBRARY_ID);
latestSong.catch(() => {}); latestSong.catch(() => {});
latestSeries.catch(() => {});
return { return {
streamed: { streamed: {
latestSong latestSong,
latestSeries
} }
}; };
}; };

1
node_modules/$app/types/env.d.ts generated vendored
View File

@@ -6,6 +6,7 @@ declare module '$app/env/private' {
export const JELLYFIN_API_KEY: string; export const JELLYFIN_API_KEY: string;
export const JELLYFIN_PLAYLIST_ID: string; export const JELLYFIN_PLAYLIST_ID: string;
export const JELLYFIN_USER_ID: string; export const JELLYFIN_USER_ID: string;
export const JELLYFIN_LIBRARY_ID: string;
} }
declare module '$app/env/public' { declare module '$app/env/public' {

9
node_modules/$app/types/index.d.ts generated vendored
View File

@@ -6,15 +6,16 @@ import './env.js';
declare module "$app/types" { declare module "$app/types" {
export interface AppTypes { export interface AppTypes {
PageRouteId(): "/"; PageRouteId(): "/";
EndpointRouteId(): "/artwork/[itemId]"; EndpointRouteId(): "/artwork/[itemId]" | "/posters/[itemId]";
RouteId(): "/" | "/artwork/[itemId]"; RouteId(): "/" | "/artwork/[itemId]" | "/posters/[itemId]";
RouteParams(): { RouteParams(): {
"/artwork/[itemId]": { itemId: string } "/artwork/[itemId]": { itemId: string };
"/posters/[itemId]": { itemId: string }
}; };
LayoutParams(): { LayoutParams(): {
"/": { itemId?: string | undefined } "/": { itemId?: string | undefined }
}; };
Path(): "" | `artwork/${string}` & {}; Path(): "" | `artwork/${string}` & {} | `posters/${string}` & {};
ResolvedPathname(): `${"/" | `/${string}/`}${ReturnType<AppTypes['Path']>}`; ResolvedPathname(): `${"/" | `/${string}/`}${ReturnType<AppTypes['Path']>}`;
AssetPath(): "robots.txt" | "adumh00man.png"; AssetPath(): "robots.txt" | "adumh00man.png";
} }

View File

@@ -4,5 +4,6 @@ export const variables = defineEnvVars({
JELLYFIN_URL: {}, JELLYFIN_URL: {},
JELLYFIN_API_KEY: {}, JELLYFIN_API_KEY: {},
JELLYFIN_PLAYLIST_ID: {}, JELLYFIN_PLAYLIST_ID: {},
JELLYFIN_USER_ID: {} JELLYFIN_USER_ID: {},
JELLYFIN_LIBRARY_ID: {}
}); });

View File

@@ -16,6 +16,28 @@ interface PlaylistItemsResponse {
TotalRecordCount: number; TotalRecordCount: number;
} }
interface JellyfinEpisode {
Id: string;
Name: string;
SeriesName?: string;
SeriesId?: string;
SeasonName?: string;
ParentIndexNumber?: number;
IndexNumber?: number;
Overview?: string;
ProductionYear?: number;
UserData?: {
Played?: boolean;
LastPlayedDate?: string;
PlaybackPositionTicks?: number;
};
}
interface EpisodesResponse {
Items: JellyfinEpisode[];
TotalRecordCount: number;
}
export interface LatestSong { export interface LatestSong {
id: string; id: string;
name: string; name: string;
@@ -25,15 +47,35 @@ export interface LatestSong {
coverArt: string | null; coverArt: string | null;
} }
export interface LatestSeries {
id: string;
name: string;
year: number | null;
poster: string | null;
episode: {
id: string;
name: string;
season: string;
seasonNumber: number | null;
episodeNumber: number | null;
overview: string | null;
dateWatched: string | null;
coverArt: string | null;
} | null;
}
interface CacheEntry<T> { interface CacheEntry<T> {
value: T; value: T;
expiresAt: number; expiresAt: number;
} }
const playlistCache = new Map<string, CacheEntry<LatestSong | null>>(); const playlistCache = new Map<string, CacheEntry<LatestSong | null>>();
const pendingRequests = new Map<string, Promise<LatestSong | null>>(); const pendingRequests = new Map<string, Promise<LatestSong | null>>();
const seriesCache = new Map<string, CacheEntry<LatestSeries | null>>();
const pendingSeriesRequests = new Map<string, Promise<LatestSeries | null>>();
async function fetchLatestPlaylistSong( async function fetchLatestPlaylistSong(
fetch: typeof globalThis.fetch, fetch: typeof globalThis.fetch,
playlistId: string playlistId: string
@@ -119,6 +161,97 @@ export async function getLatestPlaylistSong(
return request; return request;
} }
async function fetchLatestWatchedSeries(
fetch: typeof globalThis.fetch,
libraryId: string
): Promise<LatestSeries | null> {
const url = new URL(`${JELLYFIN_URL}/Users/${JELLYFIN_USER_ID}/Items`);
url.searchParams.set('ParentId', libraryId);
url.searchParams.set('Recursive', 'true');
url.searchParams.set('IncludeItemTypes', 'Episode');
url.searchParams.set('Filters', 'IsPlayed');
url.searchParams.set('SortBy', 'DatePlayed');
url.searchParams.set('SortOrder', 'Descending');
url.searchParams.set('Limit', '1');
const headers = {
'X-Emby-Token': JELLYFIN_API_KEY
};
const response = await fetch(url, { headers });
if (!response.ok) {
const body = await response.text();
throw new Error(`Jellyfin error: ${response.status} - ${body}`);
}
const data: EpisodesResponse = await response.json();
const episode = data.Items?.[0];
if (!episode || !episode.SeriesId) return null;
return {
id: episode.SeriesId,
name: episode.SeriesName ?? 'Unknown series',
year: episode.ProductionYear ?? null,
// Series poster
poster: `/posters/${encodeURIComponent(episode.SeriesId)}`,
// Most recently watched episode
episode: {
id: episode.Id,
name: episode.Name,
season: episode.SeasonName ?? 'Unknown season',
seasonNumber: episode.ParentIndexNumber ?? null,
episodeNumber: episode.IndexNumber ?? null,
overview: episode.Overview ?? null,
dateWatched: episode.UserData?.LastPlayedDate ?? null,
// Episode artwork
coverArt: `/artwork/${encodeURIComponent(episode.Id)}`
}
};
}
export async function getLatestWatchedSeries(
fetch: typeof globalThis.fetch,
libraryId: string
): Promise<LatestSeries | null> {
const cached = seriesCache.get(libraryId);
if (cached && cached.expiresAt > Date.now()) {
return cached.value;
}
const pending = pendingSeriesRequests.get(libraryId);
if (pending) return pending;
const request = fetchLatestWatchedSeries(fetch, libraryId)
.then((series) => {
seriesCache.set(libraryId, {
value: series,
expiresAt: Date.now() + CACHE_TTL
});
return series;
})
.finally(() => {
pendingSeriesRequests.delete(libraryId);
});
pendingSeriesRequests.set(libraryId, request);
return request;
}
export function invalidatePlaylistCache(playlistId: string): void { export function invalidatePlaylistCache(playlistId: string): void {
playlistCache.delete(playlistId); playlistCache.delete(playlistId);
} }
export function invalidateSeriesCache(libraryId: string): void {
seriesCache.delete(libraryId);
}

View File

@@ -1,15 +1,19 @@
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import { getLatestPlaylistSong } from '#lib/server/jellyfin'; import { getLatestPlaylistSong, getLatestWatchedSeries } from '#lib/server/jellyfin';
import { JELLYFIN_PLAYLIST_ID } from '$app/env/private'; import { JELLYFIN_PLAYLIST_ID, JELLYFIN_LIBRARY_ID } from '$app/env/private';
export const load: PageServerLoad = () => { export const load: PageServerLoad = () => {
const latestSong = getLatestPlaylistSong(globalThis.fetch, JELLYFIN_PLAYLIST_ID); const latestSong = getLatestPlaylistSong(globalThis.fetch, JELLYFIN_PLAYLIST_ID);
console.log(JELLYFIN_LIBRARY_ID);
const latestSeries = getLatestWatchedSeries(globalThis.fetch, JELLYFIN_LIBRARY_ID);
latestSong.catch(() => {}); latestSong.catch(() => {});
latestSeries.catch(() => {});
return { return {
streamed: { streamed: {
latestSong latestSong,
latestSeries
} }
}; };
}; };

View File

@@ -66,7 +66,48 @@
<p>{error}</p> <p>{error}</p>
{/await} {/await}
</div> </div>
<div class="sub-container" style="--container-color:var(--ctp-peach);">watching</div> <div
class="sub-container flex items-center gap-3 overflow-hidden pr-3"
style="--container-color:var(--ctp-peach);"
>
{#await data.streamed.latestSeries}
<p>Loading Latest Watched Series...</p>
{:then series}
<img
src={series.poster}
class="aspect-1/1 h-full w-auto shrink-0 object-contain"
alt=""
/>
<div class="flex min-w-0 flex-col justify-center">
<p class="fira-mono-medium">Currently Watching…</p>
<div
id="music-title-block"
onclick={() =>
window.open(`https://thetvdb.com/search?query=${series.name}`, '_blank')}
style="cursor: pointer;"
role="link"
onkeydown={(e) => {
if (e.key === 'Enter') {
}
}}
tabindex="0"
title="{series.name} S{series.episode.seasonNumber}E{series.episode
.episodeNumber} - {series.episode.name}"
class="pl-2"
>
<p class="fira-mono-bold w-full truncate text-2xl">
{series.name}
</p>
<p class="fira-mono-medium w-full truncate text-xl">
S{series.episode.seasonNumber}E{series.episode.episodeNumber} - {series.episode
.name}
</p>
</div>
</div>
{:catch error}
<p>{error}</p>
{/await}
</div>
<div class="sub-container" style="--container-color:var(--ctp-red);">reading</div> <div class="sub-container" style="--container-color:var(--ctp-red);">reading</div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,32 @@
import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { JELLYFIN_URL, JELLYFIN_API_KEY } from '$app/env/private';
export const GET: RequestHandler = async ({ params, fetch }) => {
const { itemId } = params;
if (!/^[a-zA-Z0-9-]+$/.test(itemId)) {
error(400, 'Invalid item ID');
}
const response = await fetch(
`${JELLYFIN_URL}/Items/${encodeURIComponent(itemId)}/Images/Primary`,
{
headers: {
'X-Emby-Token': JELLYFIN_API_KEY
}
}
);
if (!response.ok) {
error(response.status, 'Poster unavailable');
}
return new Response(response.body, {
headers: {
'Content-Type': response.headers.get('Content-Type') ?? 'image/jpeg',
'Cache-Control': 'private, max-age=3600'
}
});
};

View File

@@ -1,10 +1,11 @@
{ {
"extends": "$app/tsconfig",
"compilerOptions": { "compilerOptions": {
"rewriteRelativeImportExtensions": true, "rewriteRelativeImportExtensions": true,
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"esModuleInterop": true, "esModuleInterop": true,
"types": ["bun", "node"], "types": ["bun", "node", "$app/types"],
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"skipLibCheck": true, "skipLibCheck": true,