yt-cli


Logs | Files | README | README | LICENSE | GitLab


1
commit 855ac4c0bfdecbd63812e1138de4dbd0d36cffc1
2
Author: Connor Etherington <[email protected]>
3
Date:   Fri May 26 08:20:15 2023 +0200
4
5
    Auto-Commit Update - 20230526
6
---
7
 PKGBUILD                                  |  2 +-
8
 usr/lib/node_modules/yt-cli/lib/yt-cli.js | 86 +++++++++++++++++--------------
9
 2 files changed, 48 insertions(+), 40 deletions(-)
10
11
diff --git a/PKGBUILD b/PKGBUILD
12
index ae7aa8c..4fe6f55 100644
13
--- a/PKGBUILD
14
+++ b/PKGBUILD
15
@@ -1,7 +1,7 @@
16
 # Maintainer: Connor Etherington <[email protected]>
17
 # ---
18
 pkgname=yt-cli
19
-pkgver=0.2.1
20
+pkgver=0.2.2
21
 pkgrel=1
22
 pkgdesc="An easy to use CLI YouTube client"
23
 arch=('any')
24
diff --git a/usr/lib/node_modules/yt-cli/lib/yt-cli.js b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
25
index f894667..284715b 100755
26
--- a/usr/lib/node_modules/yt-cli/lib/yt-cli.js
27
+++ b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
28
@@ -68,12 +68,19 @@ const main = async (search) => {
29
 
30
   if(!response.searchTerm) process.exit(0);
31
 
32
-  let help, auto, download, to;
33
+  let help = false,
34
+      to = false,
35
+      auto = false,
36
+      download = false;
37
 
38
   if(search) {
39
 
40
-    if(search.match(/^-h\s*?/) || search.match(/\s*?-h\s*?/) ||
41
-      search.match(/^--help\s*?/) || search.match(/\s*?--help\s*?/)) {
42
+    if(response.searchTerm.match(/-h\s*?/) || response.searchTerm.match(/--help\s*?/)) if(response.searchTerm.split(/--?h(elp)?\s?/)[0]
43
+      .replace(/--?to?\s/, '')
44
+      .replace(/--?a(uto)?\s?/, '')
45
+      .replace(/--?d(ownload)?\s?/, '')
46
+      .replace(/-dt\s?/, '')
47
+      .replace(/ /g, '') === '') {
48
 
49
       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"`);
50
 
51
@@ -82,61 +89,56 @@ const main = async (search) => {
52
       help = false;
53
     }
54
 
55
-    if(search.match(/^-a\s*?/) || search.match(/\s*?-a\s*?/) ||
56
-      search.match(/^--auto\s*?/) || search.match(/\s*?--auto\s*?/)) {
57
+    if(response.searchTerm.match(/-t\s*/) || response.searchTerm.match(/--to\s*/)) if(response.searchTerm.split(/--?to?\s/)[0]
58
+      .replace(/--?a(uto)?\s?/, '')
59
+      .replace(/--?d(ownload)?\s?/, '')
60
+      .replace(/-dt\s?/, '')
61
+      .replace(/ /g, '') === '') {
62
 
63
-      response.searchTerm = search.replace(/^-a\s?/, '')
64
-        .replace(/\s?-a\s?$/, '') .replace(/\^--auto\s?/, '')
65
-        .replace(/\s?--auto\s?$/, '');
66
+      to = response.searchTerm.split(/--?to?\s/)[1] ? response.searchTerm.split(/--?to?\s/)[1].split(' ')[0] : false;
67
+      response.searchTerm = response.searchTerm.replace(/--?to?\s/, '').replace(`${to}`, '').replace(/^\s+|\s+$/g, '');
68
 
69
-      auto = true;
70
     } else {
71
-      auto = false;
72
+      to = false;
73
     }
74
 
75
-    if(search.match(/^-d\s*?/) || search.match(/\s*?-d\s*?/) ||
76
-      search.match(/^--download\s*?/) || search.match(/\s*?--download\s*?/)) {
77
+    if(response.searchTerm.match(/-dt\s*/) || response.searchTerm.match(/--download-to\s*/)) if(response.searchTerm.split(/-dt\s/)[0]
78
+      .replace(/--?a(uto)?\s?/, '')
79
+      .replace(/--?d(ownload)?\s?/, '')
80
+      .replace(/ /g, '') === '') {
81
 
82
-      response.searchTerm = search.replace(/^-d\s?/, '')
83
-        .replace(/\s?-d\s?$/, '') .replace(/\^--download\s?/, '')
84
-        .replace(/\s?--download\s?$/, '');
85
+
86
+      to = response.searchTerm.split(/-dt\s/)[1] ? response.searchTerm.split(/-dt\s/)[1].split(' ')[0] : false;
87
+      response.searchTerm = response.searchTerm.replace(/-dt\s/, '').replace(`${to}`, '').replace(/^\s+|\s+$/g, '');
88
 
89
       download = true;
90
+
91
     } else {
92
-      download = false;
93
+      to = false;
94
     }
95
 
96
-    if(search.match(/^-dt\s*?/) || search.match(/\s*?-dt\s*?/)) {
97
-
98
-      to = response.searchTerm.split(/-dt\s?/)[1] ? response.searchTerm.split(/-td\s?/)[1].split(' ')[0] : false;
99
-      response.searchTerm = search.replace(/^-dt\s?/, '').replace(/\s?-dt\s?$/, '');
100
+    if(response.searchTerm.match(/-a\s*?/) || response.searchTerm.match(/--auto\s*?/)) if(response.searchTerm.split(/--?a(uto)?\s?/)[0]
101
+      .replace(/--?d(ownload)?\s?/, '')
102
+      .replace(/-dt\s?/, '')
103
+      .replace(/ /g, '') === '') {
104
 
105
-      download = true;
106
+      response.searchTerm = response.searchTerm.replace(/--?a(uto)?\s/, '');
107
+      auto = true;
108
     }
109
 
110
-    if(search.match(/^-t\s*?/) || search.match(/\s*?-t\s*?/) ||
111
-      search.match(/^--to\s*?/) || search.match(/\s*?--to\s*?/)) {
112
+    if(response.searchTerm.match(/-d\s*/) || response.searchTerm.match(/--download\s*?/)) if(response.searchTerm.split(/--?d(ownload)?\s?/)[0]
113
+      .replace(/-dt\s?/, '')
114
+      .replace(/ /g, '') === '') {
115
 
116
-      to = response.searchTerm.split(/-t\s?/)[1] ? response.searchTerm.split(/-t\s?/)[1].split(' ')[0] :
117
-        response.searchTerm.split(/--to\s?/)[1] ? response.searchTerm.split(/--to\s?/)[1].split(' ')[0] : false;
118
+      response.searchTerm = response.searchTerm.replace(/--?d(ownload)?\s/, '');
119
 
120
-      if(to === false) {
121
-        await sh(`echo -e "\n [-] Error: the --to flag requires an argument\n"`);
122
-        process.exit(0);
123
-      }
124
-
125
-      response.searchTerm = search.replace(/^-t\s?/, '')
126
-        .replace(/\s?-t\s?$/, '') .replace(/\^--to\s?/, '')
127
-        .replace(/\s?--to\s?$/, '').replace(to, '');
128
-
129
-      if(to && !download) {
130
-        await sh(`echo -e "\n [-] Error: the --to flag cannot be used without the --download flag\n"`);
131
-      }
132
+      download = true;
133
 
134
     } else {
135
-      to = false;
136
+      download = false;
137
     }
138
 
139
+
140
   } else {
141
     help = false;
142
     auto = false;
143
@@ -144,8 +146,14 @@ const main = async (search) => {
144
     to = false;
145
   }
146
 
147
+
148
   if(help) process.exit(0);
149
-  if(to && !download) process.exit(0);
150
+
151
+  if(to && !download) {
152
+    await sh(`echo -e "\n [-] Error: the --to flag cannot be used without the --download flag\n"`);
153
+    process.exit(0);
154
+  }
155
+
156
 
157
   const data = await getData(response.searchTerm);
158
   const list = data.map((d, i) => {