+ rewriteInvidiousToYouTube(urlLongen(stripZshEscaping(url)))
+
+
+proc directPlay*(url: string, player: string, options: Table[string, bool]) =
+ let url =
+ if find(url, PEERTUBE_REGEX) != -1 and isInstalled("webtorrent"):
+ getPeerTubeMagnetLink(url)
+ else: url
+ if url.startswith("magnet:") or url.endswith(".torrent"):
+ if options["musicOnly"]:
+ # TODO Replace with WebTorrent once it supports media player options
+ discard execShellCmd(&"peerflix '{url}' -a --{player} -- --no-video")
+ else:
+ # WebTorrent is so much faster!
+ discard execProcess("webtorrent", args=[url, &"--{player}"], options=processOptions)
+ else:
+ play(player, options, url)
+
+
+proc directDownload*(url: string, musicOnly: bool) =
+ let args =
+ if musicOnly: buildMusicDownloadArgs(url)
+ else: buildVideoDownloadArgs(url)
+ if isInstalled("aria2c"):
+ discard execShellCmd(&"youtube-dl {args.join(\" \")} --external-downloader aria2c --external-downloader-args '-x 16 -s 16 -k 2M'")
+ else:
+ discard execShellCmd(&"youtube-dl {args.join(\" \")}")
+
+
+proc offerSelection(searchResults: SearchResults, options: Table[string, bool], selectionRange: SelectionRange): string =
+ if options["feelingLucky"]: "0"
+ else:
+ presentVideoOptions(searchResults[selectionRange.begin .. selectionRange.until])
+ stdout.styledWrite(fgYellow, "Choose video number: ")
+ readLine(stdin)
+
+
+proc handleUserInput(searchResult: SearchResult, options: Table[string, bool], player: string) =
+ if options["download"]:
+ if options["musicOnly"]:
+ download(buildMusicDownloadArgs(searchResult.url), searchResult.title)
+ else:
+ download(buildVideoDownloadArgs(searchResult.url), searchResult.title)
+ else:
+ play(player, options, searchResult.url, searchResult.title)
+
+
+proc present*(searchResults: SearchResults, options: Table[string, bool], selectionRange: SelectionRange, player: string) =
+ ##[ Continuously present options till the user quits the application
+
+ selectionRange: Currently available range to choose from depending on pagination
+ ]##
+
+ let userInput = offerSelection(searchResults, options, selectionRange)