From bec6436b580714e396bb9fedf640e26f3b0e5012 Mon Sep 17 00:00:00 2001 From: Nihal Mirpuri Date: Mon, 29 Jan 2024 07:52:14 +0000 Subject: [PATCH] Increase item limit during plex token retrieval (#85) --- src/main/scala/PlexTokenDeleteSync.scala | 5 ++++- src/main/scala/plex/PlexUtils.scala | 2 ++ src/test/scala/PlexTokenSyncSpec.scala | 2 +- src/test/scala/plex/PlexUtilsSpec.scala | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/scala/PlexTokenDeleteSync.scala b/src/main/scala/PlexTokenDeleteSync.scala index 62b9085..e58ff92 100644 --- a/src/main/scala/PlexTokenDeleteSync.scala +++ b/src/main/scala/PlexTokenDeleteSync.scala @@ -1,3 +1,4 @@ +import WatchlistSync.fetchWatchlistFromRss import cats.data.EitherT import cats.effect.IO import cats.implicits._ @@ -17,10 +18,12 @@ object PlexTokenDeleteSync extends PlexUtils with SonarrUtils with RadarrUtils { val result = for { selfWatchlist <- getSelfWatchlist(config.plexConfiguration, client) othersWatchlist <- if (config.plexConfiguration.skipFriendSync) EitherT.pure[IO, Throwable](Set.empty[Item]) else getOthersWatchlist(config.plexConfiguration, client) + watchlistDatas <- EitherT[IO, Throwable, List[Set[Item]]](config.plexConfiguration.plexWatchlistUrls.map(fetchWatchlistFromRss(client)).toList.sequence.map(Right(_))) + watchlistData = watchlistDatas.flatten.toSet moviesWithoutExclusions <- fetchMovies(client)(config.radarrConfiguration.radarrApiKey, config.radarrConfiguration.radarrBaseUrl, bypass = true) seriesWithoutExclusions <- fetchSeries(client)(config.sonarrConfiguration.sonarrApiKey, config.sonarrConfiguration.sonarrBaseUrl, bypass = true) allIdsWithoutExclusions = moviesWithoutExclusions ++ seriesWithoutExclusions - _ <- missingIdsOnPlex(client)(config)(allIdsWithoutExclusions, selfWatchlist ++ othersWatchlist) + _ <- missingIdsOnPlex(client)(config)(allIdsWithoutExclusions, selfWatchlist ++ othersWatchlist ++ watchlistData) } yield () result.leftMap { diff --git a/src/main/scala/plex/PlexUtils.scala b/src/main/scala/plex/PlexUtils.scala index a1b3fa2..f44d27e 100644 --- a/src/main/scala/plex/PlexUtils.scala +++ b/src/main/scala/plex/PlexUtils.scala @@ -53,6 +53,8 @@ trait PlexUtils { 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) for { response <- EitherT(client.httpRequest(Method.GET, url)) diff --git a/src/test/scala/PlexTokenSyncSpec.scala b/src/test/scala/PlexTokenSyncSpec.scala index 6a00b46..0a86267 100644 --- a/src/test/scala/PlexTokenSyncSpec.scala +++ b/src/test/scala/PlexTokenSyncSpec.scala @@ -66,7 +66,7 @@ class PlexTokenSyncSpec extends AnyFlatSpec with Matchers with MockFactory { private def defaultPlexMock(httpClient: HttpClient): HttpClient = { (httpClient.httpRequest _).expects( Method.GET, - Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=plex-token"), + Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=plex-token&X-Plex-Container-Start=0&X-Plex-Container-Size=300"), None, None ).returning(IO.pure(parse(Source.fromResource("self-watchlist-from-token.json").getLines().mkString("\n")))).once() diff --git a/src/test/scala/plex/PlexUtilsSpec.scala b/src/test/scala/plex/PlexUtilsSpec.scala index 77f33f3..207b769 100644 --- a/src/test/scala/plex/PlexUtilsSpec.scala +++ b/src/test/scala/plex/PlexUtilsSpec.scala @@ -66,7 +66,7 @@ class PlexUtilsSpec extends AnyFlatSpec with Matchers with PlexUtils with MockFa val config = createConfiguration(Set("test-token")) (mockClient.httpRequest _).expects( Method.GET, - Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=test-token"), + Uri.unsafeFromString("https://metadata.provider.plex.tv/library/sections/watchlist/all?X-Plex-Token=test-token&X-Plex-Container-Start=0&X-Plex-Container-Size=300"), None, None ).returning(IO.pure(parse(Source.fromResource("self-watchlist-from-token.json").getLines().mkString("\n")))).once()