yt-cli


Logs | Files | README | README | LICENSE | GitLab


1
commit a1ab6ce89377f16561d8c3e97069ceaf5a70c2c9
2
Author: Connor Etherington <[email protected]>
3
Date:   Fri May 26 05:28:52 2023 +0200
4
5
    Auto-Commit Update - 20230526
6
---
7
 PKGBUILD                                           |  2 +-
8
 usr/bin/yt-cli                                     |  2 +-
9
 .../yt-cli/{bin/yt-cli => lib/yt-cli.js}           | 48 ++++++++++++++++++----
10
 usr/lib/node_modules/yt-cli/package.json           |  9 ++--
11
 4 files changed, 48 insertions(+), 13 deletions(-)
12
13
diff --git a/PKGBUILD b/PKGBUILD
14
index e99ef3e..1330d0a 100644
15
--- a/PKGBUILD
16
+++ b/PKGBUILD
17
@@ -1,7 +1,7 @@
18
 # Maintainer: Connor Etherington <[email protected]>
19
 # ---
20
 pkgname=yt-cli
21
-pkgver=0.2.0
22
+pkgver=0.2.1
23
 pkgrel=1
24
 pkgdesc="An easy to use CLI YouTube client"
25
 arch=('any')
26
diff --git a/usr/bin/yt-cli b/usr/bin/yt-cli
27
index d8df8ee..93725c2 100755
28
--- a/usr/bin/yt-cli
29
+++ b/usr/bin/yt-cli
30
@@ -1,2 +1,2 @@
31
 #!/usr/bin/env node
32
-require('/usr/lib/node_modules/yt-cli/bin/yt-cli');
33
+require('/usr/lib/node_modules/yt-cli');
34
diff --git a/usr/lib/node_modules/yt-cli/bin/yt-cli b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
35
similarity index 68%
36
rename from usr/lib/node_modules/yt-cli/bin/yt-cli
37
rename to usr/lib/node_modules/yt-cli/lib/yt-cli.js
38
index 1a322a8..48c2524 100755
39
--- a/usr/lib/node_modules/yt-cli/bin/yt-cli
40
+++ b/usr/lib/node_modules/yt-cli/lib/yt-cli.js
41
@@ -1,5 +1,8 @@
42
 #!/usr/bin/env node
43
 
44
+import { createRequire } from 'module';
45
+const require = createRequire(import.meta.url);
46
+
47
 const fs = require('fs');
48
 const beautifier = require('html-formatter');
49
 const axios = require('axios');
50
@@ -73,11 +76,7 @@ const main = async (search) => {
51
     if(search.match(/^-h\s*?/) || search.match(/\s*?-h\s*?/) ||
52
       search.match(/^--help\s*?/) || search.match(/\s*?--help\s*?/)) {
53
 
54
-      const exe = async (cmd, cb) => await require('child_process').exec( cmd, async (e, so, se) => cb(so));
55
-      const cl = (x) => console.log(x);
56
-
57
-      const c = `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    -h | --help     : display this message"`
58
-      await exe(c, cl);
59
+      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"`);
60
 
61
       var help = true;
62
     } else {
63
@@ -108,12 +107,49 @@ const main = async (search) => {
64
       var download = false;
65
     }
66
 
67
+    if(search.match(/^-dt\s*?/) || search.match(/\s*?-dt\s*?/)) {
68
+
69
+      var to = response.searchTerm.split(/-dt\s?/)[1] ? response.searchTerm.split(/-td\s?/)[1].split(' ')[0] : false;
70
+      response.searchTerm = search.replace(/^-dt\s?/, '').replace(/\s?-dt\s?$/, '');
71
+
72
+      var download = true;
73
+    } else {
74
+      var download = false;
75
+    }
76
+
77
+    if(search.match(/^-t\s*?/) || search.match(/\s*?-t\s*?/) ||
78
+      search.match(/^--to\s*?/) || search.match(/\s*?--to\s*?/)) {
79
+
80
+      var to = response.searchTerm.split(/-t\s?/)[1] ? response.searchTerm.split(/-t\s?/)[1].split(' ')[0] :
81
+        response.searchTerm.split(/--to\s?/)[1] ? response.searchTerm.split(/--to\s?/)[1].split(' ')[0] : false;
82
+
83
+      if(to === false) {
84
+        await sh(`echo -e "\n [-] Error: the --to flag requires an argument\n"`);
85
+        process.exit(0);
86
+      }
87
+
88
+      response.searchTerm = search.replace(/^-t\s?/, '')
89
+        .replace(/\s?-t\s?$/, '') .replace(/\^--to\s?/, '')
90
+        .replace(/\s?--to\s?$/, '').replace(to, '');
91
+
92
+      if(to && !download) {
93
+        await sh(`echo -e "\n [-] Error: the --to flag cannot be used without the --download flag\n"`);
94
+      }
95
+
96
+    } else {
97
+      var to = false;
98
+    }
99
+
100
   } else {
101
     var help = false;
102
     var auto = false;
103
     var download = false;
104
+    var to = false;
105
   }
106
 
107
+  if(help) process.exit(0);
108
+  if(to && !download) process.exit(0);
109
+
110
   const data = await getData(response.searchTerm);
111
   const list = data.map((d, i) => {
112
     return `${i + 1}. ${d.title}`;
113
@@ -129,8 +165,6 @@ const main = async (search) => {
114
 
115
   const selectedVideo = data[response2.video];
116
 
117
-  if(help) process.exit(0);
118
-
119
   if(download) {
120
     if(!fs.existsSync(os.homedir() + '/yt-cli')) fs.mkdirSync(os.homedir() + '/yt-cli');
121
     await dV(selectedVideo.url, os.homedir() + '/yt-cli/' + selectedVideo.title + '.mp4');
122
diff --git a/usr/lib/node_modules/yt-cli/package.json b/usr/lib/node_modules/yt-cli/package.json
123
index 82d8425..0c2abe9 100644
124
--- a/usr/lib/node_modules/yt-cli/package.json
125
+++ b/usr/lib/node_modules/yt-cli/package.json
126
@@ -1,13 +1,14 @@
127
 {
128
-  "name": "yt-cli",
129
-  "version": "0.2.0",
130
-  "main": "bin/yt-cli",
131
+  "name": "@a4to/yt-cli",
132
+  "version": "0.2.1",
133
+  "main": "lib/yt-cli.js",
134
+  "type": "module",
135
   "scripts": {
136
     "start": "node ${npm_package_main}",
137
     "dev": "nodemon ${npm_package_main}"
138
   },
139
   "bin": {
140
-    "yt-cli": "./${npm_package_main}"
141
+    "yt-cli": "lib/yt-cli.js"
142
   },
143
   "author": "Connor Etherington <[email protected]>",
144
   "license": "MIT",