From dd19bacea5b95786ad060093f96f7a2597d8068e Mon Sep 17 00:00:00 2001 From: Nihal Mirpuri Date: Sat, 28 Oct 2023 16:35:43 +0100 Subject: [PATCH] Add customizable interval (#3) --- README.md | 30 ++++++++++++++++++++---------- docker/entrypoint.sh | 4 ++++ src/main/scala/Configuration.scala | 4 ++++ src/main/scala/Server.scala | 4 +--- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3abfb97..8810e07 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Sync plex watchlists in realtime with Sonarr and Radarr. **Requires Plex Pass** ## Getting Started + The easiest way to try this code is using docker: ```bash @@ -14,20 +15,23 @@ docker run \ -e PLEX_WATCHLIST_URL_1=YOUR_PLEX_WATCHLIST_URL \ nylonee/watchlistarr ``` -| Key | Example Value | Optional | Description | -|---------------------------|---------------------------------|----------|--------------------------------------------| + +| Key | Example Value | Optional | Description | +|---------------------------|----------------------------------|----------|-----------------------------------------------------------------| +| REFRESH_INTERVAL_SECONDS | 60 | Yes | Number of seconds to wait in between checking the watchlist | | SONARR_API_KEY | 7a392fb4817a46e59f2e84e7d5f021bc | No | API key for Sonarr, found in your Sonarr UI -> General settings | -| SONARR_BASE_URL | http://localhost:8989 | Yes | Base URL for Sonarr, including the 'http' and port | -| SONARR_QUALITY_PROFILE_ID | 6 | No | Quality profile ID for Sonarr | -| SONARR_ROOT_FOLDER | /data/ | Yes | Root folder for Sonarr | +| SONARR_BASE_URL | http://localhost:8989 | Yes | Base URL for Sonarr, including the 'http' and port | +| SONARR_QUALITY_PROFILE_ID | 6 | No | Quality profile ID for Sonarr | +| SONARR_ROOT_FOLDER | /data/ | Yes | Root folder for Sonarr | | RADARR_API_KEY | 7a392fb4817a46e59f2e84e7d5f021bc | No | API key for Radarr, found in your Radarr UI -> General settings | -| RADARR_BASE_URL | http://127.0.0.1:7878 | Yes | Base URL for Radarr, including the 'http' and port | -| RADARR_QUALITY_PROFILE_ID | 6 | No | Quality profile ID for Radarr | -| RADARR_ROOT_FOLDER | /data/ | Yes | Root folder for Radarr | -| PLEX_WATCHLIST_URL_1 | https://rss.plex.tv/UUID | No | First Plex Watchlist URL | -| PLEX_WATCHLIST_URL_2 | https://rss.plex.tv/UUID | Yes | Second Plex Watchlist URL (if applicable) | +| RADARR_BASE_URL | http://127.0.0.1:7878 | Yes | Base URL for Radarr, including the 'http' and port | +| RADARR_QUALITY_PROFILE_ID | 6 | No | Quality profile ID for Radarr | +| RADARR_ROOT_FOLDER | /data/ | Yes | Root folder for Radarr | +| PLEX_WATCHLIST_URL_1 | https://rss.plex.tv/UUID | No | First Plex Watchlist URL | +| PLEX_WATCHLIST_URL_2 | https://rss.plex.tv/UUID | Yes | Second Plex Watchlist URL (if applicable) | ### Getting your Quality Profile IDs + Eventually I will make this easier to get, but for now: 1. Go to your Sonarr/Radarr UI @@ -39,28 +43,34 @@ Eventually I will make this easier to get, but for now: 7. A new entry will show up on the network tab, with a number. This number is your Quality Profile ID ### Getting your Plex Watchlist URLs + 1. Go to [Watchlist settings in Plex](https://app.plex.tv/desktop/#!/settings/watchlist) 2. Generate RSS Feeds for the watchlists you want to monitor, and copy those URLs ## Developers Corner Build the docker image: + ``` docker build -t nylonee/watchlistarr:latest -f docker/Dockerfile . ``` Run the docker image: + ``` docker run nylonee/watchlistarr ``` Run the sbt version: + ``` sbt run ``` Make a fat jar: + ``` sbt assembly ``` + (look in target/scala-2.13/watchlistarr-assembly-VERSION.jar) \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b45ba73..dace1e2 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -42,4 +42,8 @@ if [ -n "$PLEX_WATCHLIST_URL_2" ]; then CMD="$CMD -Dplex.watchlist2=$PLEX_WATCHLIST_URL_2" fi +if [ -n "$REFRESH_INTERVAL_SECONDS" ]; then + CMD="$CMD -Dinterval.seconds=$REFRESH_INTERVAL_SECONDS" +fi + exec $CMD diff --git a/src/main/scala/Configuration.scala b/src/main/scala/Configuration.scala index 63420bb..6917765 100644 --- a/src/main/scala/Configuration.scala +++ b/src/main/scala/Configuration.scala @@ -1,8 +1,12 @@ import cats.effect.IO import cats.effect.unsafe.implicits.global +import scala.concurrent.duration._ + class Configuration { + val refreshInterval: FiniteDuration = getConfigOption("interval.seconds").flatMap(_.toIntOption).getOrElse(60).seconds + val (sonarrBaseUrl, sonarrApiKey) = getAndTestSonarrUrlAndApiKey.unsafeRunSync() // TODO: Grab the quality profile ID automatically if it's not set val sonarrQualityProfileId: Option[Int] = getConfigOption("sonarr.qualityProfile").flatMap(_.toIntOption) diff --git a/src/main/scala/Server.scala b/src/main/scala/Server.scala index 687b012..eeff935 100644 --- a/src/main/scala/Server.scala +++ b/src/main/scala/Server.scala @@ -1,8 +1,6 @@ import cats.effect._ -import scala.concurrent.duration._ - object Server extends IOApp { val config = new Configuration @@ -11,7 +9,7 @@ object Server extends IOApp { def periodicTask: IO[Unit] = WatchlistSync.run(config) >> - IO.sleep(2.seconds) >> + IO.sleep(config.refreshInterval) >> periodicTask periodicTask.foreverM.as(ExitCode.Success)