mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user