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
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ var rootCmd = &cobra.Command{
}
}

filters := map[string](bool){}
for _, groupName := range viper.GetStringSlice("filter-groups") {
filters[groupName] = true
}

conf := &config.ProxyConfig{
HostConfig: &config.HostConfiguration{
Hostname: viper.GetString("hostname"),
Expand All @@ -83,6 +88,7 @@ var rootCmd = &cobra.Command{
HTTPS: viper.GetBool("https"),
M3UFileName: viper.GetString("m3u-file-name"),
CustomEndpoint: viper.GetString("custom-endpoint"),
FilterGroups: filters,
}

server, err := server.NewServer(conf)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ type ProxyConfig struct {
RemoteURL *url.URL
HTTPS bool
User, Password CredentialString
FilterGroups map[string](bool)
}
15 changes: 15 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,24 @@ func (c *Config) playlistInitialization() error {
// MarshallInto a *bufio.Writer a Playlist.
func (c *Config) marshallInto(into *os.File, xtream bool) error {
into.WriteString("#EXTM3U\n") // nolint: errcheck

TRACKS_LOOP:
for _, track := range c.playlist.Tracks {

// Groups filtering
if len(c.FilterGroups) > 0 {
for i := range track.Tags {
name := track.Tags[i].Name
value := track.Tags[i].Value
if name == "group-title" && !c.FilterGroups[value] {
continue TRACKS_LOOP
}
}
}

into.WriteString("#EXTINF:") // nolint: errcheck
into.WriteString(fmt.Sprintf("%d ", track.Length)) // nolint: errcheck

for i := range track.Tags {
if i == len(track.Tags)-1 {
into.WriteString(fmt.Sprintf("%s=%q", track.Tags[i].Name, track.Tags[i].Value)) // nolint: errcheck
Expand Down