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