Skip to content

Commit

Permalink
Add customizable interval (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee authored Oct 28, 2023
1 parent 10ae136 commit dd19bac
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
4 changes: 4 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/main/scala/Configuration.scala
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/Server.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import cats.effect._

import scala.concurrent.duration._

object Server extends IOApp {

val config = new Configuration
Expand All @@ -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)
Expand Down

0 comments on commit dd19bac

Please sign in to comment.