mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-16 04:20:46 +08:00
Initial commit, pt. 32
This commit is contained in:
@@ -33,10 +33,10 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
StreamStart = &cobra.Command{
|
||||
Use: "stream-start",
|
||||
StreamSetup = &cobra.Command{
|
||||
Use: "stream-setup",
|
||||
Args: cobra.ExactArgs(0),
|
||||
Run: streamStart,
|
||||
Run: streamSetup,
|
||||
}
|
||||
|
||||
StreamStatus = &cobra.Command{
|
||||
@@ -49,14 +49,14 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
Root.AddCommand(StreamStart)
|
||||
Root.AddCommand(StreamSetup)
|
||||
Root.AddCommand(StreamStatus)
|
||||
|
||||
Root.PersistentFlags().Var(&LoggerLevel, "log-level", "")
|
||||
Root.PersistentFlags().String("remote-addr", "localhost:3594", "the path to the config file")
|
||||
StreamStart.PersistentFlags().String("title", "", "stream title")
|
||||
StreamStart.PersistentFlags().String("description", "", "stream description")
|
||||
StreamStart.PersistentFlags().String("profile", "", "profile")
|
||||
StreamSetup.PersistentFlags().String("title", "", "stream title")
|
||||
StreamSetup.PersistentFlags().String("description", "", "stream description")
|
||||
StreamSetup.PersistentFlags().String("profile", "", "profile")
|
||||
}
|
||||
func assertNoError(ctx context.Context, err error) {
|
||||
if err != nil {
|
||||
@@ -64,7 +64,7 @@ func assertNoError(ctx context.Context, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func streamStart(cmd *cobra.Command, args []string) {
|
||||
func streamSetup(cmd *cobra.Command, args []string) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
remoteAddr, err := cmd.Flags().GetString("remote-addr")
|
||||
|
@@ -265,6 +265,15 @@ func (yt *YouTube) InsertAdsCuePoint(
|
||||
})
|
||||
}
|
||||
|
||||
func (yt *YouTube) DeleteActiveBroadcasts(
|
||||
ctx context.Context,
|
||||
) error {
|
||||
return yt.iterateActiveBroadcasts(ctx, func(broadcast *youtube.LiveBroadcast) error {
|
||||
logger.Debugf(ctx, "deleting broadcast %v", broadcast.Id)
|
||||
return yt.YouTubeService.LiveBroadcasts.Delete(broadcast.Id).Context(ctx).Do()
|
||||
})
|
||||
}
|
||||
|
||||
type FlagBroadcastTemplateIDs []string
|
||||
|
||||
var liveBroadcastParts = []string{
|
||||
@@ -316,6 +325,11 @@ func (yt *YouTube) StartStream(
|
||||
profile StreamProfile,
|
||||
customArgs ...any,
|
||||
) error {
|
||||
err := yt.DeleteActiveBroadcasts(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to delete old streams: %w", err)
|
||||
}
|
||||
|
||||
var templateBroadcastIDs []string
|
||||
for _, templateBroadcastIDCandidate := range customArgs {
|
||||
_templateBroadcastIDs, ok := templateBroadcastIDCandidate.(FlagBroadcastTemplateIDs)
|
||||
|
Reference in New Issue
Block a user