@@ -153,39 +153,110 @@ func UPnPServerCompletion(_ *cobra.Command, args []string, toComplete string) ([
153153}
154154
155155// upnpIndexConfigCmd is the parent for index config subcommands.
156- var upnpIndexConfigCmd = & cobra.Command {
157- Use : "index " ,
158- Short : "Configure UPnP search index settings " ,
159- Long : `Configure settings for the UPnP search index, including the container path to index .` ,
156+ var upnpContainerConfigCmd = & cobra.Command {
157+ Use : "container " ,
158+ Short : "Configure UPnP container paths " ,
159+ Long : `Configure container paths for browsing and indexing .` ,
160160 Run : func (cmd * cobra.Command , _ []string ) {
161161 _ = cmd .Help ()
162162 },
163163}
164164
165- // upnpIndexContainerCmd shows or sets the index container path.
166- var upnpIndexContainerCmd = & cobra.Command {
167- Use : "container [path]" ,
165+ // upnpContainerBrowseCmd shows or sets the browse container path.
166+ var upnpContainerBrowseCmd = & cobra.Command {
167+ Use : "browse [path]" ,
168+ Short : "Show or set the container path for browsing" ,
169+ Long : `Show the current container path for browsing, or set a new one.
170+
171+ The browse container determines the starting point when browsing your UPnP library.
172+ When set, you won't see parent containers or other servers - the browse container
173+ becomes your "root" for navigation.
174+
175+ Use "/" as separator for nested paths.
176+
177+ Without arguments, displays the current setting.
178+ With a path, sets that as the starting container for browsing.
179+
180+ Examples:
181+ kefw2 config upnp container browse # Show current
182+ kefw2 config upnp container browse "Music" # Start from Music folder
183+ kefw2 config upnp container browse "Music/Hilli's Music" # Start from specific folder
184+ kefw2 config upnp container browse "" # Clear (show all servers)` ,
185+ Run : func (_ * cobra.Command , args []string ) {
186+ if len (args ) == 0 {
187+ // Show current setting
188+ containerPath := viper .GetString ("upnp.browse_container" )
189+ if containerPath == "" {
190+ contentPrinter .Println ("No browse container configured (will show all servers)." )
191+ contentPrinter .Println ("Use 'kefw2 config upnp container browse <path>' to set one." )
192+ return
193+ }
194+ headerPrinter .Print ("Browse container: " )
195+ contentPrinter .Println (containerPath )
196+ return
197+ }
198+
199+ // Set new container path
200+ containerPath := args [0 ]
201+
202+ // If a path is provided, validate it exists
203+ if containerPath != "" {
204+ serverPath := viper .GetString ("upnp.default_server_path" )
205+ if serverPath == "" {
206+ exitWithError ("No default UPnP server configured. Set one first with: kefw2 config upnp server default <name>" )
207+ }
208+
209+ client := kefw2 .NewAirableClient (currentSpeaker )
210+ _ , resolvedName , err := kefw2 .FindContainerByPath (client , serverPath , containerPath )
211+ if err != nil {
212+ exitWithError ("Invalid container path: %v" , err )
213+ }
214+ // Use the resolved path (with proper casing)
215+ containerPath = resolvedName
216+ }
217+
218+ // Save to config
219+ viper .Set ("upnp.browse_container" , containerPath )
220+ err := viper .WriteConfig ()
221+ exitOnError (err , "Error saving config" )
222+
223+ if containerPath == "" {
224+ taskConpletedPrinter .Println ("Browse container cleared (will show all servers)" )
225+ } else {
226+ taskConpletedPrinter .Print ("Browse container set: " )
227+ contentPrinter .Println (containerPath )
228+ }
229+ },
230+ ValidArgsFunction : UPnPContainerCompletion ,
231+ }
232+
233+ // upnpContainerIndexCmd shows or sets the index container path.
234+ var upnpContainerIndexCmd = & cobra.Command {
235+ Use : "index [path]" ,
168236 Short : "Show or set the container path for indexing" ,
169237 Long : `Show the current container path for indexing, or set a new one.
170238
171239The container path determines which folder to start indexing from.
172240Use "/" as separator for nested paths.
173241
242+ TIP: For best results, use a "By Folder" path (e.g., "Music/Hilli's Music/By Folder").
243+ This indexes your actual folder structure without any reorganization by the media server.
244+
174245Without arguments, displays the current setting.
175246With a path, sets that as the default container to index.
176247
177248Examples:
178- kefw2 config upnp index container # Show current
179- kefw2 config upnp index container "Music" # Index Music folder
180- kefw2 config upnp index container "Music/Hilli's Music/By Folder" # Index specific folder
181- kefw2 config upnp index container "" # Clear (index entire server)` ,
249+ kefw2 config upnp container index # Show current
250+ kefw2 config upnp container index "Music" # Index Music folder
251+ kefw2 config upnp container index "Music/Hilli's Music/By Folder" # Index by folder (recommended)
252+ kefw2 config upnp container index "" # Clear (index entire server)` ,
182253 Run : func (_ * cobra.Command , args []string ) {
183254 if len (args ) == 0 {
184255 // Show current setting
185256 containerPath := viper .GetString ("upnp.index_container" )
186257 if containerPath == "" {
187258 contentPrinter .Println ("No index container configured (will index entire server)." )
188- contentPrinter .Println ("Use 'kefw2 config upnp index container <path>' to set one." )
259+ contentPrinter .Println ("Use 'kefw2 config upnp container index <path>' to set one." )
189260 return
190261 }
191262 headerPrinter .Print ("Index container: " )
@@ -204,12 +275,12 @@ Examples:
204275 }
205276
206277 client := kefw2 .NewAirableClient (currentSpeaker )
207- _ , resolvedPath , err := findContainerByPath (client , serverPath , containerPath )
278+ _ , resolvedName , err := kefw2 . FindContainerByPath (client , serverPath , containerPath )
208279 if err != nil {
209280 exitWithError ("Invalid container path: %v" , err )
210281 }
211282 // Use the resolved path (with proper casing)
212- containerPath = resolvedPath
283+ containerPath = resolvedName
213284 }
214285
215286 // Save to config
@@ -256,7 +327,7 @@ func UPnPContainerCompletion(_ *cobra.Command, args []string, toComplete string)
256327 }
257328
258329 // Get containers at the parent path
259- containers , err := listContainersAtPath (client , serverPath , parentPath )
330+ containers , err := kefw2 . ListContainersAtPath (client , serverPath , parentPath )
260331 if err != nil {
261332 return nil , cobra .ShellCompDirectiveNoFileComp
262333 }
@@ -285,6 +356,7 @@ func init() {
285356 upnpConfigCmd .AddCommand (upnpServerConfigCmd )
286357 upnpServerConfigCmd .AddCommand (upnpServerDefaultCmd )
287358 upnpServerConfigCmd .AddCommand (upnpServerListCmd )
288- upnpConfigCmd .AddCommand (upnpIndexConfigCmd )
289- upnpIndexConfigCmd .AddCommand (upnpIndexContainerCmd )
359+ upnpConfigCmd .AddCommand (upnpContainerConfigCmd )
360+ upnpContainerConfigCmd .AddCommand (upnpContainerBrowseCmd )
361+ upnpContainerConfigCmd .AddCommand (upnpContainerIndexCmd )
290362}
0 commit comments