Skip to content

Commit

Permalink
Merge pull request #3411 from justcallmelarry/feature/add-duration-wh…
Browse files Browse the repository at this point in the history
…en-creating-sessions

Add duration to local sessions on creation
  • Loading branch information
advplyr authored Sep 12, 2024
2 parents 5b09bd8 + d430d9f commit 3d9af89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/managers/PlaybackSessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class PlaybackSessionManager {
// New session from local
session = new PlaybackSession(sessionJson)
session.deviceInfo = deviceInfo
session.setDuration(libraryItem, sessionJson.episodeId)
Logger.debug(`[PlaybackSessionManager] Inserting new session for "${session.displayTitle}" (${session.id})`)
await Database.createPlaybackSession(session)
} else {
Expand Down
14 changes: 9 additions & 5 deletions server/objects/PlaybackSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ class PlaybackSession {
this.displayAuthor = libraryItem.media.getPlaybackAuthor()
this.coverPath = libraryItem.media.coverPath

if (episodeId) {
this.duration = libraryItem.media.getEpisodeDuration(episodeId)
} else {
this.duration = libraryItem.media.duration
}
this.setDuration(libraryItem, episodeId)

this.mediaPlayer = mediaPlayer
this.deviceInfo = deviceInfo || new DeviceInfo()
Expand All @@ -239,6 +235,14 @@ class PlaybackSession {
this.updatedAt = Date.now()
}

setDuration(libraryItem, episodeId) {
if (episodeId) {
this.duration = libraryItem.media.getEpisodeDuration(episodeId)
} else {
this.duration = libraryItem.media.duration
}
}

addListeningTime(timeListened) {
if (!timeListened || isNaN(timeListened)) return

Expand Down

0 comments on commit 3d9af89

Please sign in to comment.