Commit b40b7243 authored by Joseph Nuthalapati's avatar Joseph Nuthalapati

strformat everywhere! 馃コ

parent 9a160f06
Pipeline #100707134 passed with stage
in 52 seconds
......@@ -3,6 +3,7 @@ import httpClient
import os
import osproc
import sequtils, sugar
import strformat
import std/[terminal]
import strtabs
import strutils
......@@ -20,7 +21,7 @@ type SearchResult = tuple[title: string, url: string]
proc selectMediaPlayer(): string =
let availablePlayers = filterIt(supportedPlayers, execProcess("which " & it).len != 0)
if len(availablePlayers) == 0:
stderr.writeLine "Please install one of the supported media players: ", $supportedPlayers
stderr.writeLine &"Please install one of the supported media players: {supportedPlayers}"
raise newException(OSError, "No supported media player found")
else:
return availablePlayers[0]
......@@ -28,7 +29,7 @@ proc selectMediaPlayer(): string =
proc getYoutubePage(searchQuery: string): string =
let queryParam = encodeUrl(searchQuery)
let client = newHttpClient()
let response = get(client, "https://www.youtube.com/results?hl=en&search_query=" & queryParam)
let response = get(client, &"https://www.youtube.com/results?hl=en&search_query={queryParam}")
return $response.body
proc extractTitlesAndUrls(htmlFile: string): seq[SearchResult] =
......@@ -45,7 +46,7 @@ let input = paramStr(1)
let player = selectMediaPlayer()
if "https://www.youtube.com" in input:
discard execProcess(player & " " & input)
discard execProcess(&"{player} {input}")
quit(0)
let searchResults = extractTitlesAndUrls(getYoutubePage(input))
......@@ -58,4 +59,4 @@ let number: int = parseInt(readLine(stdin))
styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
# Play the video using the preferred/available media player
discard execProcess(player & " " & searchResults[number].url)
discard execProcess(&"{player} {searchResults[number].url}")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment