Skip to content

Commit

Permalink
Bugfix: Watchlists larger than 300 items will now work (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee committed Feb 16, 2024
1 parent 2528cf0 commit 8394741
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/plex/MediaContainer.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package plex

private[plex] case class MediaContainer(Metadata: List[TokenWatchlistItem])
private[plex] case class MediaContainer(Metadata: List[TokenWatchlistItem], totalSize: Int)
16 changes: 11 additions & 5 deletions src/main/scala/plex/PlexUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ trait PlexUtils {
}
}.toList.sequence.map(_ => ())

protected def getSelfWatchlist(config: PlexConfiguration, client: HttpClient): EitherT[IO, Throwable, Set[Item]] = config.plexTokens.map { token =>
protected def getSelfWatchlist(config: PlexConfiguration, client: HttpClient, containerStart: Int = 0): EitherT[IO, Throwable, Set[Item]] = config.plexTokens.map { token =>
val containerSize = 300
val url = Uri
.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all")
.withQueryParam("X-Plex-Token", token)
.withQueryParam("X-Plex-Container-Start", 0) // todo: pagination
.withQueryParam("X-Plex-Container-Size", 300)
.withQueryParam("X-Plex-Container-Start", containerStart)
.withQueryParam("X-Plex-Container-Size", containerSize)

for {
response <- EitherT(client.httpRequest(Method.GET, url))
result <- EitherT(response.as[TokenWatchlist].map(toItems(config, client)).sequence).leftMap(err => new Throwable(err))
} yield result
tokenWatchlist <- EitherT(IO.pure(response.as[TokenWatchlist])).leftMap(err => new Throwable(err))
result <- EitherT.liftF(toItems(config, client)(tokenWatchlist))
nextPage <- if (tokenWatchlist.MediaContainer.totalSize > containerStart + containerSize)
getSelfWatchlist(config, client, containerStart + containerSize)
else
EitherT.pure[IO, Throwable](Set.empty[Item])
} yield result ++ nextPage
}.toList.sequence.map(_.toSet.flatten)

protected def getOthersWatchlist(config: PlexConfiguration, client: HttpClient): EitherT[IO, Throwable, Set[Item]] =
Expand Down

0 comments on commit 8394741

Please sign in to comment.