feat: configurable parser and refactor config

This commit is contained in:
krau
2025-08-23 14:29:32 +08:00
parent 03eb4f8a18
commit e5d1e143e0
28 changed files with 181 additions and 105 deletions

View File

@@ -11,12 +11,18 @@ type Parser interface {
Parse(ctx context.Context, url string) (*Item, error)
}
type ConfigurableParser interface {
Parser
Configure(config map[string]any) error
Name() string
}
// Resource is a single downloadable resource with metadata.
type Resource struct {
URL string `json:"url"`
Filename string `json:"filename"` // with ext
MimeType string `json:"mime_type"`
Extension string `json:"extension"`
Extension string `json:"extension"` // e.g. "mp4"
Size int64 `json:"size"` // 0 when unknown
Hash map[string]string `json:"hash"` // {"md5": "...", "sha256": "..."}
Headers map[string]string `json:"headers"` // HTTP headers when downloading

View File

@@ -9,5 +9,5 @@ import (
func NewDownloader(file TGFile) *downloader.Builder {
return downloader.NewDownloader().WithPartSize(tglimit.MaxPartSize).
Download(file.Dler(), file.Location()).WithThreads(dlutil.BestThreads(file.Size(), config.Cfg.Threads))
Download(file.Dler(), file.Location()).WithThreads(dlutil.BestThreads(file.Size(), config.C().Threads))
}