Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Playlist: Sort videos by published date #6280

Merged
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
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 @@ -32,6 +32,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 @@ -42,6 +43,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 @@ -216,6 +216,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 @@ -99,6 +99,7 @@ export default defineComponent({
channelId: '',
channelSubscriptionCountText: '',
videoPublished: 0,
premiereDate: undefined,
videoStoryboardSrc: '',
/** @type {string|null} */
manifestSrc: null,
Expand Down Expand Up @@ -627,9 +628,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 @@ -122,6 +122,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 @@ -918,6 +918,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
Loading