]> njoseph.me Git - nimcoon.git/blobdiff - src/lib.nim
Use aria2c download manager if available
[nimcoon.git] / src / lib.nim
index ccd1a39797f990c90c870f52d72bc72f179150ec..30334588040993ba0a5c1d5fb900048ad855205c 100644 (file)
@@ -27,9 +27,8 @@ type
   SelectionRange* = tuple[begin: int, until: int]
 
 
-# poEchoCmd can be added to options for debugging
 let
-  processOptions = {poStdErrToStdOut, poUsePath}
+  processOptions = {poStdErrToStdOut, poUsePath} # poEchoCmd can be added to options for debugging
   PEERTUBE_REGEX = re"videos\/watch\/[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}"
 
 
@@ -54,7 +53,7 @@ proc getYoutubePage*(searchQuery: string): string =
 
 
 proc getPeerTubeMagnetLink(url: string): string =
-  # Gets the magnet link of the best possible resolutino from PeerTube
+  ## Gets the magnet link of the best possible resolution from PeerTube
   let uuid = url.substr(find(url, PEERTUBE_REGEX) + "videos/watch/".len)
   let domainName = url.substr(8, find(url, '/', start=8) - 1)
   let apiURL = &"https://{domainName}/api/v1/videos/{uuid}"
@@ -74,7 +73,7 @@ func extractTitlesAndUrls*(html: string): SearchResults =
 proc presentVideoOptions*(searchResults: SearchResults) =
   eraseScreen()
   for index, (title, url) in searchResults:
-    styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
+    styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, "   ", url, "\n"
 
 
 func isPlaylist(url: string): bool =
@@ -157,7 +156,10 @@ proc directDownload*(url: string, musicOnly: bool) =
   let args =
     if musicOnly: buildMusicDownloadArgs(url)
     else: buildVideoDownloadArgs(url)
-  discard execShellCmd(&"youtube-dl {args.join(\" \")}")
+  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 =