yt-cli


Logs | Files | README | README | LICENSE | GitLab


1
commit a062592d702d013e87caf2392dc0e4d924b9a2ad
2
Author: Connor Etherington <[email protected]>
3
Date:   Fri May 26 06:25:11 2023 +0200
4
5
    Auto-Commit Update - 20230526
6
---
7
 usr/lib/node_modules/yt-cli/lib/yt-cli.js | 37 +++++++++++++++++--------------
8
 1 file changed, 20 insertions(+), 17 deletions(-)
9
10
diff --git a/usr/lib/node_modules/yt-cli/lib/yt-cli.js b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
11
index 7d75c0a..f894667 100755
12
--- a/usr/lib/node_modules/yt-cli/lib/yt-cli.js
13
+++ b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
14
@@ -68,6 +68,8 @@ const main = async (search) => {
15
 
16
   if(!response.searchTerm) process.exit(0);
17
 
18
+  let help, auto, download, to;
19
+
20
   if(search) {
21
 
22
     if(search.match(/^-h\s*?/) || search.match(/\s*?-h\s*?/) ||
23
@@ -75,9 +77,9 @@ const main = async (search) => {
24
 
25
       await sh(`echo -e "\n  Usage: yt-cli [options] [search-term]\n\n    -a | --auto     : auto select first result\n    -d | --download : download selected video to \${HOME}/yt-cli\n    -t | --to       : download selected video to specified directory\n    -h | --help     : show this help message\n\n"`);
26
 
27
-      var help = true;
28
+      help = true;
29
     } else {
30
-      var help = false;
31
+      help = false;
32
     }
33
 
34
     if(search.match(/^-a\s*?/) || search.match(/\s*?-a\s*?/) ||
35
@@ -87,9 +89,9 @@ const main = async (search) => {
36
         .replace(/\s?-a\s?$/, '') .replace(/\^--auto\s?/, '')
37
         .replace(/\s?--auto\s?$/, '');
38
 
39
-      var auto = true;
40
+      auto = true;
41
     } else {
42
-      var auto = false;
43
+      auto = false;
44
     }
45
 
46
     if(search.match(/^-d\s*?/) || search.match(/\s*?-d\s*?/) ||
47
@@ -99,23 +101,23 @@ const main = async (search) => {
48
         .replace(/\s?-d\s?$/, '') .replace(/\^--download\s?/, '')
49
         .replace(/\s?--download\s?$/, '');
50
 
51
-      var download = true;
52
+      download = true;
53
     } else {
54
-      var download = false;
55
+      download = false;
56
     }
57
 
58
     if(search.match(/^-dt\s*?/) || search.match(/\s*?-dt\s*?/)) {
59
 
60
-      var to = response.searchTerm.split(/-dt\s?/)[1] ? response.searchTerm.split(/-td\s?/)[1].split(' ')[0] : false;
61
+      to = response.searchTerm.split(/-dt\s?/)[1] ? response.searchTerm.split(/-td\s?/)[1].split(' ')[0] : false;
62
       response.searchTerm = search.replace(/^-dt\s?/, '').replace(/\s?-dt\s?$/, '');
63
 
64
-      var download = true;
65
+      download = true;
66
     }
67
 
68
     if(search.match(/^-t\s*?/) || search.match(/\s*?-t\s*?/) ||
69
       search.match(/^--to\s*?/) || search.match(/\s*?--to\s*?/)) {
70
 
71
-      var to = response.searchTerm.split(/-t\s?/)[1] ? response.searchTerm.split(/-t\s?/)[1].split(' ')[0] :
72
+      to = response.searchTerm.split(/-t\s?/)[1] ? response.searchTerm.split(/-t\s?/)[1].split(' ')[0] :
73
         response.searchTerm.split(/--to\s?/)[1] ? response.searchTerm.split(/--to\s?/)[1].split(' ')[0] : false;
74
 
75
       if(to === false) {
76
@@ -132,14 +134,14 @@ const main = async (search) => {
77
       }
78
 
79
     } else {
80
-      var to = false;
81
+      to = false;
82
     }
83
 
84
   } else {
85
-    var help = false;
86
-    var auto = false;
87
-    var download = false;
88
-    var to = false;
89
+    help = false;
90
+    auto = false;
91
+    download = false;
92
+    to = false;
93
   }
94
 
95
   if(help) process.exit(0);
96
@@ -161,9 +163,10 @@ const main = async (search) => {
97
   const selectedVideo = data[response2.video];
98
 
99
   if(download) {
100
-    if(!fs.existsSync(os.homedir() + '/yt-cli')) fs.mkdirSync(os.homedir() + '/yt-cli');
101
-    await dV(selectedVideo.url, os.homedir() + '/yt-cli/' + selectedVideo.title + '.mp4');
102
-    console.log(`\n[+] `.green + 'Video saved to \'' + (os.homedir() + '/yt-cli/' + selectedVideo.title + '.mp4\'').cyan);
103
+    if(!to) to = os.homedir() + '/yt-cli';
104
+    if(!fs.existsSync(to)) fs.mkdirSync(to);
105
+    await dV(selectedVideo.url, to + '/' + selectedVideo.title + '.mp4');
106
+    console.log(`\n[+] `.green + 'Video saved to \'' + (to + '/' + selectedVideo.title + '.mp4\'').cyan);
107
   } else sh(`mpv ${selectedVideo.url}`);
108
 
109
 };