Skip to content

Commit

Permalink
Fix playback position sync with Plex (#20) (#25)
Browse files Browse the repository at this point in the history
Plex requires the playbackTime to be the track progress, not the current epoch
  • Loading branch information
KevinDenis authored Feb 16, 2022
1 parent a92a940 commit 372f6a3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class PlexSyncScrobbleWorker(
val trackId = inputData.requireInt(TRACK_ID_ARG)
val playbackState = inputData.requireString(TRACK_STATE_ARG)
val trackProgress = inputData.requireLong(TRACK_POSITION_ARG)
val playbackTimeStamp = inputData.requireLong(PLAYBACK_TIME_STAMP)
val bookProgress = inputData.requireLong(BOOK_PROGRESS)
try {
workerScope.launch(Injector.get().unhandledExceptionHandler()) {
Expand All @@ -64,7 +63,7 @@ class PlexSyncScrobbleWorker(
Injector.get().plexMediaService().progress(
ratingKey = trackId.toString(),
offset = trackProgress.toString(),
playbackTime = playbackTimeStamp,
playbackTime = trackProgress,
playQueueItemId = track.playQueueItemID,
key = "${MediaItemTrack.PARENT_KEY_PREFIX}$trackId",
// IMPORTANT: Plex normally marks as finished at 90% progress, but it
Expand Down Expand Up @@ -125,22 +124,19 @@ class PlexSyncScrobbleWorker(
const val TRACK_ID_ARG = "Track ID"
const val TRACK_STATE_ARG = "State"
const val TRACK_POSITION_ARG = "Track position"
const val PLAYBACK_TIME_STAMP = "Original play time"
const val BOOK_PROGRESS = "Book progress"

fun makeWorkerData(
trackId: Int,
playbackState: String,
trackProgress: Long,
bookProgress: Long,
playbackTimeStamp: Long = System.currentTimeMillis()
): Data {
require(trackId != TRACK_NOT_FOUND)
return workDataOf(
TRACK_ID_ARG to trackId,
TRACK_POSITION_ARG to trackProgress,
TRACK_STATE_ARG to playbackState,
PLAYBACK_TIME_STAMP to playbackTimeStamp,
BOOK_PROGRESS to bookProgress
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class SimpleProgressUpdater @Inject constructor(
trackId,
playbackState,
trackProgress,
currentTime,
bookProgress
)
}
Expand All @@ -170,7 +169,6 @@ class SimpleProgressUpdater @Inject constructor(
trackId: Int,
playbackState: String,
trackProgress: Long,
currentTime: Long,
bookProgress: Long
) {
val syncWorkerConstraints =
Expand All @@ -179,7 +177,6 @@ class SimpleProgressUpdater @Inject constructor(
trackId = trackId,
playbackState = playbackState,
trackProgress = trackProgress,
playbackTimeStamp = currentTime,
bookProgress = bookProgress
)
val worker = OneTimeWorkRequestBuilder<PlexSyncScrobbleWorker>()
Expand Down

0 comments on commit 372f6a3

Please sign in to comment.