Skip to content
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default defineComponent({
loopEnabled: false,
reversePlaylist: false,
pauseOnCurrentVideo: false,
prevVideoBeforeDeletion: null,
channelName: '',
channelId: '',
playlistTitle: '',
Expand Down Expand Up @@ -85,15 +86,7 @@ export default defineComponent({
},

currentVideoIndexZeroBased: function () {
return this.playlistItems.findIndex((item) => {
if (item.playlistItemId != null && this.playlistItemId != null) {
return item.playlistItemId === this.playlistItemId
} else if (item.videoId != null) {
return item.videoId === this.videoId
} else {
return item.id === this.videoId
}
})
return this.findIndexOfCurrentVideoInPlaylist(this.playlistItems)
},
currentVideoIndexOneBased: function () {
return this.currentVideoIndexZeroBased + 1
Expand Down Expand Up @@ -123,16 +116,7 @@ export default defineComponent({

videoIndexInPlaylistItems: function () {
const playlistItems = this.shuffleEnabled ? this.randomizedPlaylistItems : this.playlistItems

return playlistItems.findIndex((item) => {
if (item.playlistItemId != null && this.playlistItemId != null) {
return item.playlistItemId === this.playlistItemId
} else if (item.videoId != null) {
return item.videoId === this.videoId
} else {
return item.id === this.videoId
}
})
return this.findIndexOfCurrentVideoInPlaylist(playlistItems)
},
videoIsFirstPlaylistItem: function () {
return this.videoIndexInPlaylistItems === 0
Expand Down Expand Up @@ -160,12 +144,12 @@ export default defineComponent({
},
selectedUserPlaylistVideoCount () {
// Re-fetch from local store when current user playlist updated
this.parseUserPlaylist(this.selectedUserPlaylist, { allowPlayingVideoRemoval: true })
this.parseUserPlaylist(this.selectedUserPlaylist)
this.shufflePlaylistItems()
},
selectedUserPlaylistLastUpdatedAt () {
// Re-fetch from local store when current user playlist updated
this.parseUserPlaylist(this.selectedUserPlaylist, { allowPlayingVideoRemoval: true })
this.parseUserPlaylist(this.selectedUserPlaylist)
},
videoId: function (newId, oldId) {
// Check if next video is from the shuffled list or if the user clicked a different video
Expand All @@ -186,6 +170,7 @@ export default defineComponent({
},
watchViewLoading: function (newVal, oldVal) {
// This component is loaded/rendered before watch view loaded
this.prevVideoBeforeDeletion = null
if (oldVal && !newVal) {
// Scroll after watch view loaded, otherwise doesn't work
// Mainly for Local API
Expand Down Expand Up @@ -232,6 +217,18 @@ export default defineComponent({
}
},
methods: {
findIndexOfCurrentVideoInPlaylist: function (playlist) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: this should be videos / playlistItems
findIndexOfCurrentVideoInPlaylist is called with various source of video lists (with different sorting orders applied)

return playlist.findIndex((item) => {
if (item.playlistItemId != null && (this.playlistItemId != null || this.prevVideoBeforeDeletion?.playlistItemId != null)) {
return item.playlistItemId === this.playlistItemId || item.playlistItemId === this.prevVideoBeforeDeletion?.playlistItemId
} else if (item.videoId != null) {
return item.videoId === this.videoId || item.videoId === this.prevVideoBeforeDeletion?.videoId
} else {
return item.id === this.videoId || item.id === this.prevVideoBeforeDeletion?.videoId
}
})
},
Comment thread
kommunarr marked this conversation as resolved.

getPlaylistInfoWithDelay: function () {
if (this.getPlaylistInfoRun) { return }

Expand Down Expand Up @@ -348,8 +345,20 @@ export default defineComponent({
playlistType: this.playlistType,
}

const videoIndex = this.videoIndexInPlaylistItems
let videoIndex = this.videoIndexInPlaylistItems

/*
* When the current video being watched in the playlist is deleted,
* the previous video is shown as the "current" one.
* So if we want to play the previous video, in this case,
* we actually want to actually play the "current" video.
*/
if (this.prevVideoBeforeDeletion) {
videoIndex++
}

const targetVideoIndex = (this.videoIsFirstPlaylistItem || this.videoIsNotPlaylistItem) ? this.playlistItems.length - 1 : videoIndex - 1

if (this.shuffleEnabled) {
const targetPlaylistItem = this.randomizedPlaylistItems[targetVideoIndex]

Expand Down Expand Up @@ -466,22 +475,16 @@ export default defineComponent({
})
},

parseUserPlaylist: function (playlist, { allowPlayingVideoRemoval = true } = {}) {
parseUserPlaylist: function (playlist) {
this.playlistTitle = playlist.playlistName
this.channelName = ''
this.channelId = ''

if (this.playlistItems.length === 0 || allowPlayingVideoRemoval) {
this.playlistItems = playlist.videos
} else {
// `this.currentVideo` relies on `playlistItems`
const latestPlaylistContainsCurrentVideo = playlist.videos.some(v => v.playlistItemId === this.playlistItemId)
// Only update list of videos if latest video list still contains currently playing video
if (latestPlaylistContainsCurrentVideo) {
this.playlistItems = playlist.videos
}
if (this.findIndexOfCurrentVideoInPlaylist(playlist.videos) === -1) {
this.prevVideoBeforeDeletion = this.playlistItems[this.currentVideoIndexZeroBased - 1]
}

this.playlistItems = playlist.videos
if (this.reversePlaylist) {
this.playlistItems = this.playlistItems.toReversed()
}
Expand Down