Skip to content

Commit

Permalink
Store relative paths for the actual files to send file scans to Emby &
Browse files Browse the repository at this point in the history
Jellyfin

Signed-off-by: Anagh Kumar Baranwal <[email protected]>
  • Loading branch information
darthShadow committed Dec 13, 2023
1 parent 7982fe1 commit 012332d
Show file tree
Hide file tree
Showing 21 changed files with 342 additions and 217 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
steps:
# dependencies
- name: goreleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v4
with:
install-only: true
version: 1.7.0
version: latest

- name: goreleaser info
run: goreleaser -v
Expand All @@ -44,9 +44,9 @@ jobs:

# setup go
- name: go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.21

- name: go info
run: |
Expand Down Expand Up @@ -106,15 +106,9 @@ jobs:
name: build_linux
path: dist/*linux*

- name: artifact_darwin
uses: actions/upload-artifact@v3
with:
name: build_darwin
path: dist/*darwin*

# docker login
- name: docker login
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand Down
7 changes: 2 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ builds:
main: ./cmd/autoscan
goarch:
- amd64
goamd64:
- v2
ldflags:
- -s -w
- -X "main.Version={{ .Version }}"
- -X "main.GitCommit={{ .ShortCommit }}"
- -X "main.Timestamp={{ .Timestamp }}"
flags:
- -trimpath
ignore:
- goos: freebsd
goarch: arm64
- goos: freebsd
goarch: arm

# MacOS Universal Binaries
universal_binaries:
Expand Down
6 changes: 3 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ tasks:
release:
desc: Generate a release, but don't publish
cmds:
- goreleaser --skip-validate --skip-publish --rm-dist
- goreleaser --skip-validate --skip-publish --clean

snapshot:
desc: Generate a snapshot release
cmds:
- goreleaser --snapshot --skip-publish --rm-dist
- goreleaser --snapshot --skip-publish --clean

publish:
desc: Generate a release, and publish
cmds:
- goreleaser --rm-dist
- goreleaser --clean
7 changes: 4 additions & 3 deletions autoscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
//
// The Scan is used across Triggers, Targets and the Processor.
type Scan struct {
Folder string
Priority int
Time time.Time
Folder string
RelativePath string
Priority int
Time time.Time
}

type ProcessorFunc func(...Scan) error
Expand Down
47 changes: 13 additions & 34 deletions cmd/autoscan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ func main() {
Err(err).
Msg("Failed opening config")
}
defer file.Close()
defer func() {
_ = file.Close()
}()

// set default values
c := config{
Expand Down Expand Up @@ -353,10 +355,9 @@ func main() {
targetsAvailable := false
targetsSize := len(targets)
for {
// sleep indefinitely when no targets setup
// exit when no targets setup
if targetsSize == 0 {
log.Warn().Msg("No targets initialised, processor stopped, triggers will continue...")
select {}
log.Fatal().Msg("No targets initialised, exiting...")
}

// target availability checker
Expand All @@ -365,18 +366,12 @@ func main() {
switch {
case err == nil:
targetsAvailable = true

case errors.Is(err, autoscan.ErrFatal):
log.Error().
Err(err).
Msg("Fatal error occurred while checking target availability, processor stopped, triggers will continue...")
log.Fatal().Err(err).Msg("Fatal error occurred while checking target availability, exiting...")

// sleep indefinitely
select {}
default:
log.Error().
Err(err).
Msg("Not all targets are available, retrying in 15 seconds...")

log.Error().Err(err).Msg("Not all targets are available, retrying in 15 seconds...")
time.Sleep(15 * time.Second)
continue
}
Expand All @@ -391,40 +386,24 @@ func main() {

case errors.Is(err, autoscan.ErrNoScans):
// No scans currently available, let's wait a couple of seconds
log.Trace().
Msg("No scans are available, retrying in 15 seconds...")

log.Trace().Msg("No scans are available, retrying in 15 seconds...")
time.Sleep(15 * time.Second)

case errors.Is(err, autoscan.ErrAnchorUnavailable):
log.Error().
Err(err).
Msg("Not all anchor files are available, retrying in 15 seconds...")

log.Error().Err(err).Msg("Not all anchor files are available, retrying in 15 seconds...")
time.Sleep(15 * time.Second)

case errors.Is(err, autoscan.ErrTargetUnavailable):
targetsAvailable = false
log.Error().
Err(err).
Msg("Not all targets are available, retrying in 15 seconds...")

log.Error().Err(err).Msg("Not all targets are available, retrying in 15 seconds...")
time.Sleep(15 * time.Second)

case errors.Is(err, autoscan.ErrFatal):
// fatal error occurred, processor must stop (however, triggers must not)
log.Error().
Err(err).
Msg("Fatal error occurred while processing targets, processor stopped, triggers will continue...")

// sleep indefinitely
select {}
log.Error().Err(err).Msg("Fatal error occurred while processing targets, exiting...")

default:
// unexpected error
log.Fatal().
Err(err).
Msg("Failed processing targets")
log.Fatal().Err(err).Msg("Failed processing targets, exiting...")
}
}
}
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ENV \
AUTOSCAN_VERBOSITY="0"

# Binary
COPY ["./dist/autoscan_${TARGETOS}_${TARGETARCH}${TARGETVARIANT:+_7}/autoscan", "/app/autoscan/autoscan"]
COPY ["./dist/autoscan_${TARGETOS}_${TARGETARCH}${TARGETVARIANT:+_7}_v2/autoscan", "/app/autoscan/autoscan"]

# Add root files
COPY ["./docker/run", "/etc/services.d/autoscan/run"]
Expand Down
52 changes: 26 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
module github.com/cloudbox/autoscan

go 1.19
go 1.21

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/alecthomas/kong v0.6.1
github.com/fsnotify/fsnotify v1.5.4
github.com/go-chi/chi/v5 v5.0.7
github.com/alecthomas/kong v0.8.0
github.com/fsnotify/fsnotify v1.6.0
github.com/go-chi/chi/v5 v5.0.10
github.com/l3uddz/bernard v0.5.1
github.com/m-rots/stubbs v1.1.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/oriser/regroup v0.0.0-20210730155327-fca8d7531263
github.com/oriser/regroup v0.0.0-20201024192559-010c434ff8f3
github.com/robfig/cron/v3 v3.0.1
github.com/rs/zerolog v1.28.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
golang.org/x/tools v0.1.12 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
github.com/rs/zerolog v1.30.0
golang.org/x/sync v0.3.0
golang.org/x/time v0.3.0
gopkg.in/yaml.v2 v2.4.0
modernc.org/cc/v3 v3.38.1 // indirect
modernc.org/sqlite v1.18.2
modernc.org/strutil v1.1.3 // indirect
modernc.org/sqlite v1.25.0
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/rs/xid v1.4.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/ccgo/v3 v3.16.9 // indirect
modernc.org/libc v1.19.0 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/xid v1.5.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/tools v0.9.3 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.24.1 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/token v1.0.1 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.1.0 // indirect
)
Loading

0 comments on commit 012332d

Please sign in to comment.