mirror of
https://github.com/trafficlunar/jellyfin-spicetify.git
synced 2026-06-13 19:07:06 +00:00
feat: non-spotify tracks, refactors, bug fixes
This commit is contained in:
parent
2dea8586f6
commit
eee96c84af
9 changed files with 306 additions and 157 deletions
53
src/jellyfin.ts
Normal file
53
src/jellyfin.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { Api, Jellyfin } from "@jellyfin/sdk";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
export const sdk = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: "Spicetify",
|
||||
version: "1.0.0",
|
||||
},
|
||||
deviceInfo: {
|
||||
name: "Spotify",
|
||||
id: "spotify", // TODO: should be unique?
|
||||
},
|
||||
});
|
||||
|
||||
export let api: Api | undefined;
|
||||
export let user: string | undefined;
|
||||
|
||||
export function setApi(value: Api) {
|
||||
api = value;
|
||||
}
|
||||
export function setUser(value: string) {
|
||||
user = value;
|
||||
}
|
||||
|
||||
// Automatically login to Jellyfin if settings are present
|
||||
export async function tryAutoLogin() {
|
||||
const url = Spicetify.LocalStorage.get("jellyfin-url");
|
||||
const token = Spicetify.LocalStorage.get("jellyfin-token");
|
||||
|
||||
if (url && token) {
|
||||
try {
|
||||
const servers = await sdk.discovery.getRecommendedServerCandidates(url);
|
||||
const best = sdk.discovery.findBestServer(servers);
|
||||
if (!best) {
|
||||
Spicetify.showNotification("Failed to connect to Jellyfin server!", true);
|
||||
return;
|
||||
}
|
||||
api = sdk.createApi(best.address, token);
|
||||
|
||||
const response = await getUserApi(api).getCurrentUser();
|
||||
if (response.data.Id) user = response.data.Id;
|
||||
} catch (error: any) {
|
||||
if (error?.response.status === 401) {
|
||||
Spicetify.LocalStorage.remove("jellyfin-token");
|
||||
api = undefined;
|
||||
Spicetify.showNotification("Jellyfin session expired. Please log in again.", true);
|
||||
} else {
|
||||
Spicetify.showNotification("Failed to connect to Jellyfin.", true);
|
||||
console.error("Jellyfin init error:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue