Skip to content

Commit

Permalink
fix: check for present video duration in history (with small refactor…
Browse files Browse the repository at this point in the history
…ing)
  • Loading branch information
Hoverth committed Oct 4, 2024
1 parent e630b53 commit 7f140e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/renderer/helpers/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export function getSortedPlaylistItems(playlistItems, sortOrder, locale, reverse
})
}

export function videoDurationPresent(v) {
if (typeof v.lengthSeconds !== 'number') { return false }
export function videoDurationPresent(video) {
if (typeof video.lengthSeconds !== 'number') { return false }

return !(isNaN(v.lengthSeconds) || v.lengthSeconds === 0)
return !(isNaN(video.lengthSeconds) || video.lengthSeconds === 0)
}

function videoDurationWithFallback(v) {
if (videoDurationPresent(v)) { return v.lengthSeconds }
export function videoDurationWithFallback(video) {
if (videoDurationPresent(video)) { return video.lengthSeconds }

// Fallback
return 0
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
deepCopy,
} from '../../helpers/utils'
import { invidiousGetPlaylistInfo, youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { getSortedPlaylistItems, videoDurationPresent, SORT_BY_VALUES } from '../../helpers/playlists'
import { getSortedPlaylistItems, videoDurationPresent, videoDurationWithFallback, SORT_BY_VALUES } from '../../helpers/playlists'
import packageDetails from '../../../../package.json'
import { MOBILE_WIDTH_THRESHOLD, PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD } from '../../../constants'

Expand Down Expand Up @@ -442,7 +442,7 @@ export default defineComponent({

const videoHistory = this.$store.getters.getHistoryCacheById[video.videoId]
if (typeof videoHistory !== 'undefined') {
video.lengthSeconds = videoHistory.lengthSeconds
video.lengthSeconds = videoDurationWithFallback(videoHistory)
} else {
// Mark at least one video have no duration, show notice later
// Also assign fallback duration here
Expand Down

0 comments on commit 7f140e2

Please sign in to comment.