ani-cli-npm 2.0.10 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.MD +1 -1
- package/bin/Anime.js +54 -47
- package/bin/change_config.js +79 -54
- package/bin/core_utils/curl.js +35 -0
- package/bin/core_utils/libs.js +12 -0
- package/bin/core_utils/regex.js +8 -0
- package/bin/file_managment/cache.js +79 -0
- package/bin/file_managment/change_config.js +99 -0
- package/bin/file_managment/load_config.js +110 -0
- package/bin/generate_link.js +3 -2
- package/bin/help.js +59 -0
- package/bin/index.js +11 -6
- package/bin/load_config.js +12 -0
- package/bin/search_anime.js +2 -2
- package/package.json +3 -2
package/README.MD
CHANGED
@@ -27,7 +27,7 @@ npx ani-cli-npm@latest
|
|
27
27
|
```
|
28
28
|
|
29
29
|
### Linux:
|
30
|
-
#### - Install [nodejs](https://nodejs.org/en/download/ with your distrabutions package manager.
|
30
|
+
#### - Install [nodejs](https://nodejs.org/en/download/) with your distrabutions package manager.
|
31
31
|
#### - Run the following command:
|
32
32
|
```
|
33
33
|
npx ani-cli-npm@latest
|
package/bin/Anime.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Anime = void 0;
|
4
|
-
const curl_1 = require("./curl");
|
5
|
-
const regex_1 = require("./regex");
|
4
|
+
const curl_1 = require("./core_utils/curl");
|
5
|
+
const regex_1 = require("./core_utils/regex");
|
6
6
|
const generate_link_1 = require("./generate_link");
|
7
|
-
const cache_1 = require("./cache");
|
7
|
+
const cache_1 = require("./file_managment/cache");
|
8
8
|
const input_1 = require("./input");
|
9
|
-
const load_config_1 = require("./load_config");
|
9
|
+
const load_config_1 = require("./file_managment/load_config");
|
10
|
+
const W2GClient = require("w2g-client");
|
10
11
|
const open = require("open");
|
11
12
|
const PlayerController = require("media-player-controller");
|
12
13
|
const dl = require("download-file-with-progressbar");
|
@@ -24,6 +25,7 @@ class Anime {
|
|
24
25
|
episode_list = [];
|
25
26
|
most_recent = 0;
|
26
27
|
player = 0;
|
28
|
+
current_pos = 0;
|
27
29
|
async init(anime_id, cache_folder) {
|
28
30
|
/*
|
29
31
|
Initiate Anime object
|
@@ -50,6 +52,9 @@ class Anime {
|
|
50
52
|
if (cache_object.most_recent != undefined) {
|
51
53
|
this.most_recent = cache_object.most_recent;
|
52
54
|
}
|
55
|
+
if (cache_object.position != undefined) {
|
56
|
+
this.current_pos = cache_object.position;
|
57
|
+
}
|
53
58
|
}
|
54
59
|
catch {
|
55
60
|
await this.get_ep_bases(this.id);
|
@@ -115,13 +120,13 @@ class Anime {
|
|
115
120
|
- If set to Link, it will simply print the media stream link to console, primarily for debuting peruses.
|
116
121
|
*/
|
117
122
|
console.clear();
|
118
|
-
console.log(`Playing ${this.id} episode ${episode + 1}`);
|
123
|
+
console.log(`Playing ${this.id} episode ${episode + 1} from ${new Date(this.current_pos * 1000).toISOString().slice(11, 19)}`);
|
119
124
|
switch (config.player) {
|
120
125
|
case "MPV":
|
121
126
|
console.log(("Opening MPV.."));
|
122
127
|
this.player = await new PlayerController({
|
123
128
|
app: 'mpv',
|
124
|
-
args: ['--fullscreen'],
|
129
|
+
args: ['--fullscreen', '--keep-open=yes', `--start=+${this.current_pos}`],
|
125
130
|
media: await this.get_episode_link(episode, config.player),
|
126
131
|
ipcPath: config.mpv_socket_path
|
127
132
|
});
|
@@ -135,8 +140,10 @@ class Anime {
|
|
135
140
|
console.log(("Opening VLC.."));
|
136
141
|
this.player = await new PlayerController({
|
137
142
|
app: 'vlc',
|
138
|
-
args: ['--fullscreen'],
|
139
|
-
media: await this.get_episode_link(episode, config.player)
|
143
|
+
args: ['--fullscreen', `--start-time ${this.current_pos}`],
|
144
|
+
media: await this.get_episode_link(episode, config.player),
|
145
|
+
//httpPort: (config.vlc_socket !== 0)? config.vlc_socket : null, // HTTP port for local communication (vlc only)
|
146
|
+
//httpPass: (config.vlc_pass !== "")? config.vlc_socket : null,
|
140
147
|
});
|
141
148
|
// @ts-ignore
|
142
149
|
await this.player.launch(err => {
|
@@ -148,11 +155,43 @@ class Anime {
|
|
148
155
|
console.log(("Opening browser..."));
|
149
156
|
await open(await this.get_episode_link(episode, config.player));
|
150
157
|
break;
|
158
|
+
case "W2G":
|
159
|
+
try {
|
160
|
+
this.player = new W2GClient.W2GClient(config.w2g_api_key);
|
161
|
+
await this.player.create(await this.get_episode_link(episode, config.player));
|
162
|
+
console.log(chalk.green("Room link: " + await this.player.getLink()));
|
163
|
+
}
|
164
|
+
catch {
|
165
|
+
console.log(chalk.red("Failed to create w2g.tv room. \nthis can often be because your API token is invalid. You can change it in options."));
|
166
|
+
process.exit();
|
167
|
+
}
|
168
|
+
await open(await this.player.getLink());
|
169
|
+
break;
|
151
170
|
case "LINK":
|
152
171
|
this.player = 1;
|
153
172
|
console.log(await this.get_episode_link(episode, config.player));
|
154
173
|
break;
|
155
174
|
}
|
175
|
+
if (this.player.on !== undefined) {
|
176
|
+
this.player.on('playback', (data) => {
|
177
|
+
if (data.name == "time-pos" && data.value >= 0) {
|
178
|
+
this.current_pos = data.value;
|
179
|
+
}
|
180
|
+
});
|
181
|
+
this.player.on('app-exit', (code) => {
|
182
|
+
config.most_recent.anime_id = this.id;
|
183
|
+
config.most_recent.episode_number = episode;
|
184
|
+
config.most_recent.episode_second = this.current_pos;
|
185
|
+
(0, load_config_1.write_config)(config_dir, config);
|
186
|
+
this.most_recent = episode;
|
187
|
+
(0, cache_1.new_cache)(config_dir, {
|
188
|
+
id: this.id,
|
189
|
+
episode_list: this.episode_list,
|
190
|
+
most_recent: this.most_recent,
|
191
|
+
position: this.current_pos
|
192
|
+
});
|
193
|
+
});
|
194
|
+
}
|
156
195
|
await this.play(episode, config, config_dir, true);
|
157
196
|
}
|
158
197
|
async play(episode, config, config_dir, first = false) {
|
@@ -169,6 +208,10 @@ class Anime {
|
|
169
208
|
else if (this.player == 1) {
|
170
209
|
console.log(await this.get_episode_link(episode));
|
171
210
|
}
|
211
|
+
else if (this.player.roomID != undefined) {
|
212
|
+
console.log(chalk.green("Room link: " + await this.player.getLink()));
|
213
|
+
this.player.update(await this.get_episode_link(episode));
|
214
|
+
}
|
172
215
|
else if (this.player.opts.app == "mpv") {
|
173
216
|
await this.player.load(await this.get_episode_link(episode));
|
174
217
|
}
|
@@ -188,12 +231,14 @@ class Anime {
|
|
188
231
|
}
|
189
232
|
config.most_recent.anime_id = this.id;
|
190
233
|
config.most_recent.episode_number = episode;
|
234
|
+
config.most_recent.episode_second = this.current_pos;
|
191
235
|
(0, load_config_1.write_config)(config_dir, config);
|
192
236
|
this.most_recent = episode;
|
193
237
|
(0, cache_1.new_cache)(config_dir, {
|
194
238
|
id: this.id,
|
195
239
|
episode_list: this.episode_list,
|
196
|
-
most_recent: this.most_recent
|
240
|
+
most_recent: this.most_recent,
|
241
|
+
position: this.current_pos
|
197
242
|
});
|
198
243
|
let selected; // Look, I'm sorry, but there is no way I can possibly document this in a sane way. It's a dumb patch.
|
199
244
|
do {
|
@@ -231,44 +276,6 @@ class Anime {
|
|
231
276
|
case 3:
|
232
277
|
break;
|
233
278
|
}
|
234
|
-
// if (episode <= 0){
|
235
|
-
// switch(await selection([
|
236
|
-
// "Next",
|
237
|
-
// "Quit"
|
238
|
-
// ], ["n", "q"])){
|
239
|
-
// case 0:
|
240
|
-
// await this.play(episode+1, config, config_dir)
|
241
|
-
// break
|
242
|
-
// case 1:
|
243
|
-
// break
|
244
|
-
// }
|
245
|
-
// }else if(episode >= this.episode_list.length-2){
|
246
|
-
// switch(await selection([
|
247
|
-
// "Previous",
|
248
|
-
// "Quit"
|
249
|
-
// ], ["p", "q"])){
|
250
|
-
// case 0:
|
251
|
-
// await this.play(episode-1, config, config_dir)
|
252
|
-
// break
|
253
|
-
// case 1:
|
254
|
-
// break
|
255
|
-
// }
|
256
|
-
// }else{
|
257
|
-
// switch(await selection([
|
258
|
-
// "Next",
|
259
|
-
// "Previous",
|
260
|
-
// "Quit"
|
261
|
-
// ], ["n", "p", "q"])){
|
262
|
-
// case 0:
|
263
|
-
// await this.play(episode+1, config, config_dir)
|
264
|
-
// break
|
265
|
-
// case 1:
|
266
|
-
// await this.play(episode-1, config, config_dir)
|
267
|
-
// break
|
268
|
-
// case 2:
|
269
|
-
// break
|
270
|
-
// }
|
271
|
-
// }
|
272
279
|
}
|
273
280
|
async download(episode, download_folder, final_ep) {
|
274
281
|
/*
|
package/bin/change_config.js
CHANGED
@@ -3,72 +3,97 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config_ = void 0;
|
4
4
|
const chalk = require("chalk");
|
5
5
|
const input_1 = require("./input");
|
6
|
+
const configs = [
|
7
|
+
(async (temp) => {
|
8
|
+
temp.player = [
|
9
|
+
"VLC",
|
10
|
+
"BROWSER",
|
11
|
+
"MPV",
|
12
|
+
"W2G",
|
13
|
+
"LINK",
|
14
|
+
][await (0, input_1.selection)([
|
15
|
+
"VLC - VLC media player",
|
16
|
+
"Browser - Play in default browser",
|
17
|
+
"MPV - MPV media player",
|
18
|
+
"w2g.tv - Watch together with friends in browser (Specify api token to create rooms linked to your account)",
|
19
|
+
"Link - Simply display the link in console"
|
20
|
+
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }))];
|
21
|
+
// @ts-ignore
|
22
|
+
return temp, 0;
|
23
|
+
}),
|
24
|
+
(async (temp) => {
|
25
|
+
console.log(chalk.cyan("New Proxy;"));
|
26
|
+
temp.proxy = (await ((0, input_1.input)())).replaceAll(" ", "");
|
27
|
+
// @ts-ignore
|
28
|
+
return temp, 0;
|
29
|
+
}),
|
30
|
+
(async (temp) => {
|
31
|
+
console.log(chalk.cyan("New User Agent"));
|
32
|
+
temp.user_agent = await ((0, input_1.input)());
|
33
|
+
// @ts-ignore
|
34
|
+
return temp, 0;
|
35
|
+
}),
|
36
|
+
(async (temp) => {
|
37
|
+
console.log(chalk.cyan("New Downloads Folder"));
|
38
|
+
temp.download_folder = await ((0, input_1.input)());
|
39
|
+
// @ts-ignore
|
40
|
+
return temp, 0;
|
41
|
+
}),
|
42
|
+
(async (temp) => {
|
43
|
+
console.log(chalk.cyan("New socket file"));
|
44
|
+
temp.mpv_socket_path = await ((0, input_1.input)());
|
45
|
+
// @ts-ignore
|
46
|
+
return temp, 0;
|
47
|
+
}),
|
48
|
+
(async (temp) => {
|
49
|
+
console.log(chalk.cyan("New VLC socket"));
|
50
|
+
temp.vlc_socket = await ((0, input_1.input)());
|
51
|
+
// @ts-ignore
|
52
|
+
return temp, 0;
|
53
|
+
}),
|
54
|
+
(async (temp) => {
|
55
|
+
console.log(chalk.cyan("New VLC password"));
|
56
|
+
temp.vlc_pass = await ((0, input_1.input)());
|
57
|
+
// @ts-ignore
|
58
|
+
return temp, 0;
|
59
|
+
}),
|
60
|
+
(async (temp) => {
|
61
|
+
console.log(chalk.cyan("New w2g.tv api token"));
|
62
|
+
temp.w2g_api_key = await ((0, input_1.input)());
|
63
|
+
// @ts-ignore
|
64
|
+
return temp, 0;
|
65
|
+
}),
|
66
|
+
(async (temp) => {
|
67
|
+
// @ts-ignore
|
68
|
+
return temp, 1;
|
69
|
+
}),
|
70
|
+
(async (temp) => {
|
71
|
+
// @ts-ignore
|
72
|
+
return temp, 2;
|
73
|
+
})
|
74
|
+
];
|
6
75
|
async function config_(temp) {
|
7
76
|
/*
|
8
77
|
## Lets user change a single attribute of config. Returns new config object, and an exit code
|
78
|
+
|
79
|
+
### 0 to continue (generic return)
|
80
|
+
### 1 To confirm (Save and exit)
|
81
|
+
### 2 to cancel (exit without saving changes)
|
9
82
|
*/
|
10
83
|
console.clear();
|
11
84
|
console.log(chalk.blue("ANI-CLI-NPM \n"));
|
12
85
|
console.log(chalk.yellow("Config:\n"));
|
13
|
-
|
86
|
+
return configs[await (0, input_1.selection)([
|
14
87
|
"Player; " + temp.player,
|
15
88
|
"Proxy; " + temp.proxy,
|
16
89
|
"User agent; " + temp.user_agent,
|
17
90
|
"Downloads folder; " + temp.download_folder,
|
18
|
-
"
|
91
|
+
"Mpv socket connection file; " + temp.mpv_socket_path,
|
92
|
+
"VLC socket; " + temp.vlc_socket,
|
93
|
+
"VLC pass; " + temp.vlc_pass,
|
94
|
+
"W2G api token: " + temp.w2g_api_key,
|
19
95
|
"Save and exit",
|
20
96
|
"Exit without saving"
|
21
|
-
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }));
|
22
|
-
switch (choice) {
|
23
|
-
case 0:
|
24
|
-
let player = await (0, input_1.selection)([
|
25
|
-
"VLC - VLC media player",
|
26
|
-
"Browser - Play in default browser",
|
27
|
-
"MPV - MPV media player",
|
28
|
-
"Link - Simply display the link in console"
|
29
|
-
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }));
|
30
|
-
switch (player) {
|
31
|
-
case 0:
|
32
|
-
temp.player = "VLC";
|
33
|
-
break;
|
34
|
-
case 1:
|
35
|
-
temp.player = "BROWSER";
|
36
|
-
break;
|
37
|
-
case 2:
|
38
|
-
temp.player = "MPV";
|
39
|
-
break;
|
40
|
-
case 3:
|
41
|
-
temp.player = "LINK";
|
42
|
-
break;
|
43
|
-
}
|
44
|
-
// @ts-ignore
|
45
|
-
return temp, 0;
|
46
|
-
case 1:
|
47
|
-
console.log(chalk.cyan("New Proxy;"));
|
48
|
-
temp.proxy = (await ((0, input_1.input)())).replaceAll(" ", "");
|
49
|
-
// @ts-ignore
|
50
|
-
return temp, 0;
|
51
|
-
case 2:
|
52
|
-
console.log(chalk.cyan("New User Agent"));
|
53
|
-
temp.user_agent = await ((0, input_1.input)());
|
54
|
-
// @ts-ignore
|
55
|
-
return temp, 0;
|
56
|
-
case 3:
|
57
|
-
console.log(chalk.cyan("New Downloads Folder"));
|
58
|
-
temp.download_folder = await ((0, input_1.input)());
|
59
|
-
// @ts-ignore
|
60
|
-
return temp, 0;
|
61
|
-
case 4:
|
62
|
-
console.log(chalk.cyan("New socket file"));
|
63
|
-
temp.mpv_socket_path = await ((0, input_1.input)());
|
64
|
-
// @ts-ignore
|
65
|
-
return temp, 0;
|
66
|
-
case 5:
|
67
|
-
// @ts-ignore
|
68
|
-
return temp, 1;
|
69
|
-
case 6:
|
70
|
-
// @ts-ignore
|
71
|
-
return temp, 2;
|
72
|
-
}
|
97
|
+
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }))](temp);
|
73
98
|
}
|
74
99
|
exports.config_ = config_;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.curl = void 0;
|
4
|
+
const fetch = require("node-fetch");
|
5
|
+
const chalk = require("chalk");
|
6
|
+
async function curl(url, method = "GET", redirect = false) {
|
7
|
+
try {
|
8
|
+
let response = await fetch(url, {
|
9
|
+
//"agent": proxyAgent,
|
10
|
+
"headers": {
|
11
|
+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0',
|
12
|
+
"X-Requested-With": "XMLHttpRequest"
|
13
|
+
},
|
14
|
+
"referrerPolicy": "origin",
|
15
|
+
"body": null,
|
16
|
+
"method": method,
|
17
|
+
"redirect": 'follow',
|
18
|
+
// "follow": 10,
|
19
|
+
}).catch(async function (err) {
|
20
|
+
console.warn(chalk.red(`Something went wrong connecting to ${url}. ${err}`));
|
21
|
+
process.exit();
|
22
|
+
});
|
23
|
+
if (redirect) {
|
24
|
+
return response.url;
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
return await response.text();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
catch {
|
31
|
+
console.log(chalk.red("Something went wrong in curl()"));
|
32
|
+
process.exit();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.curl = curl;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
// Random functions
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.range = void 0;
|
5
|
+
function range(start, end) {
|
6
|
+
let ans = [];
|
7
|
+
for (let i = start; i <= end; i++) {
|
8
|
+
ans.push(i);
|
9
|
+
}
|
10
|
+
return ans;
|
11
|
+
}
|
12
|
+
exports.range = range;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RegexParse = void 0;
|
4
|
+
function RegexParse(str, rule) {
|
5
|
+
let escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
6
|
+
return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(str);
|
7
|
+
}
|
8
|
+
exports.RegexParse = RegexParse;
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.search_cache = exports.new_cache = exports.clear_cache = void 0;
|
27
|
+
const fs = __importStar(require("fs"));
|
28
|
+
function clear_cache(location, show) {
|
29
|
+
try {
|
30
|
+
console.log("ye sorry that doesnt exist yet.");
|
31
|
+
if (show) {
|
32
|
+
console.log("Cleared cache");
|
33
|
+
}
|
34
|
+
}
|
35
|
+
catch {
|
36
|
+
if (show) {
|
37
|
+
console.log("Failed to clear cache.");
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.clear_cache = clear_cache;
|
42
|
+
function new_cache(location, anime) {
|
43
|
+
/*
|
44
|
+
Creates cache of Anime object, in cache file.
|
45
|
+
*/
|
46
|
+
try {
|
47
|
+
fs.writeFileSync(location + "/" + anime.id + ".cache", JSON.stringify(anime));
|
48
|
+
}
|
49
|
+
catch {
|
50
|
+
console.log("Failed to write to cache");
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.new_cache = new_cache;
|
54
|
+
function get_cache(location, anime_id) {
|
55
|
+
/*
|
56
|
+
## Get cache by anime_id. Does not check if the cache exists.
|
57
|
+
*/
|
58
|
+
return JSON.parse(fs.readFileSync(location + "/" + anime_id + ".cache").toString());
|
59
|
+
}
|
60
|
+
function search_cache(cache_folder, anime_id) {
|
61
|
+
/*
|
62
|
+
## Searches cache folder for cache file with name of anime_id, at the location of cache_folder
|
63
|
+
|
64
|
+
### returns boolean for weather it is found.
|
65
|
+
*/
|
66
|
+
try {
|
67
|
+
if (check_cache(cache_folder, anime_id)) {
|
68
|
+
return get_cache(cache_folder, anime_id);
|
69
|
+
}
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
catch {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
exports.search_cache = search_cache;
|
77
|
+
function check_cache(location, anime_id) {
|
78
|
+
return fs.readdirSync(location).includes(anime_id + ".cache");
|
79
|
+
}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.config_ = void 0;
|
4
|
+
const chalk = require("chalk");
|
5
|
+
const input_1 = require("../input");
|
6
|
+
const configs = [
|
7
|
+
(async (temp) => {
|
8
|
+
temp.player = [
|
9
|
+
"VLC",
|
10
|
+
"BROWSER",
|
11
|
+
"MPV",
|
12
|
+
"W2G",
|
13
|
+
"LINK",
|
14
|
+
][await (0, input_1.selection)([
|
15
|
+
"VLC - VLC media player",
|
16
|
+
"Browser - Play in default browser",
|
17
|
+
"MPV - MPV media player",
|
18
|
+
"w2g.tv - Watch together with friends in browser (Specify api token to create rooms linked to your account)",
|
19
|
+
"Link - Simply display the link in console"
|
20
|
+
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }))];
|
21
|
+
// @ts-ignore
|
22
|
+
return temp, 0;
|
23
|
+
}),
|
24
|
+
(async (temp) => {
|
25
|
+
console.log(chalk.cyan("New Proxy;"));
|
26
|
+
temp.proxy = (await ((0, input_1.input)())).replaceAll(" ", "");
|
27
|
+
// @ts-ignore
|
28
|
+
return temp, 0;
|
29
|
+
}),
|
30
|
+
(async (temp) => {
|
31
|
+
console.log(chalk.cyan("New User Agent"));
|
32
|
+
temp.user_agent = await ((0, input_1.input)());
|
33
|
+
// @ts-ignore
|
34
|
+
return temp, 0;
|
35
|
+
}),
|
36
|
+
(async (temp) => {
|
37
|
+
console.log(chalk.cyan("New Downloads Folder"));
|
38
|
+
temp.download_folder = await ((0, input_1.input)());
|
39
|
+
// @ts-ignore
|
40
|
+
return temp, 0;
|
41
|
+
}),
|
42
|
+
(async (temp) => {
|
43
|
+
console.log(chalk.cyan("New socket file"));
|
44
|
+
temp.mpv_socket_path = await ((0, input_1.input)());
|
45
|
+
// @ts-ignore
|
46
|
+
return temp, 0;
|
47
|
+
}),
|
48
|
+
(async (temp) => {
|
49
|
+
console.log(chalk.cyan("New VLC socket"));
|
50
|
+
temp.vlc_socket = await ((0, input_1.input)());
|
51
|
+
// @ts-ignore
|
52
|
+
return temp, 0;
|
53
|
+
}),
|
54
|
+
(async (temp) => {
|
55
|
+
console.log(chalk.cyan("New VLC password"));
|
56
|
+
temp.vlc_pass = await ((0, input_1.input)());
|
57
|
+
// @ts-ignore
|
58
|
+
return temp, 0;
|
59
|
+
}),
|
60
|
+
(async (temp) => {
|
61
|
+
console.log(chalk.cyan("New w2g.tv api token"));
|
62
|
+
temp.w2g_api_key = await ((0, input_1.input)());
|
63
|
+
// @ts-ignore
|
64
|
+
return temp, 0;
|
65
|
+
}),
|
66
|
+
(async (temp) => {
|
67
|
+
// @ts-ignore
|
68
|
+
return temp, 1;
|
69
|
+
}),
|
70
|
+
(async (temp) => {
|
71
|
+
// @ts-ignore
|
72
|
+
return temp, 2;
|
73
|
+
})
|
74
|
+
];
|
75
|
+
async function config_(temp) {
|
76
|
+
/*
|
77
|
+
## Lets user change a single attribute of config. Returns new config object, and an exit code
|
78
|
+
|
79
|
+
### 0 to continue (generic return)
|
80
|
+
### 1 To confirm (Save and exit)
|
81
|
+
### 2 to cancel (exit without saving changes)
|
82
|
+
*/
|
83
|
+
console.clear();
|
84
|
+
console.log(chalk.blue("ANI-CLI-NPM \n"));
|
85
|
+
console.log(chalk.yellow("Config:\n"));
|
86
|
+
return configs[await (0, input_1.selection)([
|
87
|
+
"Player; " + temp.player,
|
88
|
+
"Proxy; " + temp.proxy,
|
89
|
+
"User agent; " + temp.user_agent,
|
90
|
+
"Downloads folder; " + temp.download_folder,
|
91
|
+
"Mpv socket connection file; " + temp.mpv_socket_path,
|
92
|
+
"VLC socket; " + temp.vlc_socket,
|
93
|
+
"VLC pass; " + temp.vlc_pass,
|
94
|
+
"W2G api token: " + temp.w2g_api_key,
|
95
|
+
"Save and exit",
|
96
|
+
"Exit without saving"
|
97
|
+
], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }))](temp);
|
98
|
+
}
|
99
|
+
exports.config_ = config_;
|
@@ -0,0 +1,110 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.make_config_dir = exports.write_config = exports.load_config = void 0;
|
27
|
+
const fs = __importStar(require("fs"));
|
28
|
+
function make_config_dir(cache_dir, debug) {
|
29
|
+
try {
|
30
|
+
if (!fs.existsSync(cache_dir + "/"))
|
31
|
+
fs.mkdirSync(cache_dir + "/");
|
32
|
+
}
|
33
|
+
catch {
|
34
|
+
if (debug) {
|
35
|
+
console.log("Failed to make cache dir");
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
exports.make_config_dir = make_config_dir;
|
40
|
+
function write_config(cache_dir, config) {
|
41
|
+
try {
|
42
|
+
//make_config_dir(cache_dir, config.debug_mode)
|
43
|
+
fs.writeFileSync(cache_dir + "/config.conf", JSON.stringify(config), "utf-8");
|
44
|
+
}
|
45
|
+
catch {
|
46
|
+
console.log(("Failed to write to config file."));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
exports.write_config = write_config;
|
50
|
+
function load_config(cache_dir) {
|
51
|
+
let config = {
|
52
|
+
player: "BROWSER",
|
53
|
+
proxy: "",
|
54
|
+
user_agent: "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
|
55
|
+
most_recent: {
|
56
|
+
episode_number: 0,
|
57
|
+
episode_second: 0,
|
58
|
+
anime_id: ""
|
59
|
+
},
|
60
|
+
download_folder: ".",
|
61
|
+
debug_mode: false,
|
62
|
+
mpv_socket_path: "",
|
63
|
+
vlc_socket: 0,
|
64
|
+
vlc_pass: "",
|
65
|
+
w2g_api_key: ""
|
66
|
+
};
|
67
|
+
if (fs.existsSync(cache_dir + "/config.conf")) {
|
68
|
+
// @ts-ignore
|
69
|
+
let tmp = JSON.parse(fs.readFileSync(cache_dir + "/config.conf"), "utf8");
|
70
|
+
// @ts-ignore
|
71
|
+
if (tmp.player !== undefined)
|
72
|
+
config.player = tmp.player;
|
73
|
+
// @ts-ignore
|
74
|
+
if (tmp.proxy !== undefined)
|
75
|
+
config.proxy = tmp.proxy;
|
76
|
+
// @ts-ignore
|
77
|
+
if (tmp.user_agent !== undefined)
|
78
|
+
config.user_agent = tmp.user_agent;
|
79
|
+
// @ts-ignore
|
80
|
+
if (tmp.most_recent !== undefined) {
|
81
|
+
// @ts-ignore
|
82
|
+
if (tmp.most_recent.episode_number !== undefined)
|
83
|
+
config.most_recent.episode_number = tmp.most_recent.episode_number;
|
84
|
+
// @ts-ignore
|
85
|
+
if (tmp.most_recent.anime_id !== undefined)
|
86
|
+
config.most_recent.anime_id = tmp.most_recent.anime_id;
|
87
|
+
// @ts-ignore
|
88
|
+
if (tmp.most_recent.episode_second !== undefined)
|
89
|
+
config.most_recent.episode_second = tmp.most_recent.episode_second;
|
90
|
+
}
|
91
|
+
// @ts-ignore
|
92
|
+
if (tmp.download_folder !== undefined)
|
93
|
+
config.download_folder = tmp.download_folder;
|
94
|
+
// @ts-ignore
|
95
|
+
if (tmp.mpv_socket_path !== undefined)
|
96
|
+
config.mpv_socket_path = tmp.mpv_socket_path;
|
97
|
+
// @ts-ignore
|
98
|
+
if (tmp.vlc_socket !== undefined)
|
99
|
+
config.vlc_socket = tmp.vlc_socket;
|
100
|
+
// @ts-ignore
|
101
|
+
if (tmp.vlc_pass !== undefined)
|
102
|
+
config.vlc_pass = tmp.vlc_pass;
|
103
|
+
// @ts-ignore
|
104
|
+
if (tmp.w2g_api_key !== undefined)
|
105
|
+
config.w2g_api_key = tmp.w2g_api_key;
|
106
|
+
}
|
107
|
+
write_config(cache_dir, config);
|
108
|
+
return config;
|
109
|
+
}
|
110
|
+
exports.load_config = load_config;
|
package/bin/generate_link.js
CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generate_link = void 0;
|
4
4
|
const gogohd_url = "https://gogohd.net/";
|
5
5
|
const base_url = "https://animixplay.to";
|
6
|
-
const curl_1 = require("./curl");
|
7
|
-
const regex_1 = require("./regex");
|
6
|
+
const curl_1 = require("./core_utils/curl");
|
7
|
+
const regex_1 = require("./core_utils/regex");
|
8
8
|
async function generate_link(provider, id, player) {
|
9
9
|
let html_ = "";
|
10
10
|
let provider_name = "";
|
@@ -32,6 +32,7 @@ async function generate_link(provider, id, player) {
|
|
32
32
|
return post;
|
33
33
|
case 2:
|
34
34
|
provider_name = 'Animixplay';
|
35
|
+
console.log(`Fetching ${provider_name} links...`);
|
35
36
|
let buffer = new Buffer(id);
|
36
37
|
let enc_id = buffer.toString("base64");
|
37
38
|
buffer = new Buffer(id + "LTXs3GrU8we9O" + enc_id);
|
package/bin/help.js
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.help = void 0;
|
4
|
+
const input_1 = require("./input");
|
5
|
+
const chalk = require("chalk");
|
6
|
+
const helps = [
|
7
|
+
(async () => {
|
8
|
+
console.log(chalk.cyan("Playing anime: \n" +
|
9
|
+
" Search: \n" +
|
10
|
+
" Search for a show/movie. This will search on gogoanime.dk.\n" +
|
11
|
+
" Episode selection: \n" +
|
12
|
+
" Once an anime is selected, select an episode. If there is only 1 episode " +
|
13
|
+
"(in the case of a movie), the episode will be played automatically.\n" +
|
14
|
+
" The episode selected will be played in the video player selected in options. Info on video players can be found in options help."));
|
15
|
+
await help();
|
16
|
+
return;
|
17
|
+
}),
|
18
|
+
(async () => {
|
19
|
+
console.log(chalk.cyan("Downloading anime: \n" +
|
20
|
+
" Search: \n" +
|
21
|
+
" Search for a show/movie. This will search on gogoanime.dk.\n" +
|
22
|
+
" Episode selection: \n" +
|
23
|
+
" Once an anime is selected, select a start episode and an end episode. If there is only 1 episode " +
|
24
|
+
"(in the case of a movie), the episode will be downloaded automatically. Download folder can be changed in options. Default to run location.\n" +
|
25
|
+
" The selected episodes will be downloaded. It is common for episode links to fail to be fetched, when this happens the episode will be passed, then reattempted in another pass.\n" +
|
26
|
+
" Episodes sourced from Animixplay links will download m3u8 file, which you will have difficulty playing, if you are able to at all."));
|
27
|
+
await help();
|
28
|
+
return;
|
29
|
+
}),
|
30
|
+
(async () => {
|
31
|
+
console.log(chalk.cyan("Options: \n" +
|
32
|
+
" Player: \n" +
|
33
|
+
" Player used to play anime.\n" +
|
34
|
+
" Proxy: \n" +
|
35
|
+
" https proxy address and port in form ip:port. This is not currently implemented.\n" +
|
36
|
+
" User agent:\n" +
|
37
|
+
" node-fetch user agent.\n" +
|
38
|
+
" Downloads folder:\n" +
|
39
|
+
" Folder to place downloaded episodes.\n" +
|
40
|
+
" MPV socket connection file:\n" +
|
41
|
+
" File for mpv socket, used to control mpv instance with outside tools.\n" +
|
42
|
+
" VLC socket:\n" +
|
43
|
+
" VLC http control socket\n" +
|
44
|
+
" VLC pass:\n" +
|
45
|
+
" VLC http control password\n" +
|
46
|
+
" W2G api token:\n" +
|
47
|
+
" Your user access token for w2g.tv. Can be found at https://w2g.tv/en/account/edit_user under Tools/API\n"));
|
48
|
+
await help();
|
49
|
+
return;
|
50
|
+
}),
|
51
|
+
(async () => {
|
52
|
+
return;
|
53
|
+
})
|
54
|
+
];
|
55
|
+
async function help() {
|
56
|
+
console.log(chalk.cyan("Help page select: \n"));
|
57
|
+
return helps[await (0, input_1.selection)(["Playing", "Downloading", "Options", "Quit"], ["p", "d", "o", "q"])]();
|
58
|
+
}
|
59
|
+
exports.help = help;
|
package/bin/index.js
CHANGED
@@ -11,10 +11,11 @@ const chalk = require("chalk");
|
|
11
11
|
// Internal
|
12
12
|
const Anime_1 = require("./Anime");
|
13
13
|
const search_anime_1 = require("./search_anime");
|
14
|
-
const load_config_1 = require("./load_config");
|
14
|
+
const load_config_1 = require("./file_managment/load_config");
|
15
15
|
const input_1 = require("./input");
|
16
|
-
const change_config_1 = require("./change_config");
|
16
|
+
const change_config_1 = require("./file_managment/change_config");
|
17
17
|
const download_1 = require("./download");
|
18
|
+
const help_1 = require("./help");
|
18
19
|
const app_data_folder = (0, appdata_path_1.default)();
|
19
20
|
const cache_folder = app_data_folder + "/ani-cli-npm";
|
20
21
|
(0, load_config_1.make_config_dir)(cache_folder, true);
|
@@ -30,8 +31,9 @@ async function main() {
|
|
30
31
|
"Continue",
|
31
32
|
"Download",
|
32
33
|
"Option",
|
34
|
+
"Help",
|
33
35
|
"Quit",
|
34
|
-
], ["s", "c", "d", "o", "q"], ((thing) => { return chalk.magenta(thing); }), ((thing) => { return chalk.magenta(thing); }));
|
36
|
+
], ["s", "c", "d", "o", "h", "q"], ((thing) => { return chalk.magenta(thing); }), ((thing) => { return chalk.magenta(thing); }));
|
35
37
|
switch (choice) {
|
36
38
|
case 0: // Search
|
37
39
|
let temp_ = await (0, search_anime_1.search)();
|
@@ -51,7 +53,7 @@ async function main() {
|
|
51
53
|
episode_number = await (0, input_1.number_input)(anime.episode_list.length, 1, (anime.most_recent != 0) ? ["c"] : [], (anime.most_recent != 0) ? [anime.most_recent + 1] : []);
|
52
54
|
}
|
53
55
|
await anime.play_head(episode_number - 1, config, cache_folder);
|
54
|
-
if (anime.player
|
56
|
+
if (anime.player.hasOwnProperty("quit")) {
|
55
57
|
await anime.player.quit();
|
56
58
|
}
|
57
59
|
await main();
|
@@ -66,7 +68,7 @@ async function main() {
|
|
66
68
|
let continue_anime = new Anime_1.Anime();
|
67
69
|
await continue_anime.init(config.most_recent.anime_id, cache_folder);
|
68
70
|
await continue_anime.play_head(config.most_recent.episode_number, config, cache_folder);
|
69
|
-
if (continue_anime.player
|
71
|
+
if (continue_anime.player.hasOwnProperty("quit")) {
|
70
72
|
await continue_anime.player.quit();
|
71
73
|
}
|
72
74
|
await main();
|
@@ -105,7 +107,10 @@ async function main() {
|
|
105
107
|
}
|
106
108
|
await main();
|
107
109
|
break;
|
108
|
-
case 4:
|
110
|
+
case 4:
|
111
|
+
await (0, help_1.help)();
|
112
|
+
break;
|
113
|
+
case 5: // Quit
|
109
114
|
console.log("Exit");
|
110
115
|
}
|
111
116
|
return 0;
|
package/bin/load_config.js
CHANGED
@@ -59,6 +59,9 @@ function load_config(cache_dir) {
|
|
59
59
|
download_folder: ".",
|
60
60
|
debug_mode: false,
|
61
61
|
mpv_socket_path: "",
|
62
|
+
vlc_socket: 0,
|
63
|
+
vlc_pass: "",
|
64
|
+
w2g_api_key: ""
|
62
65
|
};
|
63
66
|
if (fs.existsSync(cache_dir + "/config.conf")) {
|
64
67
|
// @ts-ignore
|
@@ -87,6 +90,15 @@ function load_config(cache_dir) {
|
|
87
90
|
// @ts-ignore
|
88
91
|
if (tmp.mpv_socket_path !== undefined)
|
89
92
|
config.mpv_socket_path = tmp.mpv_socket_path;
|
93
|
+
// @ts-ignore
|
94
|
+
if (tmp.vlc_socket !== undefined)
|
95
|
+
config.vlc_socket = tmp.vlc_socket;
|
96
|
+
// @ts-ignore
|
97
|
+
if (tmp.vlc_pass !== undefined)
|
98
|
+
config.vlc_pass = tmp.vlc_pass;
|
99
|
+
// @ts-ignore
|
100
|
+
if (tmp.w2g_api_key !== undefined)
|
101
|
+
config.w2g_api_key = tmp.w2g_api_key;
|
90
102
|
}
|
91
103
|
write_config(cache_dir, config);
|
92
104
|
return config;
|
package/bin/search_anime.js
CHANGED
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.search = void 0;
|
7
|
-
const regex_1 = require("./regex");
|
8
|
-
const curl_1 = require("./curl");
|
7
|
+
const regex_1 = require("./core_utils/regex");
|
8
|
+
const curl_1 = require("./core_utils/curl");
|
9
9
|
const input_1 = require("./input");
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
11
11
|
async function search_anime(search) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ani-cli-npm",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.1.1",
|
4
4
|
"description": "ani-cli tool rewritten as npm package",
|
5
5
|
"main": "bin/index.js",
|
6
6
|
"scripts": {
|
@@ -36,7 +36,8 @@
|
|
36
36
|
"node-fetch": "^2.6.6",
|
37
37
|
"open": "^8.4.0",
|
38
38
|
"simple-input": "^1.0.1",
|
39
|
-
"typescript": "^4.9.3"
|
39
|
+
"typescript": "^4.9.3",
|
40
|
+
"w2g-client": "^1.1.0"
|
40
41
|
},
|
41
42
|
"devDependencies": {
|
42
43
|
"@types/node": "^18.11.9"
|