mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: add to blacklist if torrent has no video file
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
"polaris/log"
|
"polaris/log"
|
||||||
"polaris/pkg"
|
"polaris/pkg"
|
||||||
"polaris/pkg/notifier/message"
|
"polaris/pkg/notifier/message"
|
||||||
|
"polaris/pkg/storage"
|
||||||
"polaris/pkg/utils"
|
"polaris/pkg/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -292,6 +293,10 @@ func (c *Engine) moveCompletedTask(id int) (err1 error) {
|
|||||||
|
|
||||||
//如果种子是路径,则会把路径展开,只移动文件,类似 move dir/* dir2/, 如果种子是文件,则会直接移动文件,类似 move file dir/
|
//如果种子是路径,则会把路径展开,只移动文件,类似 move dir/* dir2/, 如果种子是文件,则会直接移动文件,类似 move file dir/
|
||||||
if err := stImpl.Copy(filepath.Join(c.db.GetDownloadDir(), torrentName), r.TargetDir, torrent.WalkFunc()); err != nil {
|
if err := stImpl.Copy(filepath.Join(c.db.GetDownloadDir(), torrentName), r.TargetDir, torrent.WalkFunc()); err != nil {
|
||||||
|
if errors.Is(err, &storage.NoVideoFileError{}) {
|
||||||
|
log.Warnf("no video file found in torrent, add torrent to blacklist: %v", torrentName)
|
||||||
|
c.db.AddTorrent2Blacklist(r.Hash, r.SourceTitle, r.MediaID)
|
||||||
|
}
|
||||||
return errors.Wrap(err, "move file")
|
return errors.Wrap(err, "move file")
|
||||||
}
|
}
|
||||||
torrent.UploadProgresser = stImpl.UploadProgress
|
torrent.UploadProgresser = stImpl.UploadProgress
|
||||||
|
|||||||
@@ -80,10 +80,24 @@ func (b *Base) isFileNeeded(name string) bool {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NoVideoFileError struct {
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NoVideoFileError) Error() string {
|
||||||
|
return "no video file in path: " + e.Path
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NoVideoFileError) Is(target error) bool {
|
||||||
|
_, ok := target.(*NoVideoFileError)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Base) Upload(destDir string, tryLink, detectMime, changeMediaHash bool, upload uploadFunc, mkdir func(string) error, walkFn WalkFn) error {
|
func (b *Base) Upload(destDir string, tryLink, detectMime, changeMediaHash bool, upload uploadFunc, mkdir func(string) error, walkFn WalkFn) error {
|
||||||
if !b.checkVideoFilesExist() {
|
if !b.checkVideoFilesExist() {
|
||||||
return errors.Errorf("torrent has no video file(s)")
|
return &NoVideoFileError{Path: b.src}
|
||||||
}
|
}
|
||||||
|
|
||||||
os.MkdirAll(destDir, os.ModePerm)
|
os.MkdirAll(destDir, os.ModePerm)
|
||||||
|
|
||||||
targetBase := filepath.Join(destDir, filepath.Base(b.src)) //文件的场景,要加上文件名, move filename ./dir/
|
targetBase := filepath.Join(destDir, filepath.Base(b.src)) //文件的场景,要加上文件名, move filename ./dir/
|
||||||
|
|||||||
16
pkg/storage/base_test.go
Normal file
16
pkg/storage/base_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestError(t *testing.T) {
|
||||||
|
err := &NoVideoFileError{Path: "/some/path"}
|
||||||
|
if errors.Is(err, &NoVideoFileError{}) {
|
||||||
|
t.Log("is NoVideoFileError")
|
||||||
|
} else {
|
||||||
|
t.Error("not match")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user