Skip to content

Commit b950658

Browse files
Add playlist duration to playlist view (#7007)
* Add playlist duration to playlist view Co-authored-by: Sulliva LUONG <sullivanluong@gmail.com> * Always return 0 when any video contains a non-number `lengthSeconds` * Break total playlist time onto new line * Remove self-closing br --------- Co-authored-by: Sulliva LUONG <sullivanluong@gmail.com>
1 parent f31f8a2 commit b950658

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

src/renderer/components/playlist-info/playlist-info.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export default defineComponent({
7575
type: Number,
7676
required: true,
7777
},
78+
totalPlaylistDuration: {
79+
type: Number,
80+
required: true
81+
},
7882
lastUpdated: {
7983
type: String,
8084
default: undefined,
@@ -123,6 +127,18 @@ export default defineComponent({
123127
}
124128
},
125129
computed: {
130+
currentLocale: function () {
131+
return this.$i18n.locale
132+
},
133+
durationFormatted: function () {
134+
const duration = {
135+
hours: Math.floor(this.totalPlaylistDuration / 3600),
136+
minutes: Math.floor((this.totalPlaylistDuration % 3600) / 60),
137+
seconds: this.totalPlaylistDuration % 60,
138+
}
139+
140+
return new Intl.DurationFormat([this.currentLocale, 'en'], { style: 'short' }).format(duration)
141+
},
126142
hideSharingActions: function () {
127143
return this.$store.getters.getHideSharingActions
128144
},

src/renderer/components/playlist-info/playlist-info.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
{{ $t("Playlist.Last Updated On") }}
7878
</span>
7979
{{ lastUpdated }}
80+
<template v-if="durationFormatted !== ''">
81+
<br>
82+
{{ $t('User Playlists.TotalTimePlaylist', { duration: durationFormatted }) }}
83+
</template>
8084
</p>
8185
</template>
8286
</div>

src/renderer/views/Playlist/Playlist.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ export default defineComponent({
243243
sortBySelectValues() {
244244
return this.sortByValues
245245
},
246+
totalPlaylistDuration() {
247+
const totalSeconds = this.playlistItems.reduce((acc, video) => {
248+
if (typeof video.lengthSeconds !== 'number') {
249+
return NaN
250+
}
251+
return acc + video.lengthSeconds
252+
}, 0)
253+
return totalSeconds
254+
},
246255
},
247256
watch: {
248257
$route() {

src/renderer/views/Playlist/Playlist.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
:video-count="videoCount"
2929
:videos="playlistItems"
3030
:view-count="viewCount"
31+
:total-playlist-duration="totalPlaylistDuration"
3132
:info-source="infoSource"
3233
:more-video-data-available="moreVideoDataAvailable"
3334
:search-video-mode-allowed="isUserPlaylistRequested && videoCount > 1"

static/locales/en-US.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ User Playlists:
195195
Cannot delete the quick bookmark target playlist.: Cannot delete the quick bookmark target playlist.
196196
Are you sure you want to delete this playlist? This cannot be undone: Are you sure you want to delete this playlist? This cannot be undone.
197197

198+
TotalTimePlaylist: "Total time: {duration}"
199+
198200
Sort By:
199201
NameAscending: 'A-Z'
200202
NameDescending: 'Z-A'

0 commit comments

Comments
 (0)