Initial commit, pt. 32

This commit is contained in:
Dmitrii Okunev
2024-06-30 23:58:02 +01:00
parent ca54428d1e
commit 020e0b74f5
2 changed files with 22 additions and 8 deletions

View File

@@ -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")

View File

@@ -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)