feat: respect pvr exclusions (#37)

This commit is contained in:
l3uddz
2022-04-14 16:18:06 +01:00
committed by GitHub
parent 2468d5b251
commit 79507adb4a
32 changed files with 321 additions and 99 deletions

5
cache/cache.go vendored
View File

@@ -6,9 +6,10 @@ import (
"time" "time"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
"github.com/l3uddz/nabarr/logger"
"github.com/lefelys/state" "github.com/lefelys/state"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/l3uddz/nabarr/logger"
) )
type Client struct { type Client struct {
@@ -26,7 +27,7 @@ func New(path string) (*Client, error) {
return nil, fmt.Errorf("open: %w", err) return nil, fmt.Errorf("open: %w", err)
} }
log := logger.New("").With().Logger() log := logger.Child()
// start cleaner // start cleaner
st, tail := state.WithShutdown() st, tail := state.WithShutdown()

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -11,16 +10,15 @@ import (
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
"github.com/goccy/go-yaml" "github.com/goccy/go-yaml"
"github.com/lefelys/state"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/build" "github.com/l3uddz/nabarr/build"
"github.com/l3uddz/nabarr/cache" "github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr" "github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/rss" "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 { type config struct {
@@ -84,28 +82,11 @@ func main() {
} }
// logger // logger
logger := log.Output(io.MultiWriter(zerolog.ConsoleWriter{ log := logger.Init(
TimeFormat: time.Stamp, logger.WithConsole(),
Out: os.Stderr, logger.WithFile(cli.Log),
}, zerolog.ConsoleWriter{ logger.WithVerbosity(cli.Verbosity),
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)
}
// config // config
log.Trace().Msg("Initialising config") log.Trace().Msg("Initialising config")

View File

@@ -4,12 +4,13 @@ import (
"errors" "errors"
"strings" "strings"
"github.com/lefelys/state"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/cache" "github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/radarr" "github.com/l3uddz/nabarr/radarr"
"github.com/l3uddz/nabarr/sonarr" "github.com/l3uddz/nabarr/sonarr"
"github.com/lefelys/state"
) )
type PVR interface { type PVR interface {

View File

@@ -7,8 +7,9 @@ import (
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
"github.com/blang/semver" "github.com/blang/semver"
"github.com/l3uddz/nabarr/build"
"github.com/rhysd/go-github-selfupdate/selfupdate" "github.com/rhysd/go-github-selfupdate/selfupdate"
"github.com/l3uddz/nabarr/build"
) )
type updateFlag string type updateFlag string

12
go.mod
View File

@@ -16,7 +16,7 @@ require (
github.com/google/flatbuffers v2.0.6+incompatible // indirect github.com/google/flatbuffers v2.0.6+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // 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/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
github.com/klauspost/compress v1.15.1 // indirect github.com/klauspost/compress v1.15.1 // indirect
github.com/lefelys/state v1.1.0 github.com/lefelys/state v1.1.0
@@ -30,10 +30,10 @@ require (
github.com/ulikunitz/xz v0.5.10 // indirect github.com/ulikunitz/xz v0.5.10 // indirect
go.opencensus.io v0.23.0 // indirect go.opencensus.io v0.23.0 // indirect
go.uber.org/ratelimit v0.2.0 go.uber.org/ratelimit v0.2.0
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.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/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-colorable v0.1.12 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // 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
View File

@@ -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-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 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= 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.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= 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.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/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= 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-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-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-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-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 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-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-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 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-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-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-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-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 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-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-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-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-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-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-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM= golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 h1:OSnWWcOd/CtWQC2cYSBgbTSJv3ciqd8r54ySIW2y3RE=
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= 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-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-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/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-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-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-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-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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-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-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 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-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-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-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-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.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.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=

View File

@@ -1,19 +1,55 @@
package logger package logger
import ( import (
"io"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func New(verbosity string) zerolog.Logger { type logger struct {
if verbosity == "" { 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 return log.Logger
} }
level, err := zerolog.ParseLevel(verbosity) func Child(opts ...ChildOption) zerolog.Logger {
if err != nil { // default
return log.Logger l := log.With().
Logger()
// loop options
for _, opt := range opts {
opt(&l)
} }
return log.Level(level) return l
} }

70
logger/options.go Normal file
View 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)
}
}

View File

@@ -3,11 +3,12 @@ package media
import ( import (
"fmt" "fmt"
"github.com/rs/zerolog"
"github.com/l3uddz/nabarr/logger" "github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/media/omdb" "github.com/l3uddz/nabarr/media/omdb"
"github.com/l3uddz/nabarr/media/trakt" "github.com/l3uddz/nabarr/media/trakt"
"github.com/l3uddz/nabarr/media/tvdb" "github.com/l3uddz/nabarr/media/tvdb"
"github.com/rs/zerolog"
) )
type Client struct { type Client struct {
@@ -29,6 +30,6 @@ func New(cfg *Config) (*Client, error) {
omdb: omdb.New(&cfg.Omdb), omdb: omdb.New(&cfg.Omdb),
tvdb: tvdb.New(&cfg.Tvdb), tvdb: tvdb.New(&cfg.Tvdb),
log: logger.New(cfg.Verbosity).With().Logger(), log: logger.Child(logger.WithLevel(cfg.Verbosity)),
}, nil }, nil
} }

View File

@@ -7,8 +7,9 @@ import (
"net/url" "net/url"
"strings" "strings"
"github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek" "github.com/lucperkins/rek"
"github.com/l3uddz/nabarr/util"
) )
var ( var (

View File

@@ -4,10 +4,11 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"go.uber.org/ratelimit" "go.uber.org/ratelimit"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
) )
type Client struct { type Client struct {
@@ -19,9 +20,8 @@ type Client struct {
} }
func New(cfg *Config) *Client { func New(cfg *Config) *Client {
l := logger.New(cfg.Verbosity).With(). l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
Str("media", "omdb"). Str("media", "omdb").Logger()
Logger()
return &Client{ return &Client{
log: l, log: l,

View File

@@ -5,10 +5,11 @@ import (
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
"github.com/l3uddz/nabarr/media/omdb" "github.com/l3uddz/nabarr/media/omdb"
"github.com/l3uddz/nabarr/media/tvdb" "github.com/l3uddz/nabarr/media/tvdb"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/pkg/errors"
) )
/* Media Item(s) */ /* Media Item(s) */

View File

@@ -6,8 +6,9 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek" "github.com/lucperkins/rek"
"github.com/l3uddz/nabarr/util"
) )
var ( var (

View File

@@ -4,10 +4,11 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"go.uber.org/ratelimit" "go.uber.org/ratelimit"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
) )
type Client struct { type Client struct {
@@ -19,9 +20,8 @@ type Client struct {
} }
func New(cfg *Config) *Client { func New(cfg *Config) *Client {
l := logger.New(cfg.Verbosity).With(). l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
Str("media", "trakt"). Str("media", "trakt").Logger()
Logger()
return &Client{ return &Client{
log: l, log: l,

View File

@@ -5,8 +5,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek" "github.com/lucperkins/rek"
"github.com/l3uddz/nabarr/util"
) )
var ( var (

View File

@@ -5,10 +5,11 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"go.uber.org/ratelimit" "go.uber.org/ratelimit"
"github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/util"
) )
type Client struct { type Client struct {
@@ -21,9 +22,8 @@ type Client struct {
} }
func New(cfg *Config) *Client { func New(cfg *Config) *Client {
l := logger.New(cfg.Verbosity).With(). l := logger.Child(logger.WithLevel(cfg.Verbosity)).With().
Str("media", "tvdb"). Str("media", "tvdb").Logger()
Logger()
return &Client{ return &Client{
log: l, log: l,

View File

@@ -4,6 +4,7 @@ import (
"time" "time"
"github.com/antonmedv/expr/vm" "github.com/antonmedv/expr/vm"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
) )

View File

@@ -8,10 +8,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/lucperkins/rek"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek"
) )
var ( 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) 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 { func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
// prepare options // prepare options
o, err := nabarr.BuildPvrOptions(opts...) o, err := nabarr.BuildPvrOptions(opts...)

View File

@@ -4,9 +4,10 @@ import (
"fmt" "fmt"
"github.com/antonmedv/expr" "github.com/antonmedv/expr"
"github.com/pkg/errors"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/pkg/errors"
) )
func (c *Client) compileExpressions(filters nabarr.PvrFilters) error { func (c *Client) compileExpressions(filters nabarr.PvrFilters) error {

View File

@@ -4,9 +4,10 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/lefelys/state"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/lefelys/state"
) )
func (c *Client) QueueFeedItem(item *media.FeedItem) { func (c *Client) QueueFeedItem(item *media.FeedItem) {
@@ -171,6 +172,27 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
continue 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 // add item to pvr
c.log.Debug(). c.log.Debug().
Str("feed_title", mediaItem.FeedTitle). Str("feed_title", mediaItem.FeedTitle).

View File

@@ -6,12 +6,13 @@ import (
"strings" "strings"
"time" "time"
"github.com/rs/zerolog"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/cache" "github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/logger" "github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/rs/zerolog"
) )
type Client struct { 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) { 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_name", c.Name).
Str("pvr_type", c.Type). Str("pvr_type", c.Type).
Logger() Logger()

View File

@@ -9,6 +9,13 @@ type qualityProfile struct {
Id int Id int
} }
type exclusion struct {
TmdbId int `json:"tmdbId"`
MovieTitle string `json:"movieTitle"`
MovieYear int `json:"movieYear"`
Id int `json:"id"`
}
type lookupRequest struct { type lookupRequest struct {
Id int `json:"id,omitempty"` Id int `json:"id,omitempty"`
Title string `json:"title"` Title string `json:"title"`

View File

@@ -4,9 +4,10 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/robfig/cron/v3"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr" "github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/robfig/cron/v3"
) )
func (c *Client) AddJob(feed feedItem) error { func (c *Client) AddJob(feed feedItem) error {

View File

@@ -6,9 +6,10 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/lucperkins/rek"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek"
) )
func (j *rssJob) process() error { func (j *rssJob) process() error {

View File

@@ -3,12 +3,13 @@ package rss
import ( import (
"time" "time"
"github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/l3uddz/nabarr/logger"
"github.com/lefelys/state" "github.com/lefelys/state"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/l3uddz/nabarr/logger"
) )
type Client struct { type Client struct {
@@ -27,7 +28,7 @@ func New(c Config, cc *cache.Client, pvrs map[string]pvr.PVR) *Client {
cache: cc, cache: cc,
pvrs: pvrs, pvrs: pvrs,
log: logger.New(c.Verbosity).With().Logger(), log: logger.Child(logger.WithLevel(c.Verbosity)),
} }
} }

View File

@@ -4,10 +4,11 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/cmd/nabarr/pvr"
) )
type feedItem struct { type feedItem struct {

View File

@@ -8,10 +8,11 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/lucperkins/rek"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek"
) )
var ( 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) 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 { func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
// prepare options // prepare options
o, err := nabarr.BuildPvrOptions(opts...) o, err := nabarr.BuildPvrOptions(opts...)

View File

@@ -4,9 +4,10 @@ import (
"fmt" "fmt"
"github.com/antonmedv/expr" "github.com/antonmedv/expr"
"github.com/pkg/errors"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/pkg/errors"
) )
func (c *Client) compileExpressions(filters nabarr.PvrFilters) error { func (c *Client) compileExpressions(filters nabarr.PvrFilters) error {

View File

@@ -5,10 +5,11 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/lefelys/state"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/lefelys/state"
) )
func (c *Client) QueueFeedItem(item *media.FeedItem) { func (c *Client) QueueFeedItem(item *media.FeedItem) {
@@ -162,6 +163,26 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
continue 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 // set appropriate series type
switch { switch {
case util.StringSliceContains(mediaItem.Genres, "anime"), util.StringSliceContains(mediaItem.Tvdb.Genre, "anime"): case util.StringSliceContains(mediaItem.Genres, "anime"), util.StringSliceContains(mediaItem.Tvdb.Genre, "anime"):

View File

@@ -6,12 +6,13 @@ import (
"strings" "strings"
"time" "time"
"github.com/rs/zerolog"
"github.com/l3uddz/nabarr" "github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/cache" "github.com/l3uddz/nabarr/cache"
"github.com/l3uddz/nabarr/logger" "github.com/l3uddz/nabarr/logger"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util" "github.com/l3uddz/nabarr/util"
"github.com/rs/zerolog"
) )
type Client struct { 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) { 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_name", c.Name).
Str("pvr_type", c.Type). Str("pvr_type", c.Type).
Logger() Logger()

View File

@@ -9,6 +9,12 @@ type qualityProfile struct {
Id int Id int
} }
type exclusion struct {
TvdbId int `json:"tvdbId"`
Title string `json:"title"`
Id int `json:"id"`
}
type languageProfile struct { type languageProfile struct {
Name string Name string
Id int Id int

View File

@@ -5,9 +5,10 @@ import (
"time" "time"
"github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/go-retryablehttp"
"github.com/l3uddz/nabarr/build"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"go.uber.org/ratelimit" "go.uber.org/ratelimit"
"github.com/l3uddz/nabarr/build"
) )
func NewRetryableHttpClient(timeout time.Duration, rl ratelimit.Limiter, log *zerolog.Logger) *http.Client { func NewRetryableHttpClient(timeout time.Duration, rl ratelimit.Limiter, log *zerolog.Logger) *http.Client {