Skip to content

Commit

Permalink
Merge RSS and token sync, fix docker environments with spaces in env …
Browse files Browse the repository at this point in the history
…variables (#91)
  • Loading branch information
nylonee committed Feb 13, 2024
1 parent 9c9c423 commit 69b2643
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 421 deletions.
47 changes: 23 additions & 24 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,87 +1,86 @@
#!/bin/bash
CMD=("/app/bin/watchlistarr")

CMD="/app/bin/watchlistarr"

JAVA_OPTS="-Xmx100m"
JAVA_OPTS=(-Xmx100m)

if [ -n "$SONARR_API_KEY" ]; then
CMD="$CMD -Dsonarr.apikey=$SONARR_API_KEY"
CMD+=("-Dsonarr.apikey=$SONARR_API_KEY")
fi

if [ -n "$SONARR_BASE_URL" ]; then
CMD="$CMD -Dsonarr.baseUrl=$SONARR_BASE_URL"
CMD+=("-Dsonarr.baseUrl=$SONARR_BASE_URL")
fi

if [ -n "$SONARR_QUALITY_PROFILE" ]; then
CMD="$CMD -Dsonarr.qualityProfile=$SONARR_QUALITY_PROFILE"
CMD+=("-Dsonarr.qualityProfile=$SONARR_QUALITY_PROFILE")
fi

if [ -n "$SONARR_ROOT_FOLDER" ]; then
CMD="$CMD -Dsonarr.rootFolder=$SONARR_ROOT_FOLDER"
CMD+=("-Dsonarr.rootFolder=$SONARR_ROOT_FOLDER")
fi

if [ -n "$RADARR_API_KEY" ]; then
CMD="$CMD -Dradarr.apikey=$RADARR_API_KEY"
CMD+=("-Dradarr.apikey=$RADARR_API_KEY")
fi

if [ -n "$RADARR_BASE_URL" ]; then
CMD="$CMD -Dradarr.baseUrl=$RADARR_BASE_URL"
CMD+=("-Dradarr.baseUrl=$RADARR_BASE_URL")
fi

if [ -n "$RADARR_QUALITY_PROFILE" ]; then
CMD="$CMD -Dradarr.qualityProfile=$RADARR_QUALITY_PROFILE"
CMD+=("-Dradarr.qualityProfile=$RADARR_QUALITY_PROFILE")
fi

if [ -n "$RADARR_ROOT_FOLDER" ]; then
CMD="$CMD -Dradarr.rootFolder=$RADARR_ROOT_FOLDER"
CMD+=("-Dradarr.rootFolder=$RADARR_ROOT_FOLDER")
fi

if [ -n "$PLEX_WATCHLIST_URL_1" ]; then
CMD="$CMD -Dplex.watchlist1=$PLEX_WATCHLIST_URL_1"
CMD+=("-Dplex.watchlist1=$PLEX_WATCHLIST_URL_1")
fi

if [ -n "$PLEX_WATCHLIST_URL_2" ]; then
CMD="$CMD -Dplex.watchlist2=$PLEX_WATCHLIST_URL_2"
CMD+=("-Dplex.watchlist2=$PLEX_WATCHLIST_URL_2")
fi

if [ -n "$REFRESH_INTERVAL_SECONDS" ]; then
CMD="$CMD -Dinterval.seconds=$REFRESH_INTERVAL_SECONDS"
CMD+=("-Dinterval.seconds=$REFRESH_INTERVAL_SECONDS")
fi

if [ -n "$SONARR_BYPASS_IGNORED" ]; then
CMD="$CMD -Dsonarr.bypassIgnored=$SONARR_BYPASS_IGNORED"
CMD+=("-Dsonarr.bypassIgnored=$SONARR_BYPASS_IGNORED")
fi

if [ -n "$RADARR_BYPASS_IGNORED" ]; then
CMD="$CMD -Dradarr.bypassIgnored=$RADARR_BYPASS_IGNORED"
CMD+=("-Dradarr.bypassIgnored=$RADARR_BYPASS_IGNORED")
fi

if [ -n "$SONARR_SEASON_MONITORING" ]; then
CMD="$CMD -Dsonarr.seasonMonitoring=$SONARR_SEASON_MONITORING"
CMD+=("-Dsonarr.seasonMonitoring=$SONARR_SEASON_MONITORING")
fi

if [ -n "$PLEX_TOKEN" ]; then
CMD="$CMD -Dplex.token=$PLEX_TOKEN"
CMD+=("-Dplex.token=$PLEX_TOKEN")
fi

if [ -n "$SKIP_FRIEND_SYNC" ]; then
CMD="$CMD -Dplex.skipfriendsync=$SKIP_FRIEND_SYNC"
CMD+=("-Dplex.skipfriendsync=$SKIP_FRIEND_SYNC")
fi

if [ -n "$ALLOW_MOVIE_DELETING" ]; then
CMD="$CMD -Ddelete.movie=$ALLOW_MOVIE_DELETING"
CMD+=("-Ddelete.movie=$ALLOW_MOVIE_DELETING")
fi

if [ -n "$ALLOW_ENDED_SHOW_DELETING" ]; then
CMD="$CMD -Ddelete.endedShow=$ALLOW_ENDED_SHOW_DELETING"
CMD+=("-Ddelete.endedShow=$ALLOW_ENDED_SHOW_DELETING")
fi

if [ -n "$ALLOW_CONTINUING_SHOW_DELETING" ]; then
CMD="$CMD -Ddelete.continuingShow=$ALLOW_CONTINUING_SHOW_DELETING"
CMD+=("-Ddelete.continuingShow=$ALLOW_CONTINUING_SHOW_DELETING")
fi

if [ -n "$DELETE_INTERVAL_DAYS" ]; then
CMD="$CMD -Ddelete.interval.days=$DELETE_INTERVAL_DAYS"
CMD+=("-Ddelete.interval.days=$DELETE_INTERVAL_DAYS")
fi

exec $CMD $JAVA_OPTS
exec "${CMD[@]}" "${JAVA_OPTS[@]}"
1 change: 0 additions & 1 deletion src/main/scala/PlexTokenDeleteSync.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import WatchlistSync.fetchWatchlistFromRss
import cats.data.EitherT
import cats.effect.IO
import cats.implicits._
Expand Down
21 changes: 13 additions & 8 deletions src/main/scala/PlexTokenSync.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ object PlexTokenSync extends PlexUtils with SonarrUtils with RadarrUtils {

private val logger = LoggerFactory.getLogger(getClass)

def run(config: Configuration, client: HttpClient): IO[Unit] = {
def run(config: Configuration, client: HttpClient, firstRun: Boolean): IO[Unit] = {
val result = for {
selfWatchlist <- getSelfWatchlist(config.plexConfiguration, client)
_ = logger.info(s"Found ${selfWatchlist.size} items on user's watchlist using the plex token")
othersWatchlist <- if (config.plexConfiguration.skipFriendSync)
selfWatchlist <- if (firstRun)
getSelfWatchlist(config.plexConfiguration, client)
else
EitherT.pure[IO, Throwable](Set.empty[Item])
_ = if (firstRun) logger.info(s"Found ${selfWatchlist.size} items on user's watchlist using the plex token")
othersWatchlist <- if (!firstRun || config.plexConfiguration.skipFriendSync)
EitherT.pure[IO, Throwable](Set.empty[Item])
else
getOthersWatchlist(config.plexConfiguration, client)
_ = logger.info(s"Found ${othersWatchlist.size} items on other available watchlists using the plex token")
watchlistDatas <- EitherT[IO, Throwable, List[Set[Item]]](config.plexConfiguration.plexWatchlistUrls.map(fetchWatchlistFromRss(client)).toList.sequence.map(Right(_)))
watchlistData = watchlistDatas.flatten.toSet
_ = if (firstRun) logger.info(s"Found ${othersWatchlist.size} items on other available watchlists using the plex token")
movies <- fetchMovies(client)(config.radarrConfiguration.radarrApiKey, config.radarrConfiguration.radarrBaseUrl, config.radarrConfiguration.radarrBypassIgnored)
series <- fetchSeries(client)(config.sonarrConfiguration.sonarrApiKey, config.sonarrConfiguration.sonarrBaseUrl, config.sonarrConfiguration.sonarrBypassIgnored)
allIds = movies ++ series
_ <- missingIds(client)(config)(allIds, selfWatchlist ++ othersWatchlist)
_ <- missingIds(client)(config)(allIds, selfWatchlist ++ othersWatchlist ++ watchlistData)
} yield ()

result.leftMap {
Expand All @@ -50,15 +55,15 @@ object PlexTokenSync extends PlexUtils with SonarrUtils with RadarrUtils {
logger.debug(s"Found show \"${watchlistedItem.title}\" which does not exist yet in Sonarr")
Right(addToSonarr(client)(config.sonarrConfiguration)(watchlistedItem))
} else {
logger.warn(s"Found show \"${watchlistedItem.title}\" which does not exist yet in Sonarr, but we do not have the tvdb ID so will skip adding")
logger.debug(s"Found show \"${watchlistedItem.title}\" which does not exist yet in Sonarr, but we do not have the tvdb ID so will skip adding")
Right(IO.unit)
}
case (false, "movie") =>
if (watchlistedItem.getTmdbId.isDefined) {
logger.debug(s"Found movie \"${watchlistedItem.title}\" which does not exist yet in Radarr")
Right(addToRadarr(client)(config.radarrConfiguration)(watchlistedItem))
} else {
logger.warn(s"Found movie \"${watchlistedItem.title}\" which does not exist yet in Radarr, but we do not have the tmdb ID so will skip adding")
logger.debug(s"Found movie \"${watchlistedItem.title}\" which does not exist yet in Radarr, but we do not have the tmdb ID so will skip adding")
Right(IO.unit)
}

Expand Down
17 changes: 5 additions & 12 deletions src/main/scala/Server.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import cats.effect._
import cats.implicits.catsSyntaxTuple4Parallel
import cats.implicits.catsSyntaxTuple3Parallel
import configuration.{Configuration, ConfigurationUtils, SystemPropertyReader}
import http.HttpClient
import org.slf4j.LoggerFactory
Expand All @@ -24,22 +24,13 @@ object Server extends IOApp {
for {
memoizedConfigIo <- ConfigurationUtils.create(configReader, httpClient).memoize
result <- (
watchlistSync(memoizedConfigIo, httpClient),
pingTokenSync(memoizedConfigIo, httpClient),
plexTokenSync(memoizedConfigIo, httpClient),
plexTokenDeleteSync(memoizedConfigIo, httpClient)
).parTupled.as(ExitCode.Success)
} yield result
}

private def watchlistSync(configIO: IO[Configuration], httpClient: HttpClient): IO[Unit] =
for {
config <- configIO
_ <- WatchlistSync.run(config, httpClient)
_ <- IO.sleep(config.refreshInterval)
_ <- watchlistSync(configIO, httpClient)
} yield ()

private def pingTokenSync(configIO: IO[Configuration], httpClient: HttpClient): IO[Unit] =
for {
config <- configIO
Expand All @@ -48,10 +39,12 @@ object Server extends IOApp {
_ <- pingTokenSync(configIO, httpClient)
} yield ()

private def plexTokenSync(configIO: IO[Configuration], httpClient: HttpClient): IO[Unit] =
private def plexTokenSync(configIO: IO[Configuration], httpClient: HttpClient, firstRun: Boolean = true): IO[Unit] =
for {
config <- configIO
_ <- PlexTokenSync.run(config, httpClient)
_ <- PlexTokenSync.run(config, httpClient, firstRun)
_ <- IO.sleep(config.refreshInterval)
_ <- plexTokenSync(configIO, httpClient, firstRun = false)
} yield ()

private def plexTokenDeleteSync(configIO: IO[Configuration], httpClient: HttpClient): IO[Unit] =
Expand Down
70 changes: 0 additions & 70 deletions src/main/scala/WatchlistSync.scala

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/scala/PlexTokenSyncSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlexTokenSyncSpec extends AnyFlatSpec with Matchers with MockFactory {
defaultRadarrMock(mockHttpClient)
defaultSonarrMock(mockHttpClient)

val sync: Unit = PlexTokenSync.run(config, mockHttpClient).unsafeRunSync()
val sync: Unit = PlexTokenSync.run(config, mockHttpClient, firstRun = true).unsafeRunSync()

sync shouldBe ()
}
Expand All @@ -51,7 +51,7 @@ class PlexTokenSyncSpec extends AnyFlatSpec with Matchers with MockFactory {
radarrBypassIgnored = false
),
PlexConfiguration(
plexWatchlistUrls = Set(Uri.unsafeFromString("https://localhost:9090")),
plexWatchlistUrls = Set(),
plexTokens = plexTokens,
skipFriendSync = false
),
Expand Down

0 comments on commit 69b2643

Please sign in to comment.