Skip to content

Commit 5484183

Browse files
absidueAlban Dumas
authored and
Alban Dumas
committed
Add support for Key Moments with the local API (FreeTubeApp#6171)
1 parent 9625668 commit 5484183

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/renderer/components/WatchVideoChapters/WatchVideoChapters.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@keydown.space.stop.prevent="toggleShowChapters"
1313
@keydown.enter.stop.prevent="toggleShowChapters"
1414
>
15-
{{ $t("Chapters.Chapters") }}
15+
{{ kind === 'keyMoments' ? $t('Chapters.Key Moments') : $t("Chapters.Chapters") }}
1616

1717
<span class="currentChapter">
1818
• {{ currentTitle }}
@@ -82,6 +82,10 @@ const props = defineProps({
8282
currentChapterIndex: {
8383
type: Number,
8484
required: true
85+
},
86+
kind: {
87+
type: String,
88+
default: 'chapters'
8589
}
8690
})
8791

src/renderer/views/Watch/Watch.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineComponent } from 'vue'
22
import { mapActions } from 'vuex'
33
import shaka from 'shaka-player'
4+
import { Utils, YTNodes } from 'youtubei.js'
45
import FtLoader from '../../components/ft-loader/ft-loader.vue'
56
import FtShakaVideoPlayer from '../../components/ft-shaka-video-player/ft-shaka-video-player.vue'
67
import WatchVideoInfo from '../../components/watch-video-info/watch-video-info.vue'
@@ -91,6 +92,8 @@ export default defineComponent({
9192
videoLengthSeconds: 0,
9293
videoChapters: [],
9394
videoCurrentChapterIndex: 0,
95+
/** @type {'chapters' | 'keyMoments'} */
96+
videoChaptersKind: 'chapters',
9497
channelName: '',
9598
channelThumbnail: '',
9699
channelId: '',
@@ -450,7 +453,26 @@ export default defineComponent({
450453
})
451454
}
452455
} else {
453-
chapters = this.extractChaptersFromDescription(result.basic_info.short_description ?? result.secondary_info.description.text)
456+
/** @type {import('youtubei.js').YTNodes.MacroMarkersList | null | undefined} */
457+
const macroMarkersList = result.page[1]?.engagement_panels
458+
?.find(pannel => pannel.panel_identifier === 'engagement-panel-macro-markers-auto-chapters')?.content
459+
460+
if (macroMarkersList) {
461+
for (const item of macroMarkersList.contents) {
462+
if (item instanceof YTNodes.MacroMarkersListItem) {
463+
chapters.push({
464+
title: item.title.text,
465+
timestamp: item.time_description.text,
466+
startSeconds: Utils.timeToSeconds(item.time_description.text),
467+
endSeconds: 0,
468+
thumbnail: item.thumbnail[0]
469+
})
470+
}
471+
}
472+
this.videoChaptersKind = 'keyMoments'
473+
} else {
474+
chapters = this.extractChaptersFromDescription(result.basic_info.short_description ?? result.secondary_info.description.text)
475+
}
454476
}
455477

456478
if (chapters.length > 0) {
@@ -1280,6 +1302,7 @@ export default defineComponent({
12801302
clearTimeout(this.playNextTimeout)
12811303
clearInterval(this.playNextCountDownIntervalId)
12821304
this.videoChapters = []
1305+
this.videoChaptersKind = 'chapters'
12831306

12841307
this.handleWatchProgress()
12851308
},

src/renderer/views/Watch/Watch.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
v-if="!hideChapters && !isLoading && videoChapters.length > 0"
152152
:chapters="videoChapters"
153153
:current-chapter-index="videoCurrentChapterIndex"
154+
:kind="videoChaptersKind"
154155
class="watchVideo"
155156
:class="{ theatreWatchVideo: useTheatreMode }"
156157
@timestamp-event="changeTimestamp"

static/locales/en-US.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ Clipboard:
940940

941941
Chapters:
942942
Chapters: Chapters
943+
Key Moments: Key Moments
943944
'Chapters list visible, current chapter: {chapterName}': 'Chapters list visible, current chapter: {chapterName}'
944945
'Chapters list hidden, current chapter: {chapterName}': 'Chapters list hidden, current chapter: {chapterName}'
945946

0 commit comments

Comments
 (0)