Add file size gte

This commit is contained in:
Ben Sarmiento
2023-12-06 12:37:38 +01:00
parent 3a753f6f26
commit 2a0b0fa9cd
5 changed files with 59 additions and 21 deletions

View File

@@ -12,7 +12,7 @@ type ConfigInterface interface {
GetHost() string GetHost() string
GetPort() string GetPort() string
GetDirectories() []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 GetOnLibraryUpdate() string
GetNetworkBufferSize() int GetNetworkBufferSize() int
EnableRetainFolderNameExtension() bool EnableRetainFolderNameExtension() bool

View File

@@ -73,7 +73,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
return result 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 { if directory == ALL_TORRENTS {
return true return true
} }
@@ -81,14 +81,14 @@ func (z *ZurgConfigV1) MeetsConditions(directory, torrentName string, torrentIDs
return false return false
} }
for _, filter := range z.Directories[directory].Filters { 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 true
} }
} }
return false 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 != "" { if filter.ID != "" {
for _, torrentID := range torrentIDs { for _, torrentID := range torrentIDs {
if torrentID == filter.ID { 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)) { if filter.NotContains != "" && !strings.Contains(strings.ToLower(torrentName), strings.ToLower(filter.NotContains)) {
return true 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 { if len(filter.And) > 0 {
andResult := true andResult := true
for _, andFilter := range filter.And { 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 { if !andResult {
return false return false
} }
@@ -140,7 +146,7 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []s
} }
if len(filter.Or) > 0 { if len(filter.Or) > 0 {
for _, orFilter := range filter.Or { for _, orFilter := range filter.Or {
if z.matchFilter(torrentName, torrentIDs, fileNames, orFilter) { if z.matchFilter(torrentName, torrentSize, torrentIDs, fileNames, fileSizes, orFilter) {
return true return true
} }
} }
@@ -211,6 +217,20 @@ func (z *ZurgConfigV1) matchFilter(torrentName string, torrentIDs, fileNames []s
} }
return checkArithmeticSequenceInFilenames(fileNames) 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 return false
} }

View File

@@ -21,6 +21,8 @@ type FilterConditionsV1 struct {
NotRegexStr string `yaml:"not_regex"` NotRegexStr string `yaml:"not_regex"`
NotContains string `yaml:"not_contains"` NotContains string `yaml:"not_contains"`
NotContainsStrict string `yaml:"not_contains_strict"` NotContainsStrict string `yaml:"not_contains_strict"`
SizeGreaterThanOrEqual int64 `yaml:"size_gte"`
SizeLessThanOrEqual int64 `yaml:"size_lte"`
And []*FilterConditionsV1 `yaml:"and"` And []*FilterConditionsV1 `yaml:"and"`
Or []*FilterConditionsV1 `yaml:"or"` Or []*FilterConditionsV1 `yaml:"or"`
@@ -31,6 +33,8 @@ type FilterConditionsV1 struct {
FileInsideNotRegexStr string `yaml:"any_file_inside_not_regex"` FileInsideNotRegexStr string `yaml:"any_file_inside_not_regex"`
FileInsideNotContains string `yaml:"any_file_inside_not_contains"` FileInsideNotContains string `yaml:"any_file_inside_not_contains"`
FileInsideNotContainsStrict string `yaml:"any_file_inside_not_contains_strict"` 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"` HasEpisodes bool `yaml:"has_episodes"`
} }

View File

@@ -3,6 +3,7 @@ package torrent
import ( import (
"io" "io"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/debridmediamanager/zurg/internal/config" "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)) { func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
torrentIDs := strset.Union(tor.DownloadedIDs, tor.InProgressIDs).List() torrentIDs := strset.Union(tor.DownloadedIDs, tor.InProgressIDs).List()
// get filenames needed for directory conditions // 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 // Map torrents to directories
switch t.Config.GetVersion() { switch t.Config.GetVersion() {
case "v1": case "v1":
configV1 := t.Config.(*config.ZurgConfigV1) configV1 := t.Config.(*config.ZurgConfigV1)
for _, directories := range configV1.GetGroupMap() { for _, directories := range configV1.GetGroupMap() {
for _, directory := range directories { 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) cb(directory)
break break
} }

View File

@@ -104,6 +104,14 @@ func (t *Torrent) AllInProgress() bool {
return t.DownloadedIDs.IsEmpty() 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 { type File struct {
realdebrid.File realdebrid.File
Added string `json:"Added"` Added string `json:"Added"`