Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
SkipSponsors bool `yaml:"skip-sponsors"`
Categories []string `yaml:"categories"`
ActionTypes []string `yaml:"action-types"`
AllowChannels []string `yaml:"allow-channels"`

YouTubeAPIKey string `yaml:"youtube-api-key"`
MuteAds bool `yaml:"mute-ads"`
Expand All @@ -47,6 +48,7 @@ func New() *Config {
SkipSponsors: true,
Categories: []string{"sponsor"},
ActionTypes: []string{"skip", "mute"},
AllowChannels: []string{},

MuteAds: true,
}
Expand All @@ -72,6 +74,7 @@ func RegisterFlags(cmd *cobra.Command) {
fs.Bool(names.FlagSkipSponsors, c.SkipSponsors, "Skip sponsored segments with SponsorBlock")
fs.StringSliceP(names.FlagCategories, "c", c.Categories, "Comma-separated list of SponsorBlock categories to skip")
fs.StringSlice(names.FlagActionTypes, c.ActionTypes, "SponsorBlock action types to handle. Shorter segments that overlap with content can be muted instead of skipped.")
fs.StringSliceP(names.FlagAllowChannels, "a", c.AllowChannels, "Comma-separated list of channel names or IDs to allowlist (will not skip sponsors)")

fs.String(names.FlagYouTubeAPIKey, c.YouTubeAPIKey, "YouTube API key for fallback video identification (required on some Chromecast devices).")
fs.Bool(names.FlagMuteAds, c.MuteAds, "Mutes the device while an ad is playing")
Expand Down
6 changes: 5 additions & 1 deletion internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
}

// Load envs
if err := k.Load(env.ProviderWithValue(EnvPrefix, ".", func(k string, v string) (string, any) {

Check warning on line 84 in internal/config/load.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Group together these consecutive parameters of the same type.

See more on https://sonarcloud.io/project/issues?id=gabe565_CastSponsorSkip&issues=AZ0fUqZnGCUUzfFYUlrV&open=AZ0fUqZnGCUUzfFYUlrV&pullRequest=189
k = strings.ReplaceAll(strings.ToLower(strings.TrimPrefix(k, EnvPrefix)), "_", "-")

switch k {
case names.FlagDevices, names.FlagCategories, names.FlagActionTypes:
case names.FlagDevices, names.FlagCategories, names.FlagActionTypes, names.FlagAllowChannels:
return k, strings.Split(v, ",")
default:
return k, v
Expand Down Expand Up @@ -120,6 +120,10 @@
c.ActionTypes[i] = strings.TrimSpace(actionType)
}

for i, allowChannel := range c.AllowChannels {
c.AllowChannels[i] = strings.TrimSpace(allowChannel)
}

if len(c.DeviceAddrStrs) != 0 {
c.DeviceAddrs = make([]castdns.CastEntry, 0, len(c.DeviceAddrStrs))
for _, device := range c.DeviceAddrStrs {
Expand Down
1 change: 1 addition & 0 deletions internal/config/names/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
FlagSkipSponsors = "skip-sponsors"
FlagCategories = "categories"
FlagActionTypes = "action-types"
FlagAllowChannels = "allow-channels"

FlagYouTubeAPIKey = "youtube-api-key"
FlagMuteAds = "mute-ads"
Expand Down
18 changes: 15 additions & 3 deletions internal/device/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"runtime/debug"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -218,9 +219,20 @@ func (d *Device) tick() error {
break
}

for i, segment := range d.segments {
if (segment.Segment[0]+float32(d.config.SkipDelay.Seconds())) <= castMedia.CurrentTime && castMedia.CurrentTime < segment.Segment[1]-1 {
d.handleSegment(castMedia, castVol, segment, i)
// Skip processing if the channel is in the allowlist
allowed := false
for _, allowChannel := range d.config.AllowChannels {
if strings.EqualFold(d.meta.CurrArtist, allowChannel) {
allowed = true
break
}
}

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

Expand Down