]> njoseph.me Git - nimcoon.git/commitdiff
Add option to download video
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 27 Mar 2020 07:23:35 +0000 (12:53 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 27 Mar 2020 07:23:35 +0000 (12:53 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
README.md
TODO.org
src/nimcoon.nim

index d5d51b6fb87dc53afd41207db10edbfe7a0d0e76..4b4bb32b2330993d40dd9c49684b88e754e2430c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ only the standard library.
 - [x] Play direct links from YouTube and PeerTube
 - [x] Stream video from magnet links
 - [x] Download music
-- [ ] Download video
+- [x] Download video
 - [ ] Configuration options
 
 ## Installation
index 6851e8eb7ec80c2f8b83ab02b00db893b3267048..54886302ec98351e82a1db0a41ef57bebd32bfbe 100644 (file)
--- a/TODO.org
+++ b/TODO.org
@@ -1,14 +1,14 @@
-* Task list [6/11]
+* Task list [7/11]
 - [X] Pretty colors in terminal
 - [X] Get rid of temp file or make one temp file per user
 - [X] Preferences should go into a config file
 - [X] Create a proper CLI
 - [X] PeerTube support (only direct download, because webtorrent seeds are too slow)
 - [X] Find a better name. clitube is an SEO disaster
+- [X] Option to download audio/video
 - [ ] Spawn video player and quit immediately
 - [ ] SoundCloud support? Search and play music
 - [ ] LRU cache of content so that frequently-played content doesn't use BW
-- [ ] Option to download audio/video
 - [ ] Better CLI using curses - select with arrows and press enter
-      - illwill library can be used
-      - see nim-mod project as an example
+  - illwill library can be used
+  - see nim-mod project as an example
index 2db5ece023a706ac3312e2a73419cdf22282b355..2ddafc94d4384968048b25f2665ea83eb7d413bd 100644 (file)
@@ -76,10 +76,20 @@ proc main() =
       args.add(searchResults[number].url)
       return args
 
+  func buildVideoDownloadArgs(number: int): seq[string] =
+    {.noSideEffect.}:
+      var args = @["-f", "best", "-o"]
+      let downloadLocation = &"'{expandTilde(videoDownloadDirectory)}/%(title)s.%(ext)s'"
+      args.add(downloadLocation)
+      args.add(searchResults[number].url)
+      return args
+
   proc handleUserInput(number: int) =
     if options["download"]:
       if options["musicOnly"]:
         download(buildMusicDownloadArgs(number), searchResults[number].title)
+      else:
+        download(buildVideoDownloadArgs(number), searchResults[number].title)
     else:
       play(player, buildPlayerArgs(number), searchResults[number].title)