Skip to content

Commit

Permalink
[Feature] Playlist: Sort videos by published date (#6280)
Browse files Browse the repository at this point in the history
* include `published` info for playlisted videos

* playlist: sort videos by published date

* playlist: fix published date formatting for upcoming videos

* playlist: add `premiereDate` to the metadata
  • Loading branch information
GLEBR1K authored Dec 29, 2024
1 parent 32843b2 commit d180612
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,9 @@ export default defineComponent({
description: this.description,
viewCount: this.viewCount,
lengthSeconds: this.data.lengthSeconds,
published: this.published,
premiereDate: this.data.premiereDate,
premiereTimestamp: this.data.premiereTimestamp,
}

this.showAddToPlaylistPromptForManyVideos({ videos: [videoData] })
Expand Down Expand Up @@ -824,6 +827,9 @@ export default defineComponent({
author: this.channelName,
authorId: this.channelId,
lengthSeconds: this.data.lengthSeconds,
published: this.published,
premiereDate: this.data.premiereDate,
premiereTimestamp: this.data.premiereTimestamp,
}

this.addVideo({
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/components/watch-video-info/watch-video-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default defineComponent({
type: Number,
required: true
},
premiereDate: {
type: Date,
default: undefined
},
viewCount: {
type: Number,
required: true
Expand Down Expand Up @@ -348,6 +352,8 @@ export default defineComponent({
description: this.description,
viewCount: this.viewCount,
lengthSeconds: this.lengthSeconds,
published: this.published,
premiereDate: this.premiereDate,
}

this.showAddToPlaylistPromptForManyVideos({ videos: [videoData] })
Expand All @@ -372,6 +378,8 @@ export default defineComponent({
author: this.channelName,
authorId: this.channelId,
lengthSeconds: this.lengthSeconds,
published: this.published,
premiereDate: this.premiereDate,
}

this.addVideo({
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/helpers/playlists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const SORT_BY_VALUES = {
DateAddedNewest: 'date_added_descending',
DateAddedOldest: 'date_added_ascending',
PublishedNewest: 'published_descending',
PublishedOldest: 'published_ascending',
AuthorAscending: 'author_ascending',
AuthorDescending: 'author_descending',
VideoTitleAscending: 'video_title_ascending',
Expand Down Expand Up @@ -48,12 +50,21 @@ export function videoDurationWithFallback(video) {
return 0
}

function publishedWithFallback(video) {
const published = video.published
return typeof published === 'number' && !isNaN(published) && published !== 0 ? published : 0
}

function compareTwoPlaylistItems(a, b, sortOrder, collator) {
switch (sortOrder) {
case SORT_BY_VALUES.DateAddedNewest:
return b.timeAdded - a.timeAdded
case SORT_BY_VALUES.DateAddedOldest:
return a.timeAdded - b.timeAdded
case SORT_BY_VALUES.PublishedNewest:
return publishedWithFallback(b) - publishedWithFallback(a)
case SORT_BY_VALUES.PublishedOldest:
return publishedWithFallback(a) - publishedWithFallback(b)
case SORT_BY_VALUES.VideoTitleAscending:
return collator.compare(a.title, b.title)
case SORT_BY_VALUES.VideoTitleDescending:
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getIconForSortPreference(sortPreference) {
case 'latest_created_first':
case 'latest_played_first':
case 'date_added_descending':
case 'published_descending':
case 'last':
case 'newest':
case 'popular':
Expand All @@ -40,6 +41,7 @@ export function getIconForSortPreference(sortPreference) {
case 'earliest_created_first':
case 'earliest_played_first':
case 'date_added_ascending':
case 'published_ascending':
case 'oldest':
default:
// quantity ascending
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export default defineComponent({
return this.$t('Playlist.Sort By.DateAddedNewest')
case SORT_BY_VALUES.DateAddedOldest:
return this.$t('Playlist.Sort By.DateAddedOldest')
case SORT_BY_VALUES.PublishedNewest:
return this.$t('Playlist.Sort By.PublishedNewest')
case SORT_BY_VALUES.PublishedOldest:
return this.$t('Playlist.Sort By.PublishedOldest')
case SORT_BY_VALUES.VideoTitleAscending:
return this.$t('Playlist.Sort By.VideoTitleAscending')
case SORT_BY_VALUES.VideoTitleDescending:
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default defineComponent({
channelId: '',
channelSubscriptionCountText: '',
videoPublished: 0,
premiereDate: undefined,
videoStoryboardSrc: '',
/** @type {string|null} */
manifestSrc: null,
Expand Down Expand Up @@ -629,9 +630,12 @@ export default defineComponent({
// TODO a I18n entry for time format might be needed here
this.upcomingTimeLeft = new Intl.RelativeTimeFormat(this.currentLocale).format(upcomingTimeLeft, timeUnit)
}

this.premiereDate = upcomingTimestamp
} else {
this.upcomingTimestamp = null
this.upcomingTimeLeft = null
this.premiereDate = undefined
}
} else {
this.videoLengthSeconds = result.basic_info.duration
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
:channel-name="channelName"
:channel-thumbnail="channelThumbnail"
:published="videoPublished"
:premiere-date="premiereDate"
:subscription-count-text="channelSubscriptionCountText"
:like-count="videoLikeCount"
:dislike-count="videoDislikeCount"
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ Playlist:
Sort By: Sort By
DateAddedNewest: Latest added first
DateAddedOldest: Earliest added first
PublishedNewest: Latest published first
PublishedOldest: Earliest published first
AuthorAscending: Author (A-Z)
AuthorDescending: Author (Z-A)
VideoTitleAscending: Title (A-Z)
Expand Down

0 comments on commit d180612

Please sign in to comment.