Skip to content

Commit

Permalink
Increase item limit during plex token retrieval (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee committed Jan 29, 2024
1 parent fc9af6c commit bec6436
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/scala/PlexTokenDeleteSync.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import WatchlistSync.fetchWatchlistFromRss
import cats.data.EitherT
import cats.effect.IO
import cats.implicits._
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/plex/PlexUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/PlexTokenSyncSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/plex/PlexUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bec6436

Please sign in to comment.