Support YAML for the configuration and rearrange the config struct
This commit is contained in:
parent
fb15dcf3d5
commit
95ce7fccee
3 changed files with 69 additions and 66 deletions
81
README.md
81
README.md
|
@ -10,61 +10,58 @@ Uploads .torrent files from a local "blackhole" to a remote (SSH) rtorrent watch
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
## Example
|
## Example
|
||||||
Ignore the keys that start with an underscore, they are comments.
|
```yaml
|
||||||
```json
|
# The file mode to use for downloaded files and directories
|
||||||
{
|
file_download_filemode: 0777
|
||||||
"_rtorrent_addr": "The address to the rtorrent XMLRPC endpoint",
|
|
||||||
"rtorrent_addr": "mycoolrtorrentserver.com/XMLRPC",
|
|
||||||
|
|
||||||
"_rtorrent_insecure_cert": "true to ignore the certificate authenticity; false to honor it",
|
# The correlation of .torrent file paths and where their contents should be downloaded to"
|
||||||
"rtorrent_insecure_cert": false,
|
watch_to_download_paths:
|
||||||
|
/home/tblyler/torrent_files/tv: /home/tblyler/Downloads/tv
|
||||||
|
/home/tblyler/torrent_files/movies: /home/tblyler/Downloads/movies
|
||||||
|
/home/tblyler/torrent_files: /home/tblyler/Downloads
|
||||||
|
|
||||||
"_torrent_username": "The HTTP Basic auth username to use for rtorrent's XMLRPC",
|
# The root path to temporarily download to and then move to the folder in the setting above. The destination path is created underneath the temp_download_path
|
||||||
"rtorrent_username": "JohnDoe",
|
temp_download_path: /home/tblyler/tempDownloads
|
||||||
|
|
||||||
"_rtorrent_password": "The HTTP Basic auth password to use for rtorrent's XMLRPC",
|
# If defined, the finished .torrent files finished are moved to their respected path here. Otherwise, they are deleted.
|
||||||
"rtorrent_password": "correct horse battery staple",
|
watch_to_finish_path:
|
||||||
|
/home/tblyler/torrent_files/tv: /home/tblyler/completed_torrent_files/tv
|
||||||
|
/home/tblyler/torrent_files: /home/tblyler/completed_torrent_files
|
||||||
|
|
||||||
"_ssh_username": "The ssh username to use for getting finished torrents from the remote host",
|
# The time in nano seconds to update the list of torrents and their statuses in rTorrent
|
||||||
"ssh_username": "JohnDoe",
|
rtorrent_update_interval: 60000000000
|
||||||
|
|
||||||
"_SSH_AUTH_COMMENT": "You may choose to use an ssh key or ssh password. If both are supplied, the password will not be used.",
|
# The number of concurrent completed torrent downloads to have at one time
|
||||||
|
download_jobs: 2
|
||||||
|
|
||||||
"_ssh_password": "The SSH password to use for SSH authentication",
|
rtorrent:
|
||||||
"ssh_password": "correct horse battery staple SSH",
|
# The address to the rtorrent XMLRPC endpoint
|
||||||
|
addr: mycoolrtorrentserver.com/XMLRPC
|
||||||
|
|
||||||
"_ssh_privkey_path": "The path to the private SSH key for SSH authentication",
|
# true to ignore the certificate authenticity; false to honor it
|
||||||
"ssh_privkey_path": "/home/tblyler/.ssh/id_rsa",
|
insecure_cert: false
|
||||||
|
|
||||||
"_ssh_addr": "The SSH address to connect to",
|
# The HTTP Basic auth username to use for rtorrent's XMLRPC
|
||||||
"ssh_addr": "mysshserver.com:22",
|
username: JohnDoe
|
||||||
|
|
||||||
"_ssh_connect_timeout": "The time in nano seconds to wait for an SSH connection attempt",
|
# The HTTP Basic auth password to use for rtorrent's XMLRPC
|
||||||
"ssh_connect_timeout": 30000000000,
|
password: "correct horse battery staple"
|
||||||
|
|
||||||
"_file_download_filemode": "The base 10 file mode to use for downloaded files",
|
ssh:
|
||||||
"file_download_filemode": 511,
|
# The ssh username to use for getting finished torrents from the remote host
|
||||||
|
username: JohnDoe
|
||||||
|
|
||||||
"_watch_to_download_paths": "The correlation of .torrent file paths and where their contents should be downloaded to",
|
# You may choose to use an ssh key or ssh password. If both are supplied, the password will not be used.
|
||||||
"watch_to_download_paths": {
|
|
||||||
"/home/tblyler/torrent_files/tv": "/home/tblyler/Downloads/tv",
|
|
||||||
"/home/tblyler/torrent_files/movies": "/home/tblyler/Downloads/movies",
|
|
||||||
"/home/tblyler/torrent_files": "/home/tblyler/Downloads"
|
|
||||||
},
|
|
||||||
|
|
||||||
"_temp_download_path": "The root path to temporarily download to and then move to the folder in the setting above. The destination path is created underneath the temp_download_path",
|
# The SSH password to use for SSH authentication
|
||||||
"temp_download_path": "/home/tblyler/tempDownloads",
|
password: "correct horse battery staple SSH"
|
||||||
|
|
||||||
"_watch_to_finish_path": "If defined, the finished .torrent files finished are moved to their respected path here. Otherwise, they are deleted.",
|
# The path to the private SSH key for SSH authentication
|
||||||
"watch_to_finish_path": {
|
privkey_path: /home/tblyler/.ssh/id_rsa
|
||||||
"/home/tblyler/torrent_files/tv": "/home/tblyler/completed_torrent_files/tv",
|
|
||||||
"/home/tblyler/torrent_files": "/home/tblyler/completed_torrent_files"
|
|
||||||
},
|
|
||||||
|
|
||||||
"_rtorrent_update_interval": "The time in nano seconds to update the list of torrents and their statuses in rTorrent",
|
# The SSH address to connect to
|
||||||
"rtorrent_update_interval": 300000000000,
|
addr: "mysshserver.com:22"
|
||||||
|
|
||||||
"_download_jobs": "The number of concurrent download streams to have at one time",
|
# The time in nano seconds to wait for an SSH connection attempt
|
||||||
"download_jobs": 2
|
connect_timeout: 30000000000
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/tblyler/hoarder/queue"
|
"github.com/tblyler/hoarder/queue"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -28,7 +28,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &queue.Config{}
|
config := &queue.Config{}
|
||||||
err = json.Unmarshal(configRaw, config)
|
err = yaml.Unmarshal(configRaw, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Printf("Unable to decode config json at '%s': '%s'", *configPath, err)
|
logger.Printf("Unable to decode config json at '%s': '%s'", *configPath, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -19,21 +19,27 @@ import (
|
||||||
|
|
||||||
// Config defines the settings for watching, uploading, and downloading
|
// Config defines the settings for watching, uploading, and downloading
|
||||||
type Config struct {
|
type Config struct {
|
||||||
RtorrentAddr string `json:"rtorrent_addr"`
|
Rtorrent struct {
|
||||||
RtorrentInsecureCert bool `json:"rtorrent_insecure_cert"`
|
Addr string `json:"addr" yaml:"addr"`
|
||||||
RtorrentUsername string `json:"rtorrent_username"`
|
InsecureCert bool `json:"insecure_cert" yaml:"insecure_cert"`
|
||||||
RtorrentPassword string `json:"rtorrent_password"`
|
Username string `json:"username" yaml:"username"`
|
||||||
SSHUsername string `json:"ssh_username"`
|
Password string `json:"password" yaml:"password"`
|
||||||
SSHPassword string `json:"ssh_password"`
|
} `json:"rtorrent" yaml:"rtorrent,flow"`
|
||||||
SSHKeyPath string `json:"ssh_privkey_path"`
|
|
||||||
SSHAddr string `json:"ssh_addr"`
|
SSH struct {
|
||||||
SSHTimeout time.Duration `json:"ssh_connect_timeout"`
|
Username string `json:"username" yaml:"username"`
|
||||||
DownloadFileMode os.FileMode `json:"file_download_filemode"`
|
Password string `json:"password" yaml:"password"`
|
||||||
WatchDownloadPaths map[string]string `json:"watch_to_download_paths"`
|
KeyPath string `json:"privkey_path" yaml:"privkey_path"`
|
||||||
TempDownloadPath string `json:"temp_download_path"`
|
Addr string `json:"addr" yaml:"addr"`
|
||||||
FinishedTorrentFilePath map[string]string `json:"watch_to_finish_path"`
|
Timeout time.Duration `json:"connect_timeout" yaml:"connect_timeout"`
|
||||||
TorrentListUpdateInterval time.Duration `json:"rtorrent_update_interval"`
|
} `json:"ssh" yaml:"ssh,flow"`
|
||||||
ConcurrentDownloads uint `json:"download_jobs"`
|
|
||||||
|
DownloadFileMode os.FileMode `json:"file_download_filemode" yaml:"file_download_filemode"`
|
||||||
|
WatchDownloadPaths map[string]string `json:"watch_to_download_paths" yaml:"watch_to_download_paths,flow"`
|
||||||
|
TempDownloadPath string `json:"temp_download_path" yaml:"temp_download_path"`
|
||||||
|
FinishedTorrentFilePath map[string]string `json:"watch_to_finish_path" yaml:"watch_to_finish_path,flow"`
|
||||||
|
TorrentListUpdateInterval time.Duration `json:"rtorrent_update_interval" yaml:"rtorrent_update_interval"`
|
||||||
|
ConcurrentDownloads uint `json:"download_jobs" yaml:"download_jobs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue watches the given folders for new .torrent files,
|
// Queue watches the given folders for new .torrent files,
|
||||||
|
@ -116,15 +122,15 @@ func NewQueue(config *Config, logger *log.Logger) (*Queue, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rtClient := rtorrent.New(config.RtorrentAddr, config.RtorrentInsecureCert)
|
rtClient := rtorrent.New(config.Rtorrent.Addr, config.Rtorrent.InsecureCert)
|
||||||
rtClient.SetAuth(config.RtorrentUsername, config.RtorrentPassword)
|
rtClient.SetAuth(config.Rtorrent.Username, config.Rtorrent.Password)
|
||||||
|
|
||||||
sftpClient, err := easysftp.Connect(&easysftp.ClientConfig{
|
sftpClient, err := easysftp.Connect(&easysftp.ClientConfig{
|
||||||
Username: config.SSHUsername,
|
Username: config.SSH.Username,
|
||||||
Password: config.SSHPassword,
|
Password: config.SSH.Password,
|
||||||
KeyPath: config.SSHKeyPath,
|
KeyPath: config.SSH.KeyPath,
|
||||||
Host: config.SSHAddr,
|
Host: config.SSH.Addr,
|
||||||
Timeout: config.SSHTimeout,
|
Timeout: config.SSH.Timeout,
|
||||||
FileMode: config.DownloadFileMode,
|
FileMode: config.DownloadFileMode,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue