-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ target/ | |
|
||
### Environment file for local variables | ||
.env | ||
config/ | ||
|
||
*.txt | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## Watchlistarr Configuration | ||
## Uncomment the lines you would like to configure, then save this file and restart Watchlistarr | ||
|
||
################################################################# | ||
## How often do you want Watchlistarr to pull the latest from Plex? In general, 10 seconds is okay. | ||
## If you're running this on a slower system (e.g. Raspberry Pi), you may want to increase this to 60 seconds. | ||
################################################################# | ||
|
||
#interval: | ||
# seconds: 10 | ||
|
||
|
||
################################################################# | ||
## Sonarr Configuration | ||
################################################################# | ||
|
||
#sonarr: | ||
# baseUrl: "127.0.0.1:8989" # Base URL for Sonarr, including the 'http' and port and any configured urlbase | ||
# apikey: "YOUR-API-KEY" # API key for Sonarr, found in your Sonarr UI -> General settings | ||
# qualityProfile: "Your Desired Sonarr Quality Profile" # If not set, will grab the first one it finds on Sonarr | ||
# rootFolder: "/root/folder/location" # Root folder for Sonarr. If not set, will grab the first one it finds on Sonarr | ||
# bypassIgnored: false | ||
# seasonMonitoring: all # Possible values under 'MonitorTypes' in sonarr.tv/docs/api | ||
# tags: | ||
# - watchlistarr | ||
|
||
|
||
################################################################# | ||
## Radarr Configuration | ||
################################################################# | ||
|
||
#radarr: | ||
# baseUrl: "127.0.0.1:7878" # Base URL for Radarr, including the 'http' and port and any configured urlbase | ||
# apikey: "YOUR-API-KEY" | ||
# qualityProfile: "Your Desired Radarr Quality Profile" # If not set, will grab the first one it finds on Radarr | ||
# rootFolder: "/root/folder/location" # If not set, will grab the first one it finds on Radarr | ||
# bypassIgnored: false # Boolean flag to bypass tv shows that are on the Sonarr Exclusion List | ||
# tags: | ||
# - watchlistarr | ||
|
||
|
||
################################################################# | ||
## Plex Configuration | ||
################################################################# | ||
|
||
#plex: | ||
# token: "YOUR-PLEX-TOKEN" # Multiple tokens can be provided | ||
# skipfriendsync: false # Don't sync friends watchlists, only your own | ||
|
||
|
||
################################################################# | ||
## Delete Sync Configuration | ||
################################################################# | ||
|
||
#delete: | ||
# movie: false # If enabled, movies that are not watchlisted will be deleted from Radarr | ||
# endedShow: false # If enabled, shows that have no more planned seasons and are not watchlisted will be deleted from Sonarr | ||
# continuingShow: false # If enabled, shows that still have planned seasons and are not watchlisted will be deleted from Sonarr | ||
# interval.days: 7 # Number of days to wait before deleting content from the arrs (Deleting must be enabled) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/scala/configuration/FileAndSystemPropertyReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package configuration | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.yaml.snakeyaml.Yaml | ||
|
||
import java.io.{File, FileInputStream} | ||
import java.nio.file.{Files, Paths, StandardCopyOption} | ||
import java.util | ||
import scala.jdk.CollectionConverters.{ListHasAsScala, MapHasAsScala} | ||
|
||
object FileAndSystemPropertyReader extends ConfigurationReader { | ||
|
||
private val logger = LoggerFactory.getLogger(getClass) | ||
|
||
private lazy val data: Map[String, String] = { | ||
val yaml = new Yaml() | ||
val configDirPath = "config" | ||
val configFile = new File(s"$configDirPath/config.yaml") | ||
|
||
try { | ||
// Ensure parent config folder exists | ||
val parentDir = configFile.getParentFile | ||
if (!parentDir.exists()) parentDir.mkdirs() | ||
|
||
if (!configFile.exists()) { | ||
val resourceStream = getClass.getClassLoader.getResourceAsStream("config-template.yaml") | ||
if (resourceStream != null) { | ||
try { | ||
Files.copy(resourceStream, Paths.get(configFile.toURI), StandardCopyOption.REPLACE_EXISTING) | ||
logger.info(s"Created config file in ${configFile.getPath}") | ||
} finally { | ||
resourceStream.close() | ||
} | ||
} else { | ||
logger.debug("config-template.yaml resource not found") | ||
} | ||
} | ||
|
||
if (configFile.exists()) { | ||
val inputStream = new FileInputStream(configFile) | ||
val result = yaml.load[util.Map[String, Object]](inputStream).asScala | ||
inputStream.close() | ||
flattenYaml(Map.from(result)) | ||
} else { | ||
Map.empty[String, String] | ||
} | ||
} catch { | ||
case e: Exception => | ||
logger.debug(s"Failed to read from config.yaml: ${e.getMessage}") | ||
Map.empty[String, String] | ||
} | ||
} | ||
|
||
override def getConfigOption(key: String): Option[String] = | ||
if (data.contains(key)) | ||
data.get(key) | ||
else | ||
SystemPropertyReader.getConfigOption(key) | ||
|
||
private def flattenYaml(yaml: Map[String, _]): Map[String, String] = yaml.flatMap { | ||
case (k, v: util.ArrayList[_]) => | ||
List((k, v.asScala.mkString(","))) | ||
|
||
case (k, v: String) => | ||
List((k, v)) | ||
|
||
case (k, v: Integer) => | ||
List((k, v.toString)) | ||
|
||
case (k, v: java.lang.Boolean) => | ||
List((k, v.toString)) | ||
|
||
case (k, v: util.LinkedHashMap[String, _]) => | ||
val flattenedInner = flattenYaml(Map.from(v.asScala)) | ||
flattenedInner.map { case (innerK, innerV) => | ||
(s"$k.$innerK", innerV) | ||
}.toList | ||
|
||
case (k, v) => | ||
logger.warn(s"Unhandled config pair of type: ${k.getClass} -> ${v.getClass}") | ||
List((k, v.toString)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package configuration | ||
|
||
object SystemPropertyReader extends ConfigurationReader { | ||
def getConfigOption(key: String): Option[String] = Option(System.getProperty(key)) | ||
override def getConfigOption(key: String): Option[String] = Option(System.getProperty(key)) | ||
} |