Skip to content

Commit

Permalink
feat: Add SkipDelay to delay skipping a segment (#19)
Browse files Browse the repository at this point in the history
* feat: Add SkipDelay to delay skipping a segment

* docs: Update flag documentation

* fix: Improve SkipDelay shell completion suggestions
  • Loading branch information
jvpernis authored Sep 9, 2023
1 parent 7ea2eea commit 842b4c6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/castsponsorskip.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ castsponsorskip [flags]
-i, --network-interface string Network interface to use for multicast dns discovery. (default all interfaces)
--paused-interval duration Interval to scan paused devices (default 1m0s)
--playing-interval duration Interval to scan playing devices (default 500ms)
--skip-delay duration Delay skipping the start of a segment
-v, --version version for castsponsorskip
--youtube-api-key string YouTube API key for fallback video identification (required on some Chromecast devices).
```
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Reset() {
DiscoverInterval: 5 * time.Minute,
PausedInterval: time.Minute,
PlayingInterval: 500 * time.Millisecond,
SkipDelay: 0,

NetworkInterface: "",

Expand All @@ -41,6 +42,7 @@ type Config struct {
DiscoverInterval time.Duration `mapstructure:"discover-interval"`
PausedInterval time.Duration `mapstructure:"paused-interval"`
PlayingInterval time.Duration `mapstructure:"playing-interval"`
SkipDelay time.Duration `mapstructure:"skip-delay"`

NetworkInterface string `mapstructure:"network-interface"`

Expand All @@ -58,6 +60,7 @@ func (c *Config) RegisterFlags(cmd *cobra.Command) {
c.RegisterDiscoverInterval(cmd)
c.RegisterPausedInterval(cmd)
c.RegisterPlayingInterval(cmd)
c.RegisterSkipDelay(cmd)
c.RegisterCategories(cmd)
c.RegisterActionTypes(cmd)
c.RegisterYouTubeAPIKey(cmd)
Expand Down
13 changes: 13 additions & 0 deletions internal/config/intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ func (c *Config) RegisterPlayingInterval(cmd *cobra.Command) {
}
}
}

func (c *Config) RegisterSkipDelay(cmd *cobra.Command) {
key := "skip-delay"
cmd.PersistentFlags().Duration(key, Default.SkipDelay, "Delay skipping the start of a segment")
if err := c.viper.BindPFlag(key, cmd.PersistentFlags().Lookup(key)); err != nil {
panic(err)
}
if err := cmd.RegisterFlagCompletionFunc(key, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"500ms", "1s", "2s", "3s", "5s", "10s"}, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveKeepOrder
}); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (d *Device) tick() error {
}

for i, segment := range d.segments {
if segment.Segment[0] <= castMedia.CurrentTime && castMedia.CurrentTime < segment.Segment[1]-1 {
if (segment.Segment[0] + float32(config.Default.SkipDelay.Seconds())) <= castMedia.CurrentTime && castMedia.CurrentTime < segment.Segment[1]-1 {
d.handleSegment(castMedia, castVol, segment, i)
}
}
Expand Down

0 comments on commit 842b4c6

Please sign in to comment.