mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 23:25:30 +02:00
34 lines
572 B
Go
34 lines
572 B
Go
package media
|
|
|
|
import "context"
|
|
|
|
type Media interface {
|
|
Rip(ctx context.Context) error
|
|
}
|
|
|
|
type Pending interface {
|
|
Resolve(ctx context.Context) (Media, error)
|
|
}
|
|
|
|
type MediaFunc struct {
|
|
RipFn func(ctx context.Context) error
|
|
}
|
|
|
|
func (m MediaFunc) Rip(ctx context.Context) error {
|
|
if m.RipFn == nil {
|
|
return nil
|
|
}
|
|
return m.RipFn(ctx)
|
|
}
|
|
|
|
type PendingFunc struct {
|
|
ResolveFn func(ctx context.Context) (Media, error)
|
|
}
|
|
|
|
func (p PendingFunc) Resolve(ctx context.Context) (Media, error) {
|
|
if p.ResolveFn == nil {
|
|
return MediaFunc{}, nil
|
|
}
|
|
return p.ResolveFn(ctx)
|
|
}
|