feat: localize UI and improve playback
Continuous Integration / build_web (push) Failing after 1s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped

- translate the interface into Russian
- add picture-in-picture and video fit modes
- derive skip segments from Jellyfin chapter markers
- align player navigation and add a window drag region
- keep audio playback alive across routes
This commit is contained in:
1xDed committed 2026-11-30 19:19:51 +03:00
1 parent 5784036eb1
commit d9bce4de04
100 files changed
+1364 -706

No files matched your search

+29 -29
View File
@@ -10,32 +10,32 @@ export const AVAILABLE_VIEWS: Array<{
compatibleCollectionTypes: CollectionType[];
}> = [
{
title: "Movies",
title: "Фильмы",
value: BaseItemKind.Movie,
compatibleCollectionTypes: [CollectionType.Movies],
},
{
title: "Shows",
title: "Сериалы",
value: BaseItemKind.Series,
compatibleCollectionTypes: [CollectionType.Tvshows],
},
{
title: "Albums",
title: "Альбомы",
value: BaseItemKind.MusicAlbum,
compatibleCollectionTypes: [CollectionType.Music],
},
{
title: "Collections",
title: "Коллекции",
value: BaseItemKind.CollectionFolder,
compatibleCollectionTypes: [CollectionType.Movies, CollectionType.Boxsets],
},
{
title: "Books",
title: "Книги",
value: BaseItemKind.Book,
compatibleCollectionTypes: [CollectionType.Books],
},
{
title: "Genres",
title: "Жанры",
compatibleCollectionTypes: [
CollectionType.Movies,
CollectionType.Tvshows,
@@ -44,32 +44,32 @@ export const AVAILABLE_VIEWS: Array<{
value: BaseItemKind.Genre,
},
{
title: "Trailers",
title: "Трейлеры",
value: BaseItemKind.Trailer,
compatibleCollectionTypes: [CollectionType.Movies],
},
{
title: "TV Networks",
title: "Телеканалы",
value: BaseItemKind.Studio,
compatibleCollectionTypes: [CollectionType.Tvshows],
},
{
title: "Album Artist",
title: "Исполнитель альбома",
value: BaseItemKind.MusicArtist,
compatibleCollectionTypes: [CollectionType.Music],
},
{
title: "Artist",
title: "Исполнитель",
value: "Artist",
compatibleCollectionTypes: [CollectionType.Music],
},
{
title: "Playlist",
title: "Плейлист",
value: BaseItemKind.Playlist,
compatibleCollectionTypes: [CollectionType.Music, CollectionType.Playlists],
},
{
title: "Songs",
title: "Песни",
value: BaseItemKind.Audio,
compatibleCollectionTypes: [CollectionType.Music],
},
@@ -82,7 +82,7 @@ export const SORT_BY_OPTIONS: Array<{
compatibleViewTypes?: BaseItemKind[];
}> = [
{
title: "Name",
title: "Название",
value: ItemSortBy.SortName,
compatibleCollectionTypes: [
CollectionType.Movies,
@@ -92,7 +92,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Track Name",
title: "Название трека",
value: ItemSortBy.Name,
compatibleViewTypes: [
BaseItemKind.Audio,
@@ -101,22 +101,22 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Album",
title: "Альбом",
value: ItemSortBy.Album,
compatibleViewTypes: [BaseItemKind.Audio],
},
{
title: "Album Artist",
title: "Исполнитель альбома",
value: ItemSortBy.AlbumArtist,
compatibleViewTypes: [BaseItemKind.Audio, BaseItemKind.MusicAlbum],
},
{
title: "Artist",
title: "Исполнитель",
value: ItemSortBy.Artist,
compatibleViewTypes: [BaseItemKind.Audio],
},
{
title: "Date Added",
title: "Дата добавления",
value: ItemSortBy.DateCreated,
compatibleViewTypes: [
BaseItemKind.MusicAlbum,
@@ -130,7 +130,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Date Played",
title: "Дата просмотра",
value: ItemSortBy.DatePlayed,
compatibleViewTypes: [BaseItemKind.Audio, BaseItemKind.Playlist],
compatibleCollectionTypes: [
@@ -140,13 +140,13 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Play Count",
title: "Количество просмотров",
value: ItemSortBy.PlayCount,
compatibleViewTypes: [BaseItemKind.Audio, BaseItemKind.Playlist],
compatibleCollectionTypes: [CollectionType.Movies, CollectionType.Boxsets],
},
{
title: "Release Date",
title: "Дата выхода",
value: ItemSortBy.PremiereDate,
compatibleViewTypes: [
BaseItemKind.MusicAlbum,
@@ -160,7 +160,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Runtime",
title: "Длительность",
value: ItemSortBy.Runtime,
compatibleViewTypes: [
BaseItemKind.MusicAlbum,
@@ -170,7 +170,7 @@ export const SORT_BY_OPTIONS: Array<{
compatibleCollectionTypes: [CollectionType.Movies, CollectionType.Boxsets],
},
{
title: "Random",
title: "Случайно",
value: ItemSortBy.Random,
compatibleViewTypes: [
// BaseItemKind.MusicAlbum,
@@ -184,7 +184,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Community Rating",
title: "Рейтинг сообщества",
value: ItemSortBy.CommunityRating,
compatibleViewTypes: [
BaseItemKind.MusicAlbum,
@@ -198,7 +198,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Critics Rating",
title: "Рейтинг критиков",
value: ItemSortBy.CriticRating,
compatibleViewTypes: [
BaseItemKind.MusicAlbum,
@@ -208,12 +208,12 @@ export const SORT_BY_OPTIONS: Array<{
compatibleCollectionTypes: [CollectionType.Movies, CollectionType.Boxsets],
},
{
title: "Folder",
title: "Папка",
value: [ItemSortBy.IsFolder, ItemSortBy.SortName],
compatibleViewTypes: [BaseItemKind.Playlist],
},
{
title: "Parental Rating",
title: "Возрастной рейтинг",
value: ItemSortBy.OfficialRating,
compatibleViewTypes: [BaseItemKind.Playlist],
compatibleCollectionTypes: [
@@ -223,7 +223,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Release Date",
title: "Дата выхода",
value: [
ItemSortBy.ProductionYear,
ItemSortBy.PremiereDate,
@@ -236,7 +236,7 @@ export const SORT_BY_OPTIONS: Array<{
],
},
{
title: "Date Episode Added",
title: "Дата добавления серии",
value: ItemSortBy.DateLastContentAdded,
compatibleCollectionTypes: [CollectionType.Tvshows],
},
+11 -11
View File
@@ -39,9 +39,9 @@ export const getRuntime = (ticks: number) => {
if (timeMin > 60) {
const timeHr = Math.floor(timeMin / 60);
timeMin -= timeHr * 60;
formatedTime = `${timeHr}hr ${timeMin}min`;
formatedTime = `${timeHr} ч ${timeMin} мин`;
} else {
formatedTime = `${timeMin}min`;
formatedTime = `${timeMin} мин`;
}
return formatedTime;
};
@@ -61,15 +61,15 @@ export const getRuntimeMusic = (ticks: number) => {
if (timeMin > 60) {
const timeHr = Math.floor(timeMin / 60);
timeMin -= timeHr * 60;
formatedTime = `${timeHr}:${timeMin.toLocaleString([], {
formatedTime = `${timeHr}:${timeMin.toLocaleString("ru-RU", {
minimumIntegerDigits: 2,
useGrouping: false,
})}:${timeSec.toLocaleString([], {
})}:${timeSec.toLocaleString("ru-RU", {
minimumIntegerDigits: 2,
useGrouping: false,
})}`;
} else {
formatedTime = `${timeMin}:${timeSec.toLocaleString([], {
formatedTime = `${timeMin}:${timeSec.toLocaleString("ru-RU", {
minimumIntegerDigits: 2,
useGrouping: false,
})}`;
@@ -91,9 +91,9 @@ export const getRuntimeFull = (ticks: number) => {
if (timeMin > 60) {
const timeHr = Math.floor(timeMin / 60);
timeMin -= timeHr * 60;
formatedTime = `${timeHr} hour ${timeMin} minutes`;
formatedTime = `${timeHr} ч ${timeMin} мин`;
} else {
formatedTime = `${timeMin} minutes`;
formatedTime = `${timeMin} мин`;
}
return formatedTime;
};
@@ -112,9 +112,9 @@ export const getRuntimeCompact = (ticks: number) => {
if (timeMin > 60) {
const timeHr = Math.floor(timeMin / 60);
timeMin -= timeHr * 60;
formatedTime = `${timeHr}h ${timeMin}m`;
formatedTime = `${timeHr} ч ${timeMin} мин`;
} else {
formatedTime = `${timeMin}m`;
formatedTime = `${timeMin} мин`;
}
return formatedTime;
};
@@ -129,11 +129,11 @@ export const endsAt = (ticks: number) => {
const currentTime = current.getTime();
const time = ticksToMs(ticks);
const calculatedTime = currentTime + time;
const formated = new Date(calculatedTime).toLocaleString([], {
const formated = new Date(calculatedTime).toLocaleString("ru-RU", {
hour: "2-digit",
minute: "2-digit",
});
// let formated = `${hr - 12}:${min}`;
// return `Ends at ${formated.getHours()}:${formated.getMinutes()}`;
return `Ends at ${formated}`;
return `Конец в ${formated}`;
};
+116
View File
@@ -0,0 +1,116 @@
import type {
BaseItemDto,
MediaSegmentDto,
MediaSegmentDtoQueryResult,
MediaSegmentType,
} from "@jellyfin/sdk/lib/generated-client";
const SEGMENT_MATCHERS: Array<{
type: MediaSegmentType;
pattern: RegExp;
}> = [
{
type: "Intro",
pattern:
/(intro|opening|title sequence|main title|заставк|опенинг|вступлен|начальн[а-яё]* титр)/i,
},
{
type: "Recap",
pattern:
/(recap|previously on|previously|ранее|в предыдущ|напоминание|краткое содержание)/i,
},
{
type: "Outro",
pattern:
/(outro|end credits|closing credits|end titles|closing titles|credits|ending|титр|концовк|финальн|завершен)/i,
},
{
type: "Preview",
pattern:
/(preview|next episode|next time|on the next|анонс|следующ[а-яё]* сери|превью)/i,
},
{
type: "Commercial",
pattern: /(commercial|ad break|реклам)/i,
},
];
const detectSegmentType = (name?: string | null) => {
if (!name) return null;
for (const matcher of SEGMENT_MATCHERS) {
if (matcher.pattern.test(name)) return matcher.type;
}
return null;
};
const overlaps = (a: MediaSegmentDto, b: MediaSegmentDto) => {
const aStart = a.StartTicks ?? 0;
const aEnd = a.EndTicks ?? aStart;
const bStart = b.StartTicks ?? 0;
const bEnd = b.EndTicks ?? bStart;
return aStart < bEnd && bStart < aEnd;
};
/**
* Jellyfin's MediaSegments API needs a server-side segment provider. Many
* libraries only have chapter markers, so derive the standard segment types
* from well-known chapter names (Recap, Opening Credits, End Credits, ...).
* Existing API segments win; chapters only fill in the gaps.
*/
export const addSegmentsFromChapters = (
item: BaseItemDto | undefined,
mediaSegments: MediaSegmentDtoQueryResult | undefined,
runtimeTicks?: number | null,
): MediaSegmentDtoQueryResult | undefined => {
const chapters = (item?.Chapters ?? [])
.filter((chapter) => typeof chapter.StartPositionTicks === "number")
.sort((a, b) => (a.StartPositionTicks ?? 0) - (b.StartPositionTicks ?? 0));
if (chapters.length === 0) return mediaSegments;
const derived: MediaSegmentDto[] = [];
const seen = new Set<string>();
for (let index = 0; index < chapters.length; index++) {
const chapter = chapters[index];
const type = detectSegmentType(chapter.Name);
if (!type) continue;
const start = chapter.StartPositionTicks ?? 0;
let end =
chapters
.slice(index + 1)
.find((next) => (next.StartPositionTicks ?? 0) > start)
?.StartPositionTicks ?? undefined;
end ??= runtimeTicks ?? item?.RunTimeTicks ?? undefined;
if (!end || end <= start) continue;
const key = `${type}:${start}`;
if (seen.has(key)) continue;
seen.add(key);
derived.push({
Id: `chapter-${type.toLowerCase()}-${start}`,
ItemId: item?.Id,
Type: type,
StartTicks: start,
EndTicks: end,
});
}
if (derived.length === 0) return mediaSegments;
const merged: MediaSegmentDto[] = [...(mediaSegments?.Items ?? [])];
for (const segment of derived) {
if (merged.some((existing) => overlaps(existing, segment))) continue;
merged.push(segment);
}
if (merged.length === 0) return mediaSegments;
merged.sort((a, b) => (a.StartTicks ?? 0) - (b.StartTicks ?? 0));
return {
...mediaSegments,
Items: merged,
TotalRecordCount: merged.length,
StartIndex: 0,
};
};
+102
View File
@@ -0,0 +1,102 @@
type WebKitPresentationMode = "inline" | "fullscreen" | "picture-in-picture";
type WebKitVideoElement = HTMLVideoElement & {
webkitPresentationMode?: WebKitPresentationMode;
webkitSupportsPresentationMode?: (mode: WebKitPresentationMode) => boolean;
webkitSetPresentationMode?: (mode: WebKitPresentationMode) => void;
};
const asWebKitVideo = (video: HTMLVideoElement) => video as WebKitVideoElement;
const isVideoElement = (
element: Element | null | undefined,
): element is HTMLVideoElement => element?.tagName === "VIDEO";
/**
* ReactPlayer may render HLS video inside the shadow DOM of `<hls-video>`.
* Fall back to a regular video element for direct play and other containers.
*/
export const getPlayerVideoElement = (): HTMLVideoElement | null => {
if (typeof document === "undefined") return null;
const shadowVideo = document
.querySelector("hls-video")
?.shadowRoot?.querySelector("video");
if (isVideoElement(shadowVideo)) return shadowVideo;
const video =
document.querySelector(".video-player video") ??
document.querySelector("video");
return isVideoElement(video) ? video : null;
};
export const supportsPictureInPicture = (
video?: HTMLVideoElement | null,
): boolean => {
if (typeof document === "undefined") return false;
if (document.pictureInPictureEnabled) return true;
const candidate =
video ?? (document.createElement("video") as WebKitVideoElement);
try {
return Boolean(
asWebKitVideo(candidate).webkitSupportsPresentationMode?.(
"picture-in-picture",
),
);
} catch {
return false;
}
};
const isPictureInPictureElement = (
element: Element | null,
video: HTMLVideoElement,
): boolean => {
if (!element) return false;
if (element === video) return true;
const root = video.getRootNode();
return root instanceof ShadowRoot && root.host === element;
};
export const isPictureInPictureActive = (video: HTMLVideoElement): boolean => {
if (typeof document === "undefined") return false;
if (isPictureInPictureElement(document.pictureInPictureElement, video)) {
return true;
}
return asWebKitVideo(video).webkitPresentationMode === "picture-in-picture";
};
export const togglePictureInPicture = async (
video: HTMLVideoElement,
): Promise<void> => {
if (isPictureInPictureActive(video)) {
if (isPictureInPictureElement(document.pictureInPictureElement, video)) {
await document.exitPictureInPicture();
return;
}
const webkitVideo = asWebKitVideo(video);
if (webkitVideo.webkitSetPresentationMode) {
webkitVideo.webkitSetPresentationMode("inline");
return;
}
return;
}
if (
document.pictureInPictureEnabled &&
typeof video.requestPictureInPicture === "function"
) {
await video.requestPictureInPicture();
return;
}
const webkitVideo = asWebKitVideo(video);
if (webkitVideo.webkitSupportsPresentationMode?.("picture-in-picture")) {
webkitVideo.webkitSetPresentationMode?.("picture-in-picture");
return;
}
throw new Error("Picture-in-picture is not supported");
};
+1 -1
View File
@@ -99,7 +99,7 @@ export const startPlaybackFromIds = async (
});
if (!playback.mediaSource?.MediaSources?.[0]?.Id) {
throw new Error("No playable media source found");
throw new Error("Не найден источник для воспроизведения");
}
const playbackItems: BaseItemDto[] = playback.item?.Items ?? [];
+7 -7
View File
@@ -83,7 +83,7 @@ export const createSyncPlayGroup = async (api: Api, name: string) => {
try {
const group = (
await syncApi(api).syncPlayCreateGroup({
newGroupRequestDto: { GroupName: name.trim() || "Watch together" },
newGroupRequestDto: { GroupName: name.trim() || "Смотреть вместе" },
})
).data;
if (group) {
@@ -97,7 +97,7 @@ export const createSyncPlayGroup = async (api: Api, name: string) => {
return group;
} catch (error) {
console.error("Could not create SyncPlay group", error);
store.setError("Could not create a group");
store.setError("Не удалось создать группу");
return undefined;
} finally {
store.setLoading(false);
@@ -122,7 +122,7 @@ export const joinSyncPlayGroup = async (api: Api, groupId: string) => {
await refreshSyncPlayGroups(api);
} catch (error) {
console.error("Could not join SyncPlay group", error);
store.setError("Could not join this group");
store.setError("Не удалось войти в группу");
} finally {
store.setLoading(false);
}
@@ -151,7 +151,7 @@ export const startSyncPlayQueue = async (api: Api) => {
.map((item) => item.Id)
.filter((id): id is string => Boolean(id));
if (ids.length === 0) {
store.setError("Start something first, then share the queue");
store.setError("Сначала включите что-нибудь, затем поделитесь очередью");
return;
}
const position = getLocalPlayback();
@@ -173,7 +173,7 @@ export const startSyncPlayQueue = async (api: Api) => {
}
} catch (error) {
console.error("Could not start SyncPlay queue", error);
store.setError("Could not start the group queue");
store.setError("Не удалось запустить очередь группы");
} finally {
store.setLoading(false);
}
@@ -205,7 +205,7 @@ export const watchSyncPlayQueueHere = async (api: Api, userId: string) => {
}
} catch (error) {
console.error("Could not start the group queue here", error);
store.setError("Could not start playback");
store.setError("Не удалось запустить воспроизведение");
} finally {
store.setLoading(false);
}
@@ -364,7 +364,7 @@ export const handleSyncPlayGroupUpdate = async (
applyingRemoteUntil = 0;
break;
case "LibraryAccessDenied":
useSyncPlayStore.getState().setError("No access to this group's library");
useSyncPlayStore.getState().setError("Нет доступа к библиотеке группы");
break;
}
};
+11
View File
@@ -1,4 +1,5 @@
import { load } from "@tauri-apps/plugin-store";
import type { VideoFitMode } from "../types/videoFitMode";
const PlayerStore = await load(".player.dat", { autoSave: true });
@@ -31,3 +32,13 @@ export const getAutoSkipSegments = async () => {
const value = await PlayerStore.get<boolean>("video.autoSkipSegments");
return value ?? false;
};
export const setVideoFitMode = async (mode: VideoFitMode) => {
await PlayerStore.set("video.fitMode", mode);
await PlayerStore.save();
};
export const getVideoFitMode = async (): Promise<VideoFitMode> => {
const value = await PlayerStore.get<VideoFitMode>("video.fitMode");
return value === "fill" || value === "stretch" ? value : "fit";
};
+2 -2
View File
@@ -23,9 +23,9 @@ export const allSettings = {
general: [
{
key: "general.enable_skip_intro_outro",
name: "Enable Intro-Skipper plugin",
name: "Включить плагин Intro-Skipper",
description:
"Shows a skip button for Intros and End Credit scenes in an episode. Note: this requires jumoog/intro-skipper plugin to be installed on server",
"Показывает кнопку пропуска интро и титров в сериях. Для этого на сервере должен быть установлен плагин jumoog/intro-skipper.",
},
],
};
+29 -3
View File
@@ -1,11 +1,13 @@
import type { Api } from "@jellyfin/sdk";
import {
type BaseItemDto,
ItemFields,
type MediaSegmentDtoQueryResult,
type MediaStream,
type PlaybackInfoResponse,
PlayMethod,
} from "@jellyfin/sdk/lib/generated-client";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api/media-info-api";
import { getMediaSegmentApi } from "@jellyfin/sdk/lib/utils/api/media-segment-api";
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
@@ -17,6 +19,7 @@ import { shallow } from "zustand/shallow";
import { createWithEqualityFn } from "zustand/traditional";
import { secToTicks, ticksToSec } from "../date/time";
import getSubtitle from "../methods/getSubtitles";
import { addSegmentsFromChapters } from "../methods/mediaSegments";
import playbackProfile from "../playback-profiles";
import {
getPlayerMuted,
@@ -377,7 +380,7 @@ export const usePlaybackStore = create<
const activeSegment = metadata.mediaSegments?.Items?.find(
(s) => s.Id === activeSegmentId,
);
if (activeSegment && ticks > (activeSegment.EndTicks ?? ticks)) {
if (activeSegment && ticks >= (activeSegment.EndTicks ?? ticks)) {
// If the current time is past the active segment's end time, clear it.
set((state) => {
state.activeSegmentId = null;
@@ -650,7 +653,7 @@ export const usePlaybackStore = create<
}
const segment = segments.find(
(s) =>
(s.StartTicks ?? ticks) <= ticks && (s.EndTicks ?? ticks) >= ticks,
(s.StartTicks ?? ticks) <= ticks && (s.EndTicks ?? ticks) > ticks,
);
const nextIndex = segments.findIndex(
(s) => (s.StartTicks ?? ticks) > ticks,
@@ -735,6 +738,29 @@ export const initializePlayback = async (args: {
const source = mediaSource.MediaSources[0];
const currentUser = (await getUserApi(api).getCurrentUser()).data;
let chapters = item.Chapters;
if (!Array.isArray(chapters) && !mediaSegments?.Items?.length && item.Id) {
try {
const fullItem = (
await getLibraryApi(api).getItems({
ids: [item.Id],
userId,
fields: [ItemFields.Chapters],
})
).data.Items?.[0];
chapters = fullItem?.Chapters;
} catch (error) {
console.warn("Не удалось загрузить главы для сегментов", error);
}
}
const segments = addSegmentsFromChapters(
Array.isArray(chapters) && chapters !== item.Chapters
? { ...item, Chapters: chapters }
: item,
mediaSegments,
item.RunTimeTicks ?? source.RunTimeTicks,
);
let itemName = item.Name;
let episodeTitle = "";
if (item.SeriesId && item.SeriesName) {
@@ -819,7 +845,7 @@ export const initializePlayback = async (args: {
isEpisode: !!item.SeriesId,
itemDuration: item.RunTimeTicks ?? 0,
item: item,
mediaSegments: mediaSegments,
mediaSegments: segments,
userDataLastPlayedPositionTicks:
startPositionTicks ?? item.UserData?.PlaybackPositionTicks ?? 0,
},
+1
View File
@@ -0,0 +1 @@
export type VideoFitMode = "fit" | "fill" | "stretch";