finalize beta-0.4.1

This commit is contained in:
Mukhtar Akere
2025-02-14 02:42:45 +01:00
parent 6a24c372f5
commit 325e6c912c
3 changed files with 19 additions and 30 deletions

2
go.mod
View File

@@ -15,6 +15,7 @@ require (
github.com/rs/zerolog v1.33.0 github.com/rs/zerolog v1.33.0
github.com/valyala/fastjson v1.6.4 github.com/valyala/fastjson v1.6.4
golang.org/x/crypto v0.33.0 golang.org/x/crypto v0.33.0
golang.org/x/net v0.33.0
golang.org/x/time v0.8.0 golang.org/x/time v0.8.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/natefinch/lumberjack.v2 v2.2.1
) )
@@ -32,7 +33,6 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stretchr/testify v1.10.0 // indirect github.com/stretchr/testify v1.10.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.30.0 // indirect golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect golang.org/x/text v0.22.0 // indirect
) )

View File

@@ -133,9 +133,7 @@ func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
func (q *QBit) ProcessSymlink(torrent *Torrent) (string, error) { func (q *QBit) ProcessSymlink(torrent *Torrent) (string, error) {
debridTorrent := torrent.DebridTorrent debridTorrent := torrent.DebridTorrent
var wg sync.WaitGroup
files := debridTorrent.Files files := debridTorrent.Files
ready := make(chan debrid.File, len(files))
if len(files) == 0 { if len(files) == 0 {
return "", fmt.Errorf("no video files found") return "", fmt.Errorf("no video files found")
} }
@@ -159,19 +157,24 @@ func (q *QBit) ProcessSymlink(torrent *Torrent) (string, error) {
if err != nil { if err != nil {
return "", fmt.Errorf("failed to create directory: %s: %v", torrentSymlinkPath, err) return "", fmt.Errorf("failed to create directory: %s: %v", torrentSymlinkPath, err)
} }
pending := make(map[string]debrid.File)
for _, file := range files { for _, file := range files {
wg.Add(1) pending[file.Path] = file
go checkFileLoop(&wg, torrentRclonePath, file, ready)
} }
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
go func() { for len(pending) > 0 {
wg.Wait() <-ticker.C
close(ready) for path, file := range pending {
}() fullFilePath := filepath.Join(torrentRclonePath, file.Path)
if _, err := os.Stat(fullFilePath); !os.IsNotExist(err) {
for f := range ready { q.logger.Info().Msgf("File is ready: %s", file.Path)
q.logger.Info().Msgf("File is ready: %s", f.Path) q.createSymLink(torrentSymlinkPath, torrentRclonePath, file)
q.createSymLink(torrentSymlinkPath, torrentRclonePath, f) delete(pending, path)
}
}
} }
return torrentSymlinkPath, nil return torrentSymlinkPath, nil
} }
@@ -183,7 +186,7 @@ func (q *QBit) getTorrentPath(rclonePath string, debridTorrent *debrid.Torrent)
q.logger.Debug().Msgf("Found torrent path: %s", torrentPath) q.logger.Debug().Msgf("Found torrent path: %s", torrentPath)
return torrentPath, err return torrentPath, err
} }
time.Sleep(time.Second) time.Sleep(100 * time.Millisecond)
} }
} }
@@ -195,6 +198,7 @@ func (q *QBit) createSymLink(path string, torrentMountPath string, file debrid.F
torrentFilePath := filepath.Join(torrentMountPath, file.Path) // debridFolder/MyTVShow/MyTVShow.S01E01.720p.mkv torrentFilePath := filepath.Join(torrentMountPath, file.Path) // debridFolder/MyTVShow/MyTVShow.S01E01.720p.mkv
err := os.Symlink(torrentFilePath, fullPath) err := os.Symlink(torrentFilePath, fullPath)
if err != nil { if err != nil {
q.logger.Info().Msgf("Failed to create symlink: %s: %v", fullPath, err) // It's okay if the symlink already exists
q.logger.Debug().Msgf("Failed to create symlink: %s: %v", fullPath, err)
} }
} }

View File

@@ -1,15 +0,0 @@
#!/bin/bash
set -e
# Install FUSE and required dependencies
apt-get update
apt-get install -y --no-install-recommends fuse3
rm -rf /var/lib/apt/lists/*
# Create nonroot user and group
groupadd -r nonroot
useradd -r -g nonroot nonroot
# Create mount directory
mkdir -p /mnt/rclone
chown nonroot:nonroot /mnt/rclone