Add file size gte
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,23 +14,27 @@ type DirectoryFilterConditionsV1 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilterConditionsV1 struct {
|
type FilterConditionsV1 struct {
|
||||||
ID string `yaml:"id"`
|
ID string `yaml:"id"`
|
||||||
RegexStr string `yaml:"regex"`
|
RegexStr string `yaml:"regex"`
|
||||||
Contains string `yaml:"contains"`
|
Contains string `yaml:"contains"`
|
||||||
ContainsStrict string `yaml:"contains_strict"`
|
ContainsStrict string `yaml:"contains_strict"`
|
||||||
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"`
|
||||||
|
|
||||||
FileInsideRegexStr string `yaml:"any_file_inside_regex"`
|
FileInsideRegexStr string `yaml:"any_file_inside_regex"`
|
||||||
FileInsideContains string `yaml:"any_file_inside_contains"`
|
FileInsideContains string `yaml:"any_file_inside_contains"`
|
||||||
FileInsideContainsStrict string `yaml:"any_file_inside_contains_strict"`
|
FileInsideContainsStrict string `yaml:"any_file_inside_contains_strict"`
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"`
|
||||||
|
|||||||
Reference in New Issue
Block a user