mirror of
https://github.com/trafficlunar/jellyfin-spicetify.git
synced 2026-06-13 19:07:06 +00:00
fix: add device id
This commit is contained in:
parent
98e317f7ff
commit
11add72f2c
3 changed files with 18 additions and 13 deletions
|
|
@ -1,6 +1,15 @@
|
|||
import { Api, Jellyfin } from "@jellyfin/sdk";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
const getDeviceId = (): string => {
|
||||
const existing = Spicetify.LocalStorage.get("jellyfin-device-id");
|
||||
if (existing) return existing;
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
Spicetify.LocalStorage.set("jellyfin-device-id", id);
|
||||
return id;
|
||||
};
|
||||
|
||||
export const sdk = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: "Spicetify",
|
||||
|
|
@ -8,7 +17,7 @@ export const sdk = new Jellyfin({
|
|||
},
|
||||
deviceInfo: {
|
||||
name: "Spotify",
|
||||
id: "spotify", // TODO: should be unique?
|
||||
id: getDeviceId(),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,6 @@ export const audio = new Audio();
|
|||
export let hijackActive = false;
|
||||
export let currentVolume = 0.5;
|
||||
|
||||
export function setHijackActive(value: boolean) {
|
||||
hijackActive = value;
|
||||
}
|
||||
export function setCurrentVolume(value: number) {
|
||||
currentVolume = value;
|
||||
}
|
||||
|
||||
const BITRATE_MAP: Record<string, string> = {
|
||||
high: "320000",
|
||||
medium: "256000",
|
||||
|
|
@ -24,6 +17,9 @@ const BITRATE_MAP: Record<string, string> = {
|
|||
let currentItemId: string | null = null;
|
||||
let oldTime = 0;
|
||||
let lastProgressReport = 0;
|
||||
export function setHijackActive(value: boolean) {
|
||||
hijackActive = value;
|
||||
}
|
||||
|
||||
export async function playTrack(id: string) {
|
||||
if (!jellyfin.api) return;
|
||||
|
|
@ -32,7 +28,7 @@ export async function playTrack(id: string) {
|
|||
const oldVolume = hijackActive ? currentVolume : Spicetify.Player.getVolume();
|
||||
if (!hijackActive) Spicetify.Player.setVolume(0); // Set Spotify audio volume to 0
|
||||
|
||||
setHijackActive(true);
|
||||
hijackActive = true;
|
||||
Spicetify.Player.setVolume(oldVolume); // Volume is now hijacked, will now set Jellyfin audio volume and also update the volume slider
|
||||
|
||||
const params = new URLSearchParams({
|
||||
|
|
@ -64,7 +60,7 @@ export async function playTrack(id: string) {
|
|||
} catch (error) {
|
||||
console.error("An error occurred trying to play a track on Jellyfin", error);
|
||||
Spicetify.showNotification("An error occurred trying to play a track on Jellyfin", true);
|
||||
setHijackActive(false);
|
||||
hijackActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +87,7 @@ export function registerEvents() {
|
|||
|
||||
const item = results.data.SearchHints?.[0];
|
||||
if (!item?.Id) {
|
||||
setHijackActive(false);
|
||||
hijackActive = false;
|
||||
audio.pause();
|
||||
Spicetify.Player.setVolume(currentVolume);
|
||||
return;
|
||||
|
|
@ -156,7 +152,7 @@ export function registerEvents() {
|
|||
const playback = Spicetify.Platform.PlaybackAPI;
|
||||
playback.setVolume = new Proxy(playback.setVolume, {
|
||||
apply(target, thisArg, args) {
|
||||
setCurrentVolume(args[0]);
|
||||
currentVolume = args[0];
|
||||
|
||||
if (hijackActive) {
|
||||
audio.volume = Math.pow(currentVolume, 3);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ export default function SettingsView({ setView }: Props) {
|
|||
<div className={styles.setting}>
|
||||
<div className={styles.settingInfo}>
|
||||
<h2>Audio Hijack</h2>
|
||||
<p>Enable to replace Spotify song audio with Jellyfin audio</p>
|
||||
<p>Enable to replace Spotify song audio with Jellyfin audio if found</p>
|
||||
</div>
|
||||
|
||||
<input type="checkbox" checked={settings.hijack} onChange={(e) => setSettings((p) => ({ ...p, hijack: e.target.checked }))} className={styles.switch} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue