From: Joseph Nuthalapati Date: Sat, 2 Jan 2021 10:28:08 +0000 (+0530) Subject: Display title when feeling lucky X-Git-Tag: 0.8.1~1 X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/commitdiff_plain/d7f4645ccad8ae3f186f0428db3c7f0b48726b45 Display title when feeling lucky Signed-off-by: Joseph Nuthalapati --- diff --git a/src/lib.nim b/src/lib.nim index 25a8016..4dbbf8b 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -33,6 +33,10 @@ proc selectMediaPlayer*(): string = return availablePlayers[0] +proc printTitle(action: string, title: string) = + styledEcho "\n", fgGreen, &"{action} ", styleBright, fgMagenta, title + + ############### # URL CLEANUP # ############### @@ -68,7 +72,7 @@ func buildPlayerArgs(url: string, options: Table[string, bool], player: string): 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 + printTitle("Playing", title) if "--no-video" in args: discard execShellCmd(&"{player} {args.join(\" \")}") else: @@ -114,7 +118,7 @@ func buildDownloadArgs(url: string, options: Options): seq[string] = proc download*(args: openArray[string], title: string) = - styledEcho "\n", fgGreen, "Downloading ", styleBright, fgMagenta, title + printTitle("Downloading", title) discard execShellCmd(&"youtube-dl {args.join(\" \")}") @@ -127,14 +131,16 @@ proc directDownload*(url: string, options: Options) = proc luckyDownload*(searchQuery: string, options: Options) = let args = @[&"ytsearch:\"{searchQuery}\""] & buildDownloadArgs("", options) - styledEcho "\n", fgGreen, "Searching and downloading using youtube-dl" - discard execShellCmd(&"youtube-dl {args.join(\" \")}") + let title = execProcess(&"youtube-dl --get-title {args.join(\" \")}").split("\n")[0] + download(args, title) proc luckyPlay*(searchQuery: string, player: string, options: Options) = let args = @[&"ytsearch:\"{searchQuery}\""] & buildDownloadArgs("", options) - let output = execProcess(&"youtube-dl --get-url {args.join(\" \")}") - let url = output.split("\n")[0] - play(player, options, url) + let output = execProcess(&"youtube-dl --get-url --get-title {args.join(\" \")}").split("\n") + let + title = output[0] + url = &"\"{output[1]}\"" + play(player, options, url, title) ########### # OPTIONS #