-proc play*(player: string, args: openArray[string], title: string) =
- styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, title
+
+func isPlaylist(url: string): bool =
+ ##[ Identifies if video is part of a playlist.
+ Only YouTube playlists are supported for now. ]##
+ "www.youtube.com" in url and "&list=" in url
+
+
+func buildPlayerArgs(url: string, options: Table[string, bool], player: string): seq[string] =
+ let url =
+ # Playlists are only supported by MPV player. VLC needs a plugin.
+ if isPlaylist(url) and player == "mpv":
+ "https://www.youtube.com/playlist?" & url.split('&')[1]
+ else: url
+ let musicOnly = if options["musicOnly"]: "--no-video" else: ""
+ let fullScreen = if options["fullScreen"]: "--fullscreen" else: ""
+ filterIt([url, musicOnly, fullScreen], it != "")
+
+
+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