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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ Or
XTREAM_PASSWORD: xtream_password
XTREAM_BASE_URL: "http://example.com:1234"
USER: test
PASSWORD: testpassword
PASSWORD: testpassword
# REGEX filters
GROUP_REGEX: 'SPORTS|NEWS'
CHANNEL_REGEX: 'HD'
```

### Start
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ var rootCmd = &cobra.Command{
M3UFileName: viper.GetString("m3u-file-name"),
CustomEndpoint: viper.GetString("custom-endpoint"),
XtreamGenerateApiGet: viper.GetBool("xtream-api-get"),
GroupRegex: viper.GetString("group-regex"),
ChannelRegex: viper.GetString("channel-regex"),
}

if conf.AdvertisedPort == 0 {
Expand Down Expand Up @@ -132,6 +134,8 @@ func init() {
rootCmd.Flags().String("xtream-base-url", "", "Xtream-code base url e.g(http://expample.tv:8080)")
rootCmd.Flags().Int("m3u-cache-expiration", 1, "M3U cache expiration in hour")
rootCmd.Flags().BoolP("xtream-api-get", "", false, "Generate get.php from xtream API instead of get.php original endpoint")
rootCmd.Flags().String("group-regex", "", "Regex applied to groups for filtering")
rootCmd.Flags().String("channel-regex", "", "Regex applied to channel names for filtering")

if e := viper.BindPFlags(rootCmd.Flags()); e != nil {
log.Fatal("error binding PFlags to viper")
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ services:
#will be used for m3u and xtream auth poxy
USER: test
PASSWORD: testpassword

# REGEX filters
GROUP_REGEX: 'SPORTS|NEWS'
CHANNEL_REGEX: 'HD'
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ type ProxyConfig struct {
AdvertisedPort int
HTTPS bool
User, Password CredentialString
GroupRegex string
ChannelRegex string
}
25 changes: 25 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path"
"path/filepath"
"strings"
"regexp"

"github.com/gin-contrib/cors"
"github.com/jamesnetherton/m3u"
Expand Down Expand Up @@ -107,7 +108,31 @@ func (c *Config) marshallInto(into *os.File, xtream bool) error {

ret := 0
into.WriteString("#EXTM3U\n") // nolint: errcheck

re_group := regexp.MustCompile(c.GroupRegex)
re_channel := regexp.MustCompile(c.ChannelRegex)

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

// Group regex
if c.GroupRegex != "" {
for i := range track.Tags {
name := track.Tags[i].Name
value := track.Tags[i].Value
if name == "group-title" && !re_group.MatchString(value) {
continue TRACKS_LOOP
}
}
}

// Channel regex
if c.ChannelRegex != "" {
if !re_channel.MatchString(track.Name) {
continue TRACKS_LOOP
}
}

var buffer bytes.Buffer

buffer.WriteString("#EXTINF:") // nolint: errcheck
Expand Down