Add file size gte
This commit is contained in:
@@ -12,7 +12,7 @@ type ConfigInterface interface {
|
||||
GetHost() string
|
||||
GetPort() string
|
||||
GetDirectories() []string
|
||||
MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool
|
||||
MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64) bool
|
||||
GetOnLibraryUpdate() string
|
||||
GetNetworkBufferSize() int
|
||||
EnableRetainFolderNameExtension() bool
|
||||
|
||||
@@ -73,7 +73,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
return result
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentIDs, fileNames []string) bool {
|
||||
func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64) bool {
|
||||
if directory == ALL_TORRENTS {
|
||||
return true
|
||||
}
|
||||
@@ -81,14 +81,14 @@ func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentIDs
|
||||
return false
|
||||
}
|
||||
for _, filter := range z.Directories[directory].Filters {
|
||||
if z.matchFilter(torrentName, torrentIDs, fileNames, filter) {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, filter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []string, filter *FilterConditionsV1) bool {
|
||||
func (z *ZurgConfigV1) matchFilter(torrentName string, torrentSize int64, torrentIDs, fileNames []string, fileSizes []int64, filter *FilterConditionsV1) bool {
|
||||
if filter.ID != "" {
|
||||
for _, torrentID := range torrentIDs {
|
||||
if torrentID == filter.ID {
|
||||
@@ -128,10 +128,16 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []s
|
||||
if filter.NotContains != "" && !strings.Contains(strings.ToLower(torrentName), strings.ToLower(filter.NotContains)) {
|
||||
return true
|
||||
}
|
||||
if filter.SizeGreaterThanOrEqual > 0 && torrentSize >= filter.SizeGreaterThanOrEqual {
|
||||
return true
|
||||
}
|
||||
if filter.SizeLessThanOrEqual > 0 && torrentSize <= filter.SizeLessThanOrEqual {
|
||||
return true
|
||||
}
|
||||
if len(filter.And) > 0 {
|
||||
andResult := true
|
||||
for _, andFilter := range filter.And {
|
||||
andResult = andResult && z.matchFilter(torrentName, torrentIDs, fileNames, andFilter)
|
||||
andResult = andResult && z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, andFilter)
|
||||
if !andResult {
|
||||
return false
|
||||
}
|
||||
@@ -140,7 +146,7 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []s
|
||||
}
|
||||
if len(filter.Or) > 0 {
|
||||
for _, orFilter := range filter.Or {
|
||||
if z.matchFilter(torrentName, torrentIDs, fileNames, orFilter) {
|
||||
if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, orFilter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -211,6 +217,20 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []s
|
||||
}
|
||||
return checkArithmeticSequenceInFilenames(fileNames)
|
||||
}
|
||||
if filter.FileInsideSizeGreaterThanOrEqual > 0 {
|
||||
for _, fileSize := range fileSizes {
|
||||
if fileSize >= filter.FileInsideSizeGreaterThanOrEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if filter.FileInsideSizeLessThanOrEqual > 0 {
|
||||
for _, fileSize := range fileSizes {
|
||||
if fileSize <= filter.FileInsideSizeLessThanOrEqual {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ type FilterConditionsV1 struct {
|
||||
NotRegexStr string `yaml:"not_regex"`
|
||||
NotContains string `yaml:"not_contains"`
|
||||
NotContainsStrict string `yaml:"not_contains_strict"`
|
||||
SizeGreaterThanOrEqual int64 `yaml:"size_gte"`
|
||||
SizeLessThanOrEqual int64 `yaml:"size_lte"`
|
||||
|
||||
And []*FilterConditionsV1 `yaml:"and"`
|
||||
Or []*FilterConditionsV1 `yaml:"or"`
|
||||
@@ -31,6 +33,8 @@ type FilterConditionsV1 struct {
|
||||
FileInsideNotRegexStr string `yaml:"any_file_inside_not_regex"`
|
||||
FileInsideNotContains string `yaml:"any_file_inside_not_contains"`
|
||||
FileInsideNotContainsStrict string `yaml:"any_file_inside_not_contains_strict"`
|
||||
FileInsideSizeGreaterThanOrEqual int64 `yaml:"any_file_inside_size_gte"`
|
||||
FileInsideSizeLessThanOrEqual int64 `yaml:"any_file_inside_size_lte"`
|
||||
|
||||
HasEpisodes bool `yaml:"has_episodes"`
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package torrent
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
@@ -120,14 +121,19 @@ func (t *TorrentManager) TriggerHookOnLibraryUpdate(updatedPaths []string) {
|
||||
func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||
torrentIDs := strset.Union(tor.DownloadedIDs, tor.InProgressIDs).List()
|
||||
// get filenames needed for directory conditions
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
var filenames []string
|
||||
var fileSizes []int64
|
||||
tor.SelectedFiles.IterCb(func(key string, file *File) {
|
||||
filenames = append(filenames, filepath.Base(file.Path))
|
||||
fileSizes = append(fileSizes, file.Bytes)
|
||||
})
|
||||
// Map torrents to directories
|
||||
switch t.Config.GetVersion() {
|
||||
case "v1":
|
||||
configV1 := t.Config.(*config.ZurgConfigV1)
|
||||
for _, directories := range configV1.GetGroupMap() {
|
||||
for _, directory := range directories {
|
||||
if t.Config.MeetsConditions(directory, tor.AccessKey, torrentIDs, filenames) {
|
||||
if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
|
||||
cb(directory)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -104,6 +104,14 @@ func (t *Torrent) AllInProgress() bool {
|
||||
return t.DownloadedIDs.IsEmpty()
|
||||
}
|
||||
|
||||
func (t *Torrent) ComputeTotalSize() int64 {
|
||||
totalSize := int64(0)
|
||||
t.SelectedFiles.IterCb(func(key string, value *File) {
|
||||
totalSize += value.Bytes
|
||||
})
|
||||
return totalSize
|
||||
}
|
||||
|
||||
type File struct {
|
||||
realdebrid.File
|
||||
Added string `json:"Added"`
|
||||
|
||||
Reference in New Issue
Block a user