Biggest file filter
This commit is contained in:
1
dist/md5.txt
vendored
1
dist/md5.txt
vendored
@@ -1 +0,0 @@
|
||||
d41d8cd98f00b204e9800998ecf8427e ./md5.txt
|
||||
@@ -40,6 +40,13 @@ func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
return rootDirectories
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetDirectoryConfig(directory string) Directory {
|
||||
if dirCfg, ok := z.Directories[directory]; ok {
|
||||
return *dirCfg
|
||||
}
|
||||
return Directory{}
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
||||
var groupMap = make(map[string][]string)
|
||||
var groupOrderMap = make(map[string]int) // To store GroupOrder for each directory
|
||||
|
||||
@@ -4,13 +4,14 @@ import "github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
|
||||
type ZurgConfigV1 struct {
|
||||
ZurgConfig `yaml:",inline"`
|
||||
Directories map[string]*DirectoryFilterConditionsV1 `yaml:"directories"`
|
||||
Directories map[string]*Directory `yaml:"directories"`
|
||||
log *logutil.Logger
|
||||
}
|
||||
type DirectoryFilterConditionsV1 struct {
|
||||
GroupOrder int `yaml:"group_order"`
|
||||
Group string `yaml:"group"`
|
||||
Filters []*FilterConditionsV1 `yaml:"filters"`
|
||||
type Directory struct {
|
||||
GroupOrder int `yaml:"group_order"`
|
||||
Group string `yaml:"group"`
|
||||
Filters []*FilterConditionsV1 `yaml:"filters"`
|
||||
OnlyShowTheBiggestFile bool `yaml:"only_show_the_biggest_file"`
|
||||
}
|
||||
|
||||
type FilterConditionsV1 struct {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
)
|
||||
@@ -59,6 +60,12 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
|
||||
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
|
||||
}
|
||||
|
||||
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
|
||||
biggestFileSize := int64(0)
|
||||
if dirCfg.OnlyShowTheBiggestFile {
|
||||
biggestFileSize = tor.ComputeBiggestFileSize()
|
||||
}
|
||||
|
||||
htmlDoc := "<ol>"
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
sort.Strings(filenames)
|
||||
@@ -67,6 +74,9 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
|
||||
if !ok || !strings.HasPrefix(file.Link, "http") {
|
||||
continue
|
||||
}
|
||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||
continue
|
||||
}
|
||||
filePath := filepath.Join(directory, torrentName, url.PathEscape(filename))
|
||||
htmlDoc += fmt.Sprintf("<li><a href=\"/http/%s\">%s</a></li>", filePath, filename)
|
||||
}
|
||||
|
||||
@@ -115,6 +115,16 @@ func (t *Torrent) ComputeTotalSize() int64 {
|
||||
return totalSize
|
||||
}
|
||||
|
||||
func (t *Torrent) ComputeBiggestFileSize() int64 {
|
||||
biggestSize := int64(0)
|
||||
t.SelectedFiles.IterCb(func(key string, value *File) {
|
||||
if value.Bytes > biggestSize {
|
||||
biggestSize = value.Bytes
|
||||
}
|
||||
})
|
||||
return biggestSize
|
||||
}
|
||||
|
||||
func (t *Torrent) OlderThanDuration(duration time.Duration) bool {
|
||||
latestAdded, err := time.Parse(time.RFC3339, t.LatestAdded)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user