259 lines
7.2 KiB
Go
259 lines
7.2 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"gopkg.in/vansante/go-ffprobe.v2"
|
|
)
|
|
|
|
type ConfigInterface interface {
|
|
EnableRepair() bool
|
|
EnableRetainFolderNameExtension() bool
|
|
EnableRetainRDTorrentName() bool
|
|
GetAPIRateLimitPerSecond() int
|
|
GetApiTimeoutSecs() int
|
|
GetConfig() ZurgConfig
|
|
GetDirectories() []string
|
|
GetDownloadsEveryMins() int
|
|
GetDownloadTimeoutSecs() int
|
|
GetDownloadTokens() []string
|
|
GetDumpTorrentsEveryMins() int
|
|
GetHost() string
|
|
GetNumberOfHosts() int
|
|
GetNumberOfWorkers() int
|
|
GetOnLibraryUpdate() string
|
|
GetPassword() string
|
|
GetPlayableExtensions() []string
|
|
GetPort() string
|
|
GetProxy() string
|
|
GetRarAction() string
|
|
GetRefreshEverySecs() int
|
|
GetRepairEveryMins() int
|
|
GetRetriesUntilFailed() int
|
|
GetToken() string
|
|
GetTorrentsRateLimitPerSecond() int
|
|
GetUsername() string
|
|
GetVersion() string
|
|
MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, mediaInfos []*ffprobe.ProbeData) bool
|
|
ShouldAutoAnalyzeNewTorrents() bool
|
|
ShouldCacheNetworkTestResults() bool
|
|
ShouldForceIPv6() bool
|
|
ShouldHideBrokenTorrents() bool
|
|
ShouldIgnoreRenames() bool
|
|
ShouldLogRequests() bool
|
|
ShouldServeFromRclone() bool
|
|
}
|
|
|
|
type ZurgConfig struct {
|
|
Version string `yaml:"zurg" json:"-"`
|
|
Token string `yaml:"token" json:"-"`
|
|
|
|
APIRateLimitPerSecond int `yaml:"api_rate_limit_per_second" json:"api_rate_limit_per_second"`
|
|
ApiTimeoutSecs int `yaml:"api_timeout_secs" json:"api_timeout_secs"`
|
|
AutoAnalyzeNewTorrents bool `yaml:"auto_analyze_new_torrents" json:"auto_analyze_new_torrents"`
|
|
CacheNetworkTestResults bool `yaml:"cache_network_test_results" json:"cache_network_test_results"`
|
|
CanRepair bool `yaml:"enable_repair" json:"enable_repair"`
|
|
DownloadsEveryMins int `yaml:"downloads_every_mins" json:"downloads_every_mins"`
|
|
DownloadTimeoutSecs int `yaml:"download_timeout_secs" json:"download_timeout_secs"`
|
|
DownloadTokens []string `yaml:"download_tokens" json:"download_tokens"`
|
|
DumpTorrentsEveryMins int `yaml:"dump_torrents_every_mins" json:"dump_torrents_every_mins"`
|
|
ForceIPv6 bool `yaml:"force_ipv6" json:"force_ipv6"`
|
|
HideBrokenTorrents bool `yaml:"hide_broken_torrents" json:"hide_broken_torrents"`
|
|
Host string `yaml:"host" json:"host"`
|
|
IgnoreRenames bool `yaml:"ignore_renames" json:"ignore_renames"`
|
|
LogRequests bool `yaml:"log_requests" json:"log_requests"`
|
|
NumberOfHosts int `yaml:"number_of_hosts" json:"number_of_hosts"`
|
|
NumOfWorkers int `yaml:"concurrent_workers" json:"concurrent_workers"`
|
|
OnLibraryUpdate string `yaml:"on_library_update" json:"on_library_update"`
|
|
Password string `yaml:"password" json:"password"`
|
|
PlayableExtensions []string `yaml:"addl_playable_extensions" json:"addl_playable_extensions"`
|
|
Port string `yaml:"port" json:"port"`
|
|
Proxy string `yaml:"proxy" json:"proxy"`
|
|
RarAction string `yaml:"rar_action" json:"rar_action"`
|
|
RefreshEverySecs int `yaml:"check_for_changes_every_secs" json:"check_for_changes_every_secs"`
|
|
RepairEveryMins int `yaml:"repair_every_mins" json:"repair_every_mins"`
|
|
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension" json:"retain_folder_name_extension"`
|
|
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name" json:"retain_rd_torrent_name"`
|
|
RetriesUntilFailed int `yaml:"retries_until_failed" json:"retries_until_failed"`
|
|
ServeFromRclone bool `yaml:"serve_from_rclone" json:"serve_from_rclone"`
|
|
TorrentsRateLimitPerSecond int `yaml:"torrents_rate_limit_per_second" json:"torrents_rate_limit_per_second"`
|
|
Username string `yaml:"username" json:"username"`
|
|
}
|
|
|
|
func (z *ZurgConfig) GetConfig() ZurgConfig {
|
|
return *z
|
|
}
|
|
|
|
func (z *ZurgConfig) GetToken() string {
|
|
return z.Token
|
|
}
|
|
|
|
func (z *ZurgConfig) GetHost() string {
|
|
if z.Host == "" {
|
|
return "[::]"
|
|
}
|
|
return z.Host
|
|
}
|
|
|
|
func (z *ZurgConfig) GetPort() string {
|
|
if os.Getenv("PORT") != "" {
|
|
return os.Getenv("PORT")
|
|
}
|
|
if z.Port == "" {
|
|
return "9999"
|
|
}
|
|
return z.Port
|
|
}
|
|
|
|
func (z *ZurgConfig) GetUsername() string {
|
|
return z.Username
|
|
}
|
|
|
|
func (z *ZurgConfig) GetPassword() string {
|
|
return z.Password
|
|
}
|
|
|
|
func (z *ZurgConfig) GetNumberOfWorkers() int {
|
|
if z.NumOfWorkers == 0 {
|
|
return 20
|
|
}
|
|
return z.NumOfWorkers
|
|
}
|
|
|
|
func (z *ZurgConfig) GetRefreshEverySecs() int {
|
|
if z.RefreshEverySecs == 0 {
|
|
return 15
|
|
}
|
|
return z.RefreshEverySecs
|
|
}
|
|
|
|
func (z *ZurgConfig) GetRepairEveryMins() int {
|
|
if z.RepairEveryMins == 0 {
|
|
return 60 // 1 hour
|
|
}
|
|
return z.RepairEveryMins
|
|
}
|
|
|
|
func (z *ZurgConfig) GetDownloadsEveryMins() int {
|
|
if z.DownloadsEveryMins == 0 {
|
|
return 720 // 12 hours
|
|
}
|
|
return z.DownloadsEveryMins
|
|
}
|
|
|
|
func (z *ZurgConfig) GetDumpTorrentsEveryMins() int {
|
|
if z.DumpTorrentsEveryMins == 0 {
|
|
return 1440 // 1 day
|
|
}
|
|
return z.DumpTorrentsEveryMins
|
|
}
|
|
|
|
func (z *ZurgConfig) EnableRepair() bool {
|
|
return z.CanRepair
|
|
}
|
|
|
|
func (z *ZurgConfig) GetOnLibraryUpdate() string {
|
|
return z.OnLibraryUpdate
|
|
}
|
|
|
|
func (z *ZurgConfig) EnableRetainFolderNameExtension() bool {
|
|
return z.RetainFolderNameExtension
|
|
}
|
|
|
|
func (z *ZurgConfig) EnableRetainRDTorrentName() bool {
|
|
return z.RetainRDTorrentName
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldIgnoreRenames() bool {
|
|
return !z.IgnoreRenames
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldServeFromRclone() bool {
|
|
return z.ServeFromRclone
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldForceIPv6() bool {
|
|
return z.ForceIPv6
|
|
}
|
|
|
|
func (z *ZurgConfig) GetRetriesUntilFailed() int {
|
|
if z.RetriesUntilFailed == 0 {
|
|
return 2
|
|
}
|
|
return z.RetriesUntilFailed
|
|
}
|
|
|
|
func (z *ZurgConfig) GetApiTimeoutSecs() int {
|
|
if z.ApiTimeoutSecs == 0 {
|
|
return 60
|
|
}
|
|
return z.ApiTimeoutSecs
|
|
}
|
|
|
|
func (z *ZurgConfig) GetDownloadTimeoutSecs() int {
|
|
if z.DownloadTimeoutSecs == 0 {
|
|
return 10
|
|
}
|
|
return z.DownloadTimeoutSecs
|
|
}
|
|
|
|
// GetRarAction returns the action to take when a rar'ed torrent is found
|
|
// none: do nothing (mark as unrepairable)
|
|
// extract: extract the rar'ed torrent
|
|
// delete: delete the rar'ed torrent
|
|
func (z *ZurgConfig) GetRarAction() string {
|
|
if z.RarAction == "" {
|
|
return "none"
|
|
}
|
|
return z.RarAction
|
|
}
|
|
|
|
func (z *ZurgConfig) GetPlayableExtensions() []string {
|
|
if len(z.PlayableExtensions) == 0 {
|
|
return []string{}
|
|
}
|
|
return z.PlayableExtensions
|
|
}
|
|
|
|
func (z *ZurgConfig) GetProxy() string {
|
|
return z.Proxy
|
|
}
|
|
|
|
func (z *ZurgConfig) GetNumberOfHosts() int {
|
|
return z.NumberOfHosts
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldAutoAnalyzeNewTorrents() bool {
|
|
return z.AutoAnalyzeNewTorrents
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldCacheNetworkTestResults() bool {
|
|
return z.CacheNetworkTestResults
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldLogRequests() bool {
|
|
return z.LogRequests
|
|
}
|
|
|
|
func (z *ZurgConfig) GetDownloadTokens() []string {
|
|
return z.DownloadTokens
|
|
}
|
|
|
|
func (z *ZurgConfig) ShouldHideBrokenTorrents() bool {
|
|
return z.HideBrokenTorrents
|
|
}
|
|
|
|
func (z *ZurgConfig) GetAPIRateLimitPerSecond() int {
|
|
if z.APIRateLimitPerSecond == 0 {
|
|
return 250
|
|
}
|
|
return z.APIRateLimitPerSecond
|
|
}
|
|
|
|
func (z *ZurgConfig) GetTorrentsRateLimitPerSecond() int {
|
|
if z.TorrentsRateLimitPerSecond == 0 {
|
|
return 1
|
|
}
|
|
return z.TorrentsRateLimitPerSecond
|
|
}
|