serve dlna: convert options to new style

This commit is contained in:
Nick Craig-Wood 2024-07-03 18:14:48 +01:00
parent 44cd2e07ca
commit eec95a164d
3 changed files with 37 additions and 30 deletions

View File

@ -128,7 +128,7 @@ func newServer(f fs.Fs, opt *dlnaflags.Options) (*server, error) {
} }
s := &server{ s := &server{
AnnounceInterval: opt.AnnounceInterval, AnnounceInterval: time.Duration(opt.AnnounceInterval),
FriendlyName: friendlyName, FriendlyName: friendlyName,
RootDeviceUUID: makeDeviceUUID(friendlyName), RootDeviceUUID: makeDeviceUUID(friendlyName),
Interfaces: interfaces, Interfaces: interfaces,

View File

@ -35,7 +35,7 @@ const (
) )
func startServer(t *testing.T, f fs.Fs) { func startServer(t *testing.T, f fs.Fs) {
opt := dlnaflags.DefaultOpt opt := dlnaflags.Opt
opt.ListenAddr = testBindAddress opt.ListenAddr = testBindAddress
var err error var err error
dlnaServer, err = newServer(f, &opt) dlnaServer, err = newServer(f, &opt)

View File

@ -4,8 +4,8 @@ package dlnaflags
import ( import (
"time" "time"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/fs/rc"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -24,39 +24,46 @@ logging of all UPNP traffic.
` `
// Options is the type for DLNA serving options. // OptionsInfo descripts the Options in use
type Options struct { var OptionsInfo = fs.Options{{
ListenAddr string Name: "addr",
FriendlyName string Default: ":7879",
LogTrace bool Help: "The ip:port or :port to bind the DLNA http server to",
InterfaceNames []string }, {
AnnounceInterval time.Duration Name: "name",
Default: "",
Help: "Name of DLNA server",
}, {
Name: "log_trace",
Default: false,
Help: "Enable trace logging of SOAP traffic",
}, {
Name: "interface",
Default: []string{},
Help: "The interface to use for SSDP (repeat as necessary)",
}, {
Name: "announce_interval",
Default: fs.Duration(12 * time.Minute),
Help: "The interval between SSDP announcements",
}}
func init() {
fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "dlna", Opt: &Opt, Options: OptionsInfo})
} }
// DefaultOpt contains the defaults options for DLNA serving. // Options is the type for DLNA serving options.
var DefaultOpt = Options{ type Options struct {
ListenAddr: ":7879", ListenAddr string `config:"addr"`
FriendlyName: "", FriendlyName string `config:"name"`
LogTrace: false, LogTrace bool `config:"log_trace"`
InterfaceNames: []string{}, InterfaceNames []string `config:"interface"`
AnnounceInterval: 12 * time.Minute, AnnounceInterval fs.Duration `config:"announce_interval"`
} }
// Opt contains the options for DLNA serving. // Opt contains the options for DLNA serving.
var ( var Opt Options
Opt = DefaultOpt
)
func addFlagsPrefix(flagSet *pflag.FlagSet, prefix string, Opt *Options) {
rc.AddOption("dlna", &Opt)
flags.StringVarP(flagSet, &Opt.ListenAddr, prefix+"addr", "", Opt.ListenAddr, "The ip:port or :port to bind the DLNA http server to", prefix)
flags.StringVarP(flagSet, &Opt.FriendlyName, prefix+"name", "", Opt.FriendlyName, "Name of DLNA server", prefix)
flags.BoolVarP(flagSet, &Opt.LogTrace, prefix+"log-trace", "", Opt.LogTrace, "Enable trace logging of SOAP traffic", prefix)
flags.StringArrayVarP(flagSet, &Opt.InterfaceNames, prefix+"interface", "", Opt.InterfaceNames, "The interface to use for SSDP (repeat as necessary)", prefix)
flags.DurationVarP(flagSet, &Opt.AnnounceInterval, prefix+"announce-interval", "", Opt.AnnounceInterval, "The interval between SSDP announcements", prefix)
}
// AddFlags add the command line flags for DLNA serving. // AddFlags add the command line flags for DLNA serving.
func AddFlags(flagSet *pflag.FlagSet) { func AddFlags(flagSet *pflag.FlagSet) {
addFlagsPrefix(flagSet, "", &Opt) flags.AddFlagsFromOptions(flagSet, "", OptionsInfo)
} }