Skip to content

Commit

Permalink
Move ffmpeg validation to main
Browse files Browse the repository at this point in the history
  • Loading branch information
csfrancis committed Sep 24, 2024
1 parent 71c7e35 commit 8f53150
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"os/exec"
"os/signal"
"regexp"
"strings"
Expand Down Expand Up @@ -78,6 +79,12 @@ func main() {

log.Infof("starting proxytv with config file: %s", *configPath)

if config.UseFFMPEG {
if _, err := exec.LookPath("ffmpeg"); err != nil {
log.Fatalf("ffmpeg is enabled but not found in PATH: %v", err)
}
}

provider, err := proxytv.NewProvider(config)
if err != nil {
log.Fatalf("failed to create provider: %v", err)
Expand Down
14 changes: 5 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package proxytv
import (
"fmt"
"os"
"os/exec"
"regexp"
"time"

Expand All @@ -30,8 +29,9 @@ type Config struct {
ListenAddress string `yaml:"listenAddress,omitempty" default:":6078"`
ServerAddress string `yaml:"serverAddress"`

UseFFMPEG bool `yaml:"ffmpeg,omitempty" default:"true"`
MaxStreams int `yaml:"maxStreams,omitempty" default:"1"`
UseFFMPEG bool
UseFFMPEGPtr *bool `yaml:"ffmpeg,omitempty" default:"true"`
MaxStreams int `yaml:"maxStreams,omitempty" default:"1"`

RefreshInterval time.Duration
RefreshIntervalStr string `yaml:"refreshInterval,omitempty" default:"12h"`
Expand All @@ -57,6 +57,8 @@ func LoadConfig(path string) (*Config, error) {
return nil, err
}

config.UseFFMPEG = *config.UseFFMPEGPtr

config.RefreshInterval, err = time.ParseDuration(config.RefreshIntervalStr)
if err != nil {
return nil, fmt.Errorf("invalid refreshInterval: %w", err)
Expand All @@ -82,12 +84,6 @@ func LoadConfig(path string) (*Config, error) {
return nil, fmt.Errorf("invalid epgUrl: %w", err)
}

if config.UseFFMPEG {
if _, err := exec.LookPath("ffmpeg"); err != nil {
return nil, fmt.Errorf("ffmpeg is enabled but not found in PATH: %w", err)
}
}

if err := config.compileFilterRegexps(); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ epgUrl: http://example.com/epg
listenAddress: localhost:8080
serverAddress: iptvserver:8080
refreshInterval: '2h'
ffmpeg: false
ffmpeg: true
maxStreams: 10
filters:
- filter: sports.*
Expand Down

0 comments on commit 8f53150

Please sign in to comment.