feat: respect pvr exclusions (#37)
This commit is contained in:
5
cache/cache.go
vendored
5
cache/cache.go
vendored
@@ -6,9 +6,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/lefelys/state"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -26,7 +27,7 @@ func New(path string) (*Client, error) {
|
||||
return nil, fmt.Errorf("open: %w", err)
|
||||
}
|
||||
|
||||
log := logger.New("").With().Logger()
|
||||
log := logger.Child()
|
||||
|
||||
// start cleaner
|
||||
st, tail := state.WithShutdown()
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -11,16 +10,15 @@ import (
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/lefelys/state"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/build"
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/rss"
|
||||
"github.com/lefelys/state"
|
||||
"github.com/natefinch/lumberjack"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -84,28 +82,11 @@ func main() {
|
||||
}
|
||||
|
||||
// logger
|
||||
logger := log.Output(io.MultiWriter(zerolog.ConsoleWriter{
|
||||
TimeFormat: time.Stamp,
|
||||
Out: os.Stderr,
|
||||
}, zerolog.ConsoleWriter{
|
||||
TimeFormat: time.Stamp,
|
||||
Out: &lumberjack.Logger{
|
||||
Filename: cli.Log,
|
||||
MaxSize: 5,
|
||||
MaxAge: 14,
|
||||
MaxBackups: 5,
|
||||
},
|
||||
NoColor: true,
|
||||
}))
|
||||
|
||||
switch {
|
||||
case cli.Verbosity == 1:
|
||||
log.Logger = logger.Level(zerolog.DebugLevel)
|
||||
case cli.Verbosity > 1:
|
||||
log.Logger = logger.Level(zerolog.TraceLevel)
|
||||
default:
|
||||
log.Logger = logger.Level(zerolog.InfoLevel)
|
||||
}
|
||||
log := logger.Init(
|
||||
logger.WithConsole(),
|
||||
logger.WithFile(cli.Log),
|
||||
logger.WithVerbosity(cli.Verbosity),
|
||||
)
|
||||
|
||||
// config
|
||||
log.Trace().Msg("Initialising config")
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/lefelys/state"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/radarr"
|
||||
"github.com/l3uddz/nabarr/sonarr"
|
||||
"github.com/lefelys/state"
|
||||
)
|
||||
|
||||
type PVR interface {
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/blang/semver"
|
||||
"github.com/l3uddz/nabarr/build"
|
||||
"github.com/rhysd/go-github-selfupdate/selfupdate"
|
||||
|
||||
"github.com/l3uddz/nabarr/build"
|
||||
)
|
||||
|
||||
type updateFlag string
|
||||
|
||||
12
go.mod
12
go.mod
@@ -16,7 +16,7 @@ require (
|
||||
github.com/google/flatbuffers v2.0.6+incompatible // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-retryablehttp v0.7.0
|
||||
github.com/hashicorp/go-retryablehttp v0.7.1
|
||||
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
|
||||
github.com/klauspost/compress v1.15.1 // indirect
|
||||
github.com/lefelys/state v1.1.0
|
||||
@@ -30,10 +30,10 @@ require (
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
go.uber.org/ratelimit v0.2.0
|
||||
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
|
||||
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
|
||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
|
||||
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
@@ -51,5 +51,5 @@ require (
|
||||
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
|
||||
)
|
||||
|
||||
23
go.sum
23
go.sum
@@ -176,8 +176,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
|
||||
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
|
||||
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
@@ -292,8 +292,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
|
||||
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@@ -357,16 +357,16 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd h1:zYlwaUHTmxuf6H7hwO2dgwqozQmH7zf4x+/qql4oVWc=
|
||||
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
|
||||
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM=
|
||||
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 h1:OSnWWcOd/CtWQC2cYSBgbTSJv3ciqd8r54ySIW2y3RE=
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -416,8 +416,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
|
||||
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -479,8 +479,9 @@ golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U=
|
||||
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
|
||||
@@ -1,19 +1,55 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func New(verbosity string) zerolog.Logger {
|
||||
if verbosity == "" {
|
||||
type logger struct {
|
||||
log zerolog.Logger
|
||||
writers []io.Writer
|
||||
verbosity int
|
||||
}
|
||||
|
||||
func Init(opts ...InitOption) zerolog.Logger {
|
||||
// prepare logger
|
||||
l := &logger{
|
||||
writers: make([]io.Writer, 0),
|
||||
verbosity: 0,
|
||||
}
|
||||
|
||||
// loop options
|
||||
for _, opt := range opts {
|
||||
opt(l)
|
||||
}
|
||||
|
||||
// set logger
|
||||
l.log = log.Output(io.MultiWriter(l.writers...))
|
||||
|
||||
// set global logger
|
||||
switch {
|
||||
case l.verbosity == 1:
|
||||
log.Logger = l.log.Level(zerolog.DebugLevel)
|
||||
case l.verbosity > 1:
|
||||
log.Logger = l.log.Level(zerolog.TraceLevel)
|
||||
default:
|
||||
log.Logger = l.log.Level(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
return log.Logger
|
||||
}
|
||||
|
||||
level, err := zerolog.ParseLevel(verbosity)
|
||||
if err != nil {
|
||||
return log.Logger
|
||||
func Child(opts ...ChildOption) zerolog.Logger {
|
||||
// default
|
||||
l := log.With().
|
||||
Logger()
|
||||
|
||||
// loop options
|
||||
for _, opt := range opts {
|
||||
opt(&l)
|
||||
}
|
||||
|
||||
return log.Level(level)
|
||||
return l
|
||||
}
|
||||
|
||||
70
logger/options.go
Normal file
70
logger/options.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
/* core logger options */
|
||||
|
||||
type InitOption func(*logger)
|
||||
|
||||
func WithConsole() InitOption {
|
||||
return func(l *logger) {
|
||||
l.writers = append(l.writers, zerolog.ConsoleWriter{
|
||||
TimeFormat: time.Stamp,
|
||||
Out: os.Stderr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func WithFile(filepath string) InitOption {
|
||||
return func(l *logger) {
|
||||
l.writers = append(l.writers, zerolog.ConsoleWriter{
|
||||
TimeFormat: time.Stamp,
|
||||
Out: &lumberjack.Logger{
|
||||
Filename: filepath,
|
||||
MaxSize: 5,
|
||||
MaxAge: 14,
|
||||
MaxBackups: 5,
|
||||
},
|
||||
NoColor: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func WithVerbosity(verbosity int) InitOption {
|
||||
return func(l *logger) {
|
||||
l.verbosity = verbosity
|
||||
}
|
||||
}
|
||||
|
||||
/* child logger options */
|
||||
|
||||
type ChildOption func(*zerolog.Logger)
|
||||
|
||||
func WithName(name string) ChildOption {
|
||||
return func(l *zerolog.Logger) {
|
||||
*l = l.With().
|
||||
Str("caller", name).
|
||||
Logger()
|
||||
}
|
||||
}
|
||||
|
||||
func WithLevel(level string) ChildOption {
|
||||
return func(l *zerolog.Logger) {
|
||||
if level == "" {
|
||||
return
|
||||
}
|
||||
|
||||
zl, err := zerolog.ParseLevel(level)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
*l = l.Level(zl)
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@ package media
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/media/omdb"
|
||||
"github.com/l3uddz/nabarr/media/trakt"
|
||||
"github.com/l3uddz/nabarr/media/tvdb"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -29,6 +30,6 @@ func New(cfg *Config) (*Client, error) {
|
||||
omdb: omdb.New(&cfg.Omdb),
|
||||
tvdb: tvdb.New(&cfg.Tvdb),
|
||||
|
||||
log: logger.New(cfg.Verbosity).With().Logger(),
|
||||
log: logger.Child(logger.WithLevel(cfg.Verbosity)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
"go.uber.org/ratelimit"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -19,9 +20,8 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(cfg *Config) *Client {
|
||||
l := logger.New(cfg.Verbosity).With().
|
||||
Str("media", "omdb").
|
||||
Logger()
|
||||
l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
|
||||
Str("media", "omdb").Logger()
|
||||
|
||||
return &Client{
|
||||
log: l,
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/l3uddz/nabarr/media/omdb"
|
||||
"github.com/l3uddz/nabarr/media/tvdb"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
/* Media Item(s) */
|
||||
|
||||
@@ -6,8 +6,9 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
"go.uber.org/ratelimit"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -19,9 +20,8 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(cfg *Config) *Client {
|
||||
l := logger.New(cfg.Verbosity).With().
|
||||
Str("media", "trakt").
|
||||
Logger()
|
||||
l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
|
||||
Str("media", "trakt").Logger()
|
||||
|
||||
return &Client{
|
||||
log: l,
|
||||
|
||||
@@ -5,8 +5,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
"go.uber.org/ratelimit"
|
||||
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -21,9 +22,8 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(cfg *Config) *Client {
|
||||
l := logger.New(cfg.Verbosity).With().
|
||||
Str("media", "tvdb").
|
||||
Logger()
|
||||
l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
|
||||
Str("media", "tvdb").Logger()
|
||||
|
||||
return &Client{
|
||||
log: l,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/antonmedv/expr/vm"
|
||||
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -118,6 +119,35 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
return nil, fmt.Errorf("movie lookup %sId: %v: %w", mdp, mdi, ErrItemNotFound)
|
||||
}
|
||||
|
||||
func (c *Client) getExclusions() (map[int]exclusion, error) {
|
||||
// send request
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "exclusions"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request exclusions: %w", err)
|
||||
}
|
||||
defer resp.Body().Close()
|
||||
|
||||
// validate response
|
||||
if resp.StatusCode() != 200 {
|
||||
return nil, fmt.Errorf("validate exclusions response: %s", resp.Status())
|
||||
}
|
||||
|
||||
// decode response
|
||||
b := new([]exclusion)
|
||||
if err := json.NewDecoder(resp.Body()).Decode(b); err != nil {
|
||||
return nil, fmt.Errorf("decode exclusions response: %w", err)
|
||||
}
|
||||
|
||||
// generate exclusion map
|
||||
exclusions := make(map[int]exclusion)
|
||||
for n := range *b {
|
||||
e := (*b)[n]
|
||||
exclusions[e.TmdbId] = e
|
||||
}
|
||||
|
||||
return exclusions, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
|
||||
// prepare options
|
||||
o, err := nabarr.BuildPvrOptions(opts...)
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/antonmedv/expr"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) compileExpressions(filters nabarr.PvrFilters) error {
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/lefelys/state"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/lefelys/state"
|
||||
)
|
||||
|
||||
func (c *Client) QueueFeedItem(item *media.FeedItem) {
|
||||
@@ -171,6 +172,27 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
continue
|
||||
}
|
||||
|
||||
// lookup pvr exclusions
|
||||
exclusions, err := c.getExclusions()
|
||||
if err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed retrieving pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := exclusions[s.TmdbId]; ok {
|
||||
// item was in pvr exclusions
|
||||
c.log.Debug().
|
||||
Str("pvr_title", s.Title).
|
||||
Int("pvr_year", s.Year).
|
||||
Str("pvr_imdb_id", s.ImdbId).
|
||||
Int("pvr_tmdb_id", s.TmdbId).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item found in pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
// add item to pvr
|
||||
c.log.Debug().
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -43,7 +44,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*Client, error) {
|
||||
l := logger.New(c.Verbosity).With().
|
||||
l := logger.Child(logger.WithLevel(c.Verbosity)).With().
|
||||
Str("pvr_name", c.Name).
|
||||
Str("pvr_type", c.Type).
|
||||
Logger()
|
||||
|
||||
@@ -9,6 +9,13 @@ type qualityProfile struct {
|
||||
Id int
|
||||
}
|
||||
|
||||
type exclusion struct {
|
||||
TmdbId int `json:"tmdbId"`
|
||||
MovieTitle string `json:"movieTitle"`
|
||||
MovieYear int `json:"movieYear"`
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
type lookupRequest struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Title string `json:"title"`
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
func (c *Client) AddJob(feed feedItem) error {
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
)
|
||||
|
||||
func (j *rssJob) process() error {
|
||||
|
||||
@@ -3,12 +3,13 @@ package rss
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/lefelys/state"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -27,7 +28,7 @@ func New(c Config, cc *cache.Client, pvrs map[string]pvr.PVR) *Client {
|
||||
cache: cc,
|
||||
pvrs: pvrs,
|
||||
|
||||
log: logger.New(c.Verbosity).With().Logger(),
|
||||
log: logger.Child(logger.WithLevel(c.Verbosity)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
|
||||
)
|
||||
|
||||
type feedItem struct {
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -140,6 +141,35 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
return nil, fmt.Errorf("series lookup %sId: %v: %w", mdp, mdi, ErrItemNotFound)
|
||||
}
|
||||
|
||||
func (c *Client) getExclusions() (map[int]exclusion, error) {
|
||||
// send request
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "importlistexclusion"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request exclusions: %w", err)
|
||||
}
|
||||
defer resp.Body().Close()
|
||||
|
||||
// validate response
|
||||
if resp.StatusCode() != 200 {
|
||||
return nil, fmt.Errorf("validate exclusions response: %s", resp.Status())
|
||||
}
|
||||
|
||||
// decode response
|
||||
b := new([]exclusion)
|
||||
if err := json.NewDecoder(resp.Body()).Decode(b); err != nil {
|
||||
return nil, fmt.Errorf("decode exclusions response: %w", err)
|
||||
}
|
||||
|
||||
// generate exclusion map
|
||||
exclusions := make(map[int]exclusion)
|
||||
for n := range *b {
|
||||
e := (*b)[n]
|
||||
exclusions[e.TvdbId] = e
|
||||
}
|
||||
|
||||
return exclusions, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
|
||||
// prepare options
|
||||
o, err := nabarr.BuildPvrOptions(opts...)
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/antonmedv/expr"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) compileExpressions(filters nabarr.PvrFilters) error {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lefelys/state"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lefelys/state"
|
||||
)
|
||||
|
||||
func (c *Client) QueueFeedItem(item *media.FeedItem) {
|
||||
@@ -162,6 +163,26 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
continue
|
||||
}
|
||||
|
||||
// lookup pvr exclusions
|
||||
exclusions, err := c.getExclusions()
|
||||
if err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed retrieving pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := exclusions[s.TvdbId]; ok {
|
||||
// item was in pvr exclusions
|
||||
c.log.Debug().
|
||||
Str("pvr_title", s.Title).
|
||||
Int("pvr_year", s.Year).
|
||||
Int("pvr_tvdb_id", s.TvdbId).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item found in pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
// set appropriate series type
|
||||
switch {
|
||||
case util.StringSliceContains(mediaItem.Genres, "anime"), util.StringSliceContains(mediaItem.Tvdb.Genre, "anime"):
|
||||
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -45,7 +46,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*Client, error) {
|
||||
l := logger.New(c.Verbosity).With().
|
||||
l := logger.Child(logger.WithLevel(c.Verbosity)).With().
|
||||
Str("pvr_name", c.Name).
|
||||
Str("pvr_type", c.Type).
|
||||
Logger()
|
||||
|
||||
@@ -9,6 +9,12 @@ type qualityProfile struct {
|
||||
Id int
|
||||
}
|
||||
|
||||
type exclusion struct {
|
||||
TvdbId int `json:"tvdbId"`
|
||||
Title string `json:"title"`
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
type languageProfile struct {
|
||||
Name string
|
||||
Id int
|
||||
|
||||
@@ -5,9 +5,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
"github.com/l3uddz/nabarr/build"
|
||||
"github.com/rs/zerolog"
|
||||
"go.uber.org/ratelimit"
|
||||
|
||||
"github.com/l3uddz/nabarr/build"
|
||||
)
|
||||
|
||||
func NewRetryableHttpClient(timeout time.Duration, rl ratelimit.Limiter, log *zerolog.Logger) *http.Client {
|
||||
|
||||
Reference in New Issue
Block a user