Skip to content

Commit

Permalink
feat: Make DLNA port configurable stashapp#4760
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Pedrazas <[email protected]>
  • Loading branch information
ipedrazas committed May 14, 2024
1 parent ca5febc commit 8bccf93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/dlna/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Config interface {
GetDLNAServerName() string
GetDLNADefaultIPWhitelist() []string
GetVideoSortOrder() string
GetDLNAPortAsString() string
}

type Service struct {
Expand Down Expand Up @@ -138,7 +139,7 @@ func (s *Service) init() error {
var dmsConfig = &dmsConfig{
Path: "",
IfNames: s.config.GetDLNADefaultIPWhitelist(),
Http: ":1338",
Http: s.config.GetDLNAPortAsString(),
FriendlyName: friendlyName,
LogHeaders: false,
NotifyInterval: 30 * time.Second,
Expand Down Expand Up @@ -241,7 +242,7 @@ func (s *Service) Start(duration *time.Duration) error {
}

go func() {
logger.Info("Starting DLNA")
logger.Info("Starting DLNA " + s.server.HTTPConn.Addr().String())
if err := s.server.Serve(); err != nil {
logger.Error(err)
}
Expand Down
19 changes: 19 additions & 0 deletions internal/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"

"sync"
Expand Down Expand Up @@ -237,6 +238,9 @@ const (
DLNAVideoSortOrder = "dlna.video_sort_order"
dlnaVideoSortOrderDefault = "title"

DLNAPort = "dlna.port"
DLNAPortDefault = 1338

// Logging options
LogFile = "logFile"
LogOut = "logOut"
Expand Down Expand Up @@ -1477,6 +1481,21 @@ func (i *Config) GetDLNAInterfaces() []string {
return i.getStringSlice(DLNAInterfaces)
}

// GetDLNAPort returns the port to run the DLNA server on. If empty, 1338
// will be used.
func (i *Config) GetDLNAPort() int {
ret := i.getInt(DLNAPort)
if ret == 0 {
ret = DLNAPortDefault
}
return ret
}

// GetDLNAPortAsString returns the port to run the DLNA server on as a string.
func (i *Config) GetDLNAPortAsString() string {
return ":" + strconv.Itoa(i.GetDLNAPort())
}

// GetVideoSortOrder returns the sort order to display videos. If
// empty, videos will be sorted by titles.
func (i *Config) GetVideoSortOrder() string {
Expand Down
1 change: 1 addition & 0 deletions internal/manager/config/config_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestConcurrentConfigAccess(t *testing.T) {
i.Set(DLNADefaultEnabled, i.GetDLNADefaultEnabled())
i.Set(DLNADefaultIPWhitelist, i.GetDLNADefaultIPWhitelist())
i.Set(DLNAInterfaces, i.GetDLNAInterfaces())
i.Set(DLNAPort, i.GetDLNAPort())
i.Set(LogFile, i.GetLogFile())
i.Set(LogOut, i.GetLogOut())
i.Set(LogLevel, i.GetLogLevel())
Expand Down

0 comments on commit 8bccf93

Please sign in to comment.