-
Notifications
You must be signed in to change notification settings - Fork 0
/
transmission-showrss.go
82 lines (67 loc) · 1.99 KB
/
transmission-showrss.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
"github.com/pborzenkov/go-transmission/transmission"
"github.com/peterbourgon/ff/v3"
"github.com/some-programs/transmission-showrss/pkg/cmdline"
"github.com/some-programs/transmission-showrss/pkg/log"
"github.com/some-programs/transmission-showrss/pkg/showrss"
"golang.org/x/sync/errgroup"
)
func main() {
fs := flag.NewFlagSet("transmission-showrss", flag.ContinueOnError)
var (
transmissionConfig = cmdline.TransmissionConfigFlags(fs)
feedSelection = cmdline.FeedSelectionFlags(fs)
showDirs = cmdline.ShowDirsFlags(fs)
databaseFile = fs.String("db.file", "showrss.db", "database file")
_ = fs.String("config", "", "config file (optional)")
)
var logConfig log.Config
logConfig.RegisterFlags(fs)
if err := ff.Parse(fs, os.Args[1:],
ff.WithEnvVarPrefix("TRANSMISSION_SHOWRSS"),
ff.WithConfigFileFlag("config"),
ff.WithConfigFileParser(ff.PlainParser),
); err != nil {
if !errors.Is(err, flag.ErrHelp) {
panic(err)
}
os.Exit(1)
}
logConfig.Setup()
log.Info().Interface("feed_selection", feedSelection).Msg("config")
if feedSelection.IsEmtpy() {
fmt.Println("Must choose at least one user or show")
os.Exit(1)
}
tc, err := transmission.New(
transmissionConfig.Address,
transmission.WithAuth(transmissionConfig.User, transmissionConfig.Password),
)
if err != nil {
log.Fatal().Err(err).Msg("error creating transmission client")
}
db, err := showrss.NewDB(*databaseFile)
if err != nil {
log.Fatal().Err(err).Msg("error connecting to database")
}
defer db.Close()
downloader := showrss.ShowRSSDownloader{
ShowDirs: *showDirs,
TC: tc,
DB: db,
Selection: *feedSelection,
}
ctx := context.Background()
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error { return downloader.Start(ctx) })
// eg.Go(func() error { return showrss.APIServer(db, tc, ":8384") })
if err := eg.Wait(); err != nil {
log.Fatal().Err(err).Msg("exiting")
}
}