up
This commit is contained in:
56
main.go
Normal file
56
main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func defaultConfigPath() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
home = "."
|
||||
}
|
||||
return filepath.Join(home, ".config", "qbhardlink", "config.yaml")
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Ldate | log.Ltime)
|
||||
|
||||
var (
|
||||
name = flag.String("name", "", "Torrent name (%N)")
|
||||
category = flag.String("category", "", "Torrent category (%L) [required]")
|
||||
contentPath = flag.String("content-path", "", "Content path (%F) [required]")
|
||||
configPath = flag.String("config", defaultConfigPath(), "Path to config YAML file")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
if *category == "" || *contentPath == "" {
|
||||
fmt.Fprintln(os.Stderr, "Usage: qbhardlink --category <cat> --content-path <path> [--name <name>] [--config <path>]")
|
||||
fmt.Fprintln(os.Stderr, "")
|
||||
fmt.Fprintln(os.Stderr, "qBittorrent run-on-finish example:")
|
||||
os.Stderr.WriteString(" /usr/local/bin/qbhardlink --name \"%N\" --category \"%L\" --content-path \"%F\"\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg, err := loadConfig(*configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
|
||||
destSubdir, ok := cfg.Categories[*category]
|
||||
if !ok {
|
||||
log.Printf("category %q not in config, nothing to do (torrent: %s)", *category, *name)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
log.Printf("processing torrent %q (category: %s -> %s)", *name, *category, destSubdir)
|
||||
|
||||
if err := processHardlinks(cfg, *contentPath, destSubdir); err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("done")
|
||||
}
|
||||
Reference in New Issue
Block a user