-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase item limit during plex token retrieval #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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._ | ||
|
@@ -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(_))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of config.plexConfiguration.plexWatchlistUrls.map(url => fetchWatchlistFromRss(client)(url).attempt).toList.sequence.map(_.collect { case Right(items) => items }) |
||
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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the hardcoded values for pagination ( Suggest adding configuration options or logic to adjust pagination parameters dynamically. |
||
|
||
for { | ||
response <- EitherT(client.httpRequest(Method.GET, url)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the Suggest adding parameterized tests to cover various pagination scenarios. |
||
None, | ||
None | ||
).returning(IO.pure(parse(Source.fromResource("self-watchlist-from-token.json").getLines().mkString("\n")))).once() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the test correctly includes the new pagination parameters, it's important to also verify the behavior when different values for these parameters are used. Consider adding tests to cover scenarios with different starting points and sizes to ensure the pagination logic works as expected across a range of values. Suggest adding parameterized tests to cover a variety of pagination scenarios. |
||
None, | ||
None | ||
).returning(IO.pure(parse(Source.fromResource("self-watchlist-from-token.json").getLines().mkString("\n")))).once() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method
missingIdsOnPlex
correctly iterates over each item to check if it exists in the watchlist. However, the pattern matching inside the loop could be simplified by extracting common logic, such as the creation ofEitherT[IO, Throwable, Unit]
for successful checks, outside the match statement.Consider refactoring to reduce redundancy and improve readability.
The error handling in
missingIdsOnPlex
uses a genericThrowable
for unknown categories, which might obscure the root cause of errors. It's recommended to use more specific exceptions or to include more context in the error message.