From: Joseph Nuthalapati Date: Thu, 4 Jun 2020 18:08:21 +0000 (+0530) Subject: Make all sequences immutable X-Git-Tag: 0.4.0~2 X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/commitdiff_plain/046c2cc3b1dc773cf9e1b92f2c4fb41e2d6d8eb0 Make all sequences immutable --- diff --git a/src/lib.nim b/src/lib.nim index 24aa930..6153992 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -58,14 +58,14 @@ func isPlaylist(url: string): bool = # 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": - let list_arg = url.split('&')[1] - args[0] = "https://www.youtube.com/playlist?" & list_arg - return args + let url = + # Playlists are only supported for MPV player + 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: "" + return filterIt([url, musicOnly, fullScreen], it != "") proc play*(player: string, options: Table[string, bool], url: string, title: string = "") = let args = buildPlayerArgs(url, options, player) @@ -78,19 +78,13 @@ proc play*(player: string, options: Table[string, bool], url: string, title: str func buildMusicDownloadArgs*(url: string): seq[string] = {.noSideEffect.}: - var args = @["--ignore-errors", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o"] let downloadLocation = &"'{expandTilde(musicDownloadDirectory)}/%(title)s.%(ext)s'" - args.add(downloadLocation) - args.add(url) - return args + return @["--ignore-errors", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", downloadLocation, url] func buildVideoDownloadArgs*(url: string): seq[string] = {.noSideEffect.}: - var args = @["-f", "best", "-o"] let downloadLocation = &"'{expandTilde(videoDownloadDirectory)}/%(title)s.%(ext)s'" - args.add(downloadLocation) - args.add(url) - return args + return @["-f", "best", "-o", downloadLocation, url] proc download*(args: openArray[string], title: string) = styledEcho "\n", fgGreen, "Downloading ", styleBright, fgMagenta, title