package ytdlp import ( "context" "crypto/sha1" "encoding/base64" "git.kmsign.ru/royalcat/tstor/pkg/ytdlp" "github.com/royalcat/ctxprogress" ) type ytdlpSource struct { Url string `json:"url"` } var hasher = sha1.New() func (s *ytdlpSource) Name() string { return base64.URLEncoding.EncodeToString(hasher.Sum([]byte(s.Url))) } func (s *ytdlpSource) Download(ctx context.Context, task TaskUpdater, dir string) error { client, err := ytdlp.New() if err != nil { return err } ctxprogress.New(ctx) ctxprogress.Set(ctx, ctxprogress.RangeProgress{Current: 0, Total: 2}) plst, err := client.Playlist(ctx, s.Url) ctxprogress.Set(ctx, ctxprogress.RangeProgress{Current: 1, Total: 2}) ctxprogress.Range(ctx, plst, func(ctx context.Context, _ int, e ytdlp.PlaylistEntry) bool { err = client.Download(ctx, e.Url(), dir) if err != nil { return false } return true }) ctxprogress.Set(ctx, ctxprogress.RangeProgress{Current: 2, Total: 2}) if err != nil { return err } return nil }