Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/layouts/default/PlayerOSD/PlayerFullscreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
{{ $t("off") }}
</v-card-subtitle>

<!-- SUBTITLE: current (audiobook) chapter -->
<v-card-subtitle
v-if="store.curChapter"
class="text-h6 text-md-h5 text-lg-h4"
>
{{ store.curChapter.name }}
</v-card-subtitle>

<!-- live (stream) metadata (artist + title) -->
<v-card-subtitle
v-if="
Expand Down
64 changes: 45 additions & 19 deletions src/layouts/default/PlayerOSD/PlayerTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"
style="width: 100%"
:min="0"
:max="store.curQueueItem?.duration"
:max="playerCurQueueItemDuration"
hide-details
:track-size="4"
:thumb-size="isThumbHidden ? 0 : 10"
Expand Down Expand Up @@ -88,36 +88,63 @@ const isDragging = ref(false);
const curTimeValue = ref(0);
const tempTime = ref(0);

const chapterTime = computed(() =>
localStorage.getItem("frontend.settings.audiobook_chapter_time") == "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain a computed property is the right way to do this ?
Like, will it only be computed once and not over and over ?

Copy link
Author

@tsipinakis tsipinakis Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, have not used vue before this. I'm open to ideas.

On the other hand: Does it matter? How much overhead is a map lookup?

);

// computed properties
const playerCurQueueItemDuration = computed(() => {
if (
chapterTime.value &&
store.curQueueItem?.media_item?.media_type == MediaType.AUDIOBOOK
) {
if (!store.curChapter?.end) return 0;
return store.curChapter?.end - store.curChapter?.start;
}
return store.curQueueItem?.duration;
});

const curQueueItemTime = computed(() => {
if (isDragging.value) {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
tempTime.value = curTimeValue.value;
return curTimeValue.value;
}

if (store.activePlayerQueue) {
if (
chapterTime.value &&
store.curQueueItem?.media_item?.media_type == MediaType.AUDIOBOOK
) {
if (!store.curChapter?.start) return 0;
return store.activePlayerQueue?.elapsed_time - store.curChapter?.start;
}
return store.activePlayerQueue.elapsed_time;
}
return 0;
});

const playerCurTimeStr = computed(() => {
if (!store.curQueueItem) return "0:00";
if (!playerCurQueueItemDuration.value || !curQueueItemTime.value) return "0:00";
if (showRemainingTime.value) {
return `-${formatDuration(
store.curQueueItem.duration - curQueueItemTime.value,
playerCurQueueItemDuration.value - curQueueItemTime.value,
)}`;
} else {
return `${formatDuration(curQueueItemTime.value)}`;
}
});

const playerTotalTimeStr = computed(() => {
if (!store.curQueueItem) return "";
if (!store.curQueueItem.duration) return "";
if (!playerCurQueueItemDuration.value || !store.curQueueItem) return "";
if (store.curQueueItem.media_item?.media_type == MediaType.RADIO) return "";
const totalSecs = store.curQueueItem.duration;
const totalSecs = playerCurQueueItemDuration.value;
return formatDuration(totalSecs);
});
const curQueueItemTime = computed(() => {
if (isDragging.value) {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
tempTime.value = curTimeValue.value;
return curTimeValue.value;
}
if (store.activePlayerQueue) return store.activePlayerQueue.elapsed_time;
return 0;
});

const chapterTicks = computed(() => {
const ticks: Record<number, string> = {};
if (chapterTime.value) return [];
if (store.curQueueItem?.media_item?.metadata?.chapters) {
store.curQueueItem.media_item.metadata.chapters.forEach((chapter) => {
ticks[chapter.start] = chapter.name;
Expand All @@ -141,10 +168,9 @@ const startDragging = function () {
const stopDragging = () => {
isDragging.value = false;
if (!isDragging.value && store.activePlayer) {
api.playerCommandSeek(
store.activePlayer.player_id,
Math.round(tempTime.value),
);
var seekTime = tempTime.value;
if (store.curChapter?.start && chapterTime.value) seekTime = store.curChapter?.start + seekTime;
api.playerCommandSeek(store.activePlayer.player_id, Math.round(seekTime));
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/layouts/default/PlayerOSD/PlayerTrackDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@
>
{{ store.curQueueItem.media_item.podcast.name }}
</div>
<!-- audiobook - current chapter as subtitle -->
<div
v-else-if="
store.curQueueItem?.media_item &&
store.curQueueItem.media_item?.media_type == MediaType.AUDIOBOOK &&
store.curChapter
"
>
{{ store.curChapter.name }}
</div>
<!-- live (stream) metadata (artist + title) -->
<div
v-else-if="
Expand Down
16 changes: 15 additions & 1 deletion src/plugins/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, reactive } from "vue";
import { MediaType, Player, PlayerQueue, QueueItem } from "./api/interfaces";
import { MediaType, Player, PlayerQueue, QueueItem, MediaItemChapter } from "./api/interfaces";

import api from "./api";
import { StoredState } from "@/components/ItemsListing.vue";
Expand Down Expand Up @@ -43,6 +43,7 @@ interface Store {
activePlayer?: Player;
activePlayerQueue?: PlayerQueue;
curQueueItem?: QueueItem;
curChapter?: MediaItemChapter;
globalSearchTerm?: string;
globalSearchType?: MediaType;
prevState?: StoredState;
Expand Down Expand Up @@ -102,6 +103,19 @@ export const store: Store = reactive({
return store.activePlayerQueue.current_item;
return undefined;
}),
curChapter: computed(() => {
if (store.curQueueItem?.media_item?.metadata?.chapters) {
return store.curQueueItem.media_item.metadata.chapters.find((chapter) => {
if (!store.activePlayerQueue?.elapsed_time) return undefined;
if (!chapter.end) return undefined;
return (
chapter.start < store.activePlayerQueue?.elapsed_time &&
chapter.end > store.activePlayerQueue?.elapsed_time
);
});
}
return undefined;
}),
globalSearchTerm: undefined,
globalSearchType: undefined,
prevState: undefined,
Expand Down
4 changes: 4 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@
"unmaintained": "Unmaintained",
"deprecated": "Deprecated"
}
},
"audiobook_chapter_time": {
"label": "Audiobook Chapter Progress",
"description": "Show the progress of the current chapter instead of the full duration when playing audiobooks."
}
},
"show_info": "Show info",
Expand Down
12 changes: 12 additions & 0 deletions src/views/settings/FrontendConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ onMounted(() => {
localStorage.getItem("frontend.settings.force_mobile_layout") !=
"false",
},
{
key: "audiobook_chapter_time",
type: ConfigEntryType.BOOLEAN,
label: "chapter_time",
default_value: false,
required: false,
multi_value: false,
category: "audiobooks_podcasts",
value:
localStorage.getItem("frontend.settings.audiobook_chapter_time") ==
"true",
},
];
});

Expand Down