mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-19 22:04:36 +08:00
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package streampanel
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/facebookincubator/go-belt/tool/logger"
|
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
|
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol/twitch"
|
|
"github.com/xaionaro-go/streamctl/pkg/streamcontrol/youtube"
|
|
)
|
|
|
|
func newTwitch(
|
|
ctx context.Context,
|
|
cfg *streamcontrol.AbstractPlatformConfig,
|
|
saveCfgFunc func(*streamcontrol.AbstractPlatformConfig) error,
|
|
) (
|
|
*twitch.Twitch,
|
|
error,
|
|
) {
|
|
platCfg := streamcontrol.ConvertPlatformConfig[twitch.PlatformSpecificConfig, twitch.StreamProfile](
|
|
ctx, cfg, twitch.ID,
|
|
)
|
|
if platCfg == nil {
|
|
return nil, fmt.Errorf("twitch config was not found")
|
|
}
|
|
|
|
logger.Debugf(ctx, "twitch config: %#+v", platCfg)
|
|
return twitch.New(ctx, *platCfg,
|
|
func(c twitch.Config) error {
|
|
return saveCfgFunc(&streamcontrol.AbstractPlatformConfig{
|
|
Config: c.Config,
|
|
StreamProfiles: streamcontrol.ToAbstractStreamProfiles(c.StreamProfiles),
|
|
})
|
|
},
|
|
)
|
|
}
|
|
|
|
func newYouTube(
|
|
ctx context.Context,
|
|
cfg *streamcontrol.AbstractPlatformConfig,
|
|
saveCfgFunc func(*streamcontrol.AbstractPlatformConfig) error,
|
|
) (
|
|
*youtube.YouTube,
|
|
error,
|
|
) {
|
|
platCfg := streamcontrol.ConvertPlatformConfig[youtube.PlatformSpecificConfig, youtube.StreamProfile](
|
|
ctx, cfg, twitch.ID,
|
|
)
|
|
if platCfg == nil {
|
|
return nil, fmt.Errorf("youtube config was not found")
|
|
}
|
|
|
|
logger.Debugf(ctx, "youtube config: %#+v", platCfg)
|
|
return youtube.New(ctx, *platCfg,
|
|
func(c youtube.Config) error {
|
|
return saveCfgFunc(&streamcontrol.AbstractPlatformConfig{
|
|
Config: c.Config,
|
|
StreamProfiles: streamcontrol.ToAbstractStreamProfiles(c.StreamProfiles),
|
|
})
|
|
},
|
|
)
|
|
}
|