From 150a90f2acda4da89c41f5b09423cc131794a4bc Mon Sep 17 00:00:00 2001 From: kanoshiou Date: Fri, 14 Aug 2026 15:34:58 +0800 Subject: [PATCH] feat(strm): add file size filtering for STRM generation (#2911) * feat(strm): add file size filtering for STRM generation - add ParseSize helper function in pkg/utils to parse human-readable byte sizes - add minFileSize setting field to STRM driver Addition struct - filter out files below minFileSize threshold during STRM generation * refactor(strm): use MB as default unit for minFileSize instead of ParseSize Replace string-based ParseSize auto-conversion with a simple int64 number field defaulting to MB, consistent with other drivers (Google Drive, Teldrive). Remove the now-unused ParseSize function and its tests. --- drivers/strm/driver.go | 2 ++ drivers/strm/meta.go | 1 + drivers/strm/util.go | 3 +++ 3 files changed, 6 insertions(+) diff --git a/drivers/strm/driver.go b/drivers/strm/driver.go index 1189fd9a7..3d243c157 100644 --- a/drivers/strm/driver.go +++ b/drivers/strm/driver.go @@ -27,6 +27,7 @@ type Strm struct { supportSuffix map[string]struct{} downloadSuffix map[string]struct{} + minSizeBytes int64 } func (d *Strm) Config() driver.Config { @@ -120,6 +121,7 @@ func (d *Strm) Init(ctx context.Context) error { if len(d.SaveLocalMode) == 0 { d.SaveLocalMode = SaveLocalInsertMode } + d.minSizeBytes = d.MinFileSize * 1024 * 1024 return nil } diff --git a/drivers/strm/meta.go b/drivers/strm/meta.go index 843ff7c66..2e2e8a08e 100644 --- a/drivers/strm/meta.go +++ b/drivers/strm/meta.go @@ -17,6 +17,7 @@ type Addition struct { PathPrefix string `json:"PathPrefix" type:"text" required:"false" default:"/d" help:"Path prefix"` DownloadFileTypes string `json:"downloadFileTypes" type:"text" default:"ass,srt,vtt,sub,strm" required:"false" help:"Files need to download with strm (usally subtitles)"` FilterFileTypes string `json:"filterFileTypes" type:"text" default:"mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac" required:"false" help:"Supports suffix name of strm file"` + MinFileSize int64 `json:"minFileSize" type:"number" required:"false" default:"0" help:"Filter out files smaller than this size (unit: MB, 0 to disable)"` EncodePath bool `json:"encodePath" default:"true" required:"true" help:"encode the path in the strm file"` WithoutUrl bool `json:"withoutUrl" default:"false" help:"strm file content without URL prefix"` WithSign bool `json:"withSign" default:"false"` diff --git a/drivers/strm/util.go b/drivers/strm/util.go index b9a40da5e..7dfc7dbee 100644 --- a/drivers/strm/util.go +++ b/drivers/strm/util.go @@ -73,6 +73,9 @@ func (d *Strm) convert2strmObjs(ctx context.Context, reqPath string, objs []mode if _, ok := d.downloadSuffix[ext]; ok { size = obj.GetSize() } else if _, ok := d.supportSuffix[ext]; ok { + if d.minSizeBytes > 0 && obj.GetSize() < d.minSizeBytes { + continue + } id = "strm" name = strings.TrimSuffix(name, sourceExt) + "strm" size = int64(len(d.getLink(ctx, path)))