-proc play*(player: string, args: openArray[string], title: string) =
- styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, title
+func isPlaylist(url: string): bool =
+ # Only YouTube playlists are supported for now
+ "www.youtube.com" in url and "&list=" in url
+
+# This is a pure function with no side effects
+func buildPlayerArgs(url: string, options: Table[string, bool], player: string): seq[string] =
+ var args = @[url]
+ if options["musicOnly"]: args.add("--no-video")
+ if options["fullScreen"]: args.add("--fullscreen")
+ # Playlists are only supported for MPV player
+ if isPlaylist(url) and player == "mpv":
+ args.add("--ytdl-raw-options=\"yes-playlist=\"")
+ return args
+
+proc play*(player: string, options: Table[string, bool], url: string, title: string = "") =
+ let args = buildPlayerArgs(url, options, player)
+ if title != "":
+ styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, title