ani-cli-npm 2.0.2 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/Anime.js +48 -13
- package/bin/cache.js +16 -7
- package/bin/change_config.js +3 -0
- package/bin/curl.js +26 -25
- package/bin/download.js +5 -1
- package/bin/index.js +11 -3
- package/bin/input.js +18 -9
- package/bin/search_anime.js +4 -0
- package/package.json +3 -4
package/bin/Anime.js
CHANGED
@@ -11,24 +11,41 @@ const open = require("open");
|
|
11
11
|
const PlayerController = require("media-player-controller");
|
12
12
|
const dl = require("download-file-with-progressbar");
|
13
13
|
const chalk = require("chalk");
|
14
|
-
// const gogohd_url="https://gogohd.net/"
|
15
|
-
const base_url = "https://animixplay.to";
|
16
14
|
class Anime {
|
15
|
+
/*
|
16
|
+
Class for handling a show/film
|
17
|
+
|
18
|
+
Stores anime dpage links assigned with anime_id.
|
19
|
+
|
20
|
+
Initialised with Anime.init()
|
21
|
+
|
22
|
+
*/
|
17
23
|
id = "";
|
18
24
|
episode_list = [];
|
19
25
|
player = 0;
|
20
26
|
async init(anime_id, cache_folder) {
|
27
|
+
/*
|
28
|
+
Initiate Anime object
|
29
|
+
|
30
|
+
Will first search cache folder for cache file (this will contain id and dpage links)
|
31
|
+
|
32
|
+
If no cache is found, it will use get_ep_bases(anime_id) to get links. (Webscrapes from animixplay.to), then creates cache
|
33
|
+
|
34
|
+
anime_id:
|
35
|
+
*/
|
21
36
|
let cache_object = (0, cache_1.search_cache)(cache_folder, anime_id);
|
37
|
+
console.log(cache_object);
|
22
38
|
this.id = anime_id;
|
23
39
|
if (cache_object == 0) {
|
24
|
-
await this.
|
40
|
+
await this.get_ep_bases(this.id);
|
41
|
+
(0, cache_1.new_cache)(cache_folder, this);
|
25
42
|
}
|
26
43
|
else {
|
27
44
|
try {
|
28
45
|
this.episode_list = cache_object.episode_list;
|
29
46
|
}
|
30
47
|
catch {
|
31
|
-
await this.
|
48
|
+
await this.get_ep_bases(this.id);
|
32
49
|
}
|
33
50
|
}
|
34
51
|
return 0;
|
@@ -49,8 +66,12 @@ class Anime {
|
|
49
66
|
}
|
50
67
|
return link;
|
51
68
|
}
|
52
|
-
async
|
53
|
-
|
69
|
+
async get_ep_bases(anime_id) {
|
70
|
+
/*
|
71
|
+
Scrapes animixplay.to for dpage links.
|
72
|
+
returns array with all dpage links
|
73
|
+
*/
|
74
|
+
let html = (await ((0, curl_1.curl)("https://animixplay.to/v1/" + anime_id))).split("\n"); //POTENTIAL BREAK POINT. animixplay.to may change domain address
|
54
75
|
let lines = "";
|
55
76
|
for (let x in html) {
|
56
77
|
if ((0, regex_1.RegexParse)(html[x], "*<div id=\"epslistplace\"*")) {
|
@@ -65,6 +86,20 @@ class Anime {
|
|
65
86
|
}
|
66
87
|
}
|
67
88
|
async play_head(episode, config, config_dir) {
|
89
|
+
/*
|
90
|
+
# Starts play cascade.
|
91
|
+
|
92
|
+
## Takes in:
|
93
|
+
### Episode number, counding from 0
|
94
|
+
### Config object
|
95
|
+
### Config save directory
|
96
|
+
|
97
|
+
- If config.player is set to MPV or VLC, it will use the media-player-controller package.
|
98
|
+
|
99
|
+
- If set to Browser, it will use the "open" packer.
|
100
|
+
|
101
|
+
- If set to Link, it will simply print the media stream link to console, primarily for debuting peruses.
|
102
|
+
*/
|
68
103
|
console.clear();
|
69
104
|
console.log(`Playing ${this.id} episode ${episode + 1}`);
|
70
105
|
switch (config.player) {
|
@@ -148,6 +183,10 @@ class Anime {
|
|
148
183
|
}
|
149
184
|
}
|
150
185
|
async play(episode, config, config_dir) {
|
186
|
+
/*
|
187
|
+
# Continues play cascade
|
188
|
+
## Continues on from play_head()
|
189
|
+
*/
|
151
190
|
console.clear();
|
152
191
|
console.log(`Playing ${this.id} episode ${episode + 1}`);
|
153
192
|
if (this.player == 0) {
|
@@ -217,6 +256,9 @@ class Anime {
|
|
217
256
|
}
|
218
257
|
}
|
219
258
|
async download(episode, download_folder) {
|
259
|
+
/*
|
260
|
+
## Downloads an episode (counting from 0) to download_folder, with progress bar.
|
261
|
+
*/
|
220
262
|
// @ts-ignore
|
221
263
|
let ep_link = await this.get_episode_link(episode);
|
222
264
|
let file_name = `${this.id}-${episode + 1}.mp4`;
|
@@ -246,12 +288,5 @@ class Anime {
|
|
246
288
|
//console.log((`${option.dir}/${option.filename}`))
|
247
289
|
return await dl(ep_link, option);
|
248
290
|
}
|
249
|
-
async bulk_download(start_episode, end_episode, download_folder) {
|
250
|
-
let downloaders = [];
|
251
|
-
for (let episode = start_episode; episode <= end_episode; episode++) {
|
252
|
-
downloaders.push(await this.download(episode, download_folder));
|
253
|
-
}
|
254
|
-
return await Promise.all(downloaders);
|
255
|
-
}
|
256
291
|
}
|
257
292
|
exports.Anime = Anime;
|
package/bin/cache.js
CHANGED
@@ -39,24 +39,33 @@ function clear_cache(location, show) {
|
|
39
39
|
}
|
40
40
|
}
|
41
41
|
exports.clear_cache = clear_cache;
|
42
|
-
function new_cache(location, anime
|
42
|
+
function new_cache(location, anime) {
|
43
|
+
/*
|
44
|
+
Creates cache of Anime object, in cache file.
|
45
|
+
*/
|
43
46
|
try {
|
44
47
|
fs.writeFileSync(location + "/" + anime.id + ".cache", JSON.stringify(anime));
|
45
48
|
}
|
46
49
|
catch {
|
47
|
-
|
48
|
-
console.log("Failed to write to cache");
|
49
|
-
}
|
50
|
+
console.log("Failed to write to cache");
|
50
51
|
}
|
51
52
|
}
|
52
53
|
exports.new_cache = new_cache;
|
53
54
|
function get_cache(location, anime_id) {
|
55
|
+
/*
|
56
|
+
## Get cache by anime_id. Does not check if the cache exists.
|
57
|
+
*/
|
54
58
|
return JSON.parse(fs.readFileSync(location + "/" + anime_id + ".cache").toString());
|
55
59
|
}
|
56
|
-
function search_cache(
|
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
|
+
*/
|
57
66
|
try {
|
58
|
-
if (check_cache(
|
59
|
-
return get_cache(
|
67
|
+
if (check_cache(cache_folder, anime_id)) {
|
68
|
+
return get_cache(cache_folder, anime_id);
|
60
69
|
}
|
61
70
|
return false;
|
62
71
|
}
|
package/bin/change_config.js
CHANGED
@@ -4,6 +4,9 @@ exports.config_ = void 0;
|
|
4
4
|
const chalk = require("chalk");
|
5
5
|
const input_1 = require("./input");
|
6
6
|
async function config_(temp) {
|
7
|
+
/*
|
8
|
+
## Lets user change a single attribute of config. Returns new config object, and an exit code
|
9
|
+
*/
|
7
10
|
console.clear();
|
8
11
|
console.log(chalk.blue("ANI-CLI-NPM \n"));
|
9
12
|
console.log(chalk.yellow("Config:\n"));
|
package/bin/curl.js
CHANGED
@@ -2,33 +2,34 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.curl = void 0;
|
4
4
|
const fetch = require("node-fetch");
|
5
|
+
const chalk = require("chalk");
|
5
6
|
async function curl(url, method = "GET", redirect = false) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
+
}
|
25
29
|
}
|
26
|
-
|
27
|
-
|
30
|
+
catch {
|
31
|
+
console.log(chalk.red("Something went wrong in curl()"));
|
32
|
+
process.exit();
|
28
33
|
}
|
29
|
-
/*}catch{
|
30
|
-
console.log(colors.Red, "Something went wrong in curl()")
|
31
|
-
await main()
|
32
|
-
}*/
|
33
34
|
}
|
34
35
|
exports.curl = curl;
|
package/bin/download.js
CHANGED
@@ -12,7 +12,11 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
12
12
|
async function download(cache_folder, config) {
|
13
13
|
try {
|
14
14
|
console.clear();
|
15
|
-
let
|
15
|
+
let temp_ = await (0, search_anime_1.search)();
|
16
|
+
if (temp_ == 1) {
|
17
|
+
return 2;
|
18
|
+
}
|
19
|
+
let download_id = temp_;
|
16
20
|
let download = new Anime_1.Anime();
|
17
21
|
await download.init(download_id, cache_folder);
|
18
22
|
let start_ep_number;
|
package/bin/index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
#!/usr/bin/env node
|
1
2
|
"use strict";
|
2
|
-
// process.removeAllListeners() // Ignore warning
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
5
|
};
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
process.removeAllListeners(); // Ignore warning
|
7
8
|
// External
|
8
9
|
const appdata_path_1 = __importDefault(require("appdata-path"));
|
9
10
|
const chalk = require("chalk");
|
@@ -33,7 +34,12 @@ async function main() {
|
|
33
34
|
], ["s", "c", "d", "o", "q"], ((thing) => { return chalk.magenta(thing); }), ((thing) => { return chalk.magenta(thing); }));
|
34
35
|
switch (choice) {
|
35
36
|
case 0: // Search
|
36
|
-
let
|
37
|
+
let temp_ = await (0, search_anime_1.search)();
|
38
|
+
if (temp_ == 1) {
|
39
|
+
await main();
|
40
|
+
process.exit();
|
41
|
+
}
|
42
|
+
let anime_id = temp_;
|
37
43
|
let anime = new Anime_1.Anime();
|
38
44
|
await anime.init(anime_id, cache_folder);
|
39
45
|
let episode_number;
|
@@ -58,7 +64,9 @@ async function main() {
|
|
58
64
|
let continue_anime = new Anime_1.Anime();
|
59
65
|
await continue_anime.init(config.most_recent.anime_id, cache_folder);
|
60
66
|
await continue_anime.play_head(config.most_recent.episode_number, config, cache_folder);
|
61
|
-
|
67
|
+
if (continue_anime.player != 0 && continue_anime.player != 1) {
|
68
|
+
await continue_anime.player.quit();
|
69
|
+
}
|
62
70
|
await main();
|
63
71
|
break;
|
64
72
|
case 2: // Download
|
package/bin/input.js
CHANGED
@@ -7,6 +7,24 @@ exports.number_input = exports.input = exports.selection = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
8
8
|
const _prompt = require("simple-input");
|
9
9
|
async function selection(options, extra_options = [], color1 = ((thing) => { return chalk_1.default.yellow(thing); }), color2 = ((thing) => { return chalk_1.default.green(thing); })) {
|
10
|
+
/*
|
11
|
+
selection(options, extra_options, color1, color2)
|
12
|
+
|
13
|
+
Gives use prompt to choose from a list of options. Either by inputting a number ranging from 1, to the length of the list. Or by inputting a letter (non-caps-sensitive) relating to the option.
|
14
|
+
|
15
|
+
|
16
|
+
- options: array of options; e.g. ["play", "download", "continue", "quit"] REQUIRED
|
17
|
+
|
18
|
+
|
19
|
+
- extra_options: array of characters as alternatives to numbers (both will be displayed). e.g. ["p", "d", "c", "q"].
|
20
|
+
|
21
|
+
default: []
|
22
|
+
|
23
|
+
- color1 and color2: functions that will dictate what 2 colors the options with alternate between (option1 will be color1, option2;color2, option3;color1, etc).
|
24
|
+
recommended for this function to return a chalk.____() parsed string.
|
25
|
+
|
26
|
+
default: ((thing:string) => {return chalk.yellow(thing)}) and ((thing:string) => {return chalk.green(thing)})
|
27
|
+
*/
|
10
28
|
let color = true;
|
11
29
|
for (let x in options) {
|
12
30
|
if (color) {
|
@@ -57,12 +75,3 @@ async function number_input(max, min = 1) {
|
|
57
75
|
return selection;
|
58
76
|
}
|
59
77
|
exports.number_input = number_input;
|
60
|
-
async function number_input_range(max, min = 1) {
|
61
|
-
let selection;
|
62
|
-
do {
|
63
|
-
selection = await _prompt(">");
|
64
|
-
if (!(min <= parseInt(selection[0]) && parseInt(selection[0]) <= max)) {
|
65
|
-
console.log(chalk_1.default.red("Invalid choice."));
|
66
|
-
}
|
67
|
-
} while (!(min <= parseInt(selection[0]) && parseInt(selection[0]) <= max));
|
68
|
-
}
|
package/bin/search_anime.js
CHANGED
@@ -30,6 +30,10 @@ async function search() {
|
|
30
30
|
console.log(chalk_1.default.magenta("Search..."));
|
31
31
|
let _selection = await (0, input_1.input)();
|
32
32
|
let results = await search_anime(_selection);
|
33
|
+
if (results[0] === undefined) {
|
34
|
+
console.log(chalk_1.default.red("No results found."));
|
35
|
+
return 1;
|
36
|
+
}
|
33
37
|
return results[await (0, input_1.selection)(results)];
|
34
38
|
}
|
35
39
|
exports.search = search;
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "ani-cli-npm",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.4",
|
4
4
|
"description": "ani-cli tool rewritten as npm package",
|
5
5
|
"main": "bin/index.js",
|
6
6
|
"scripts": {
|
7
7
|
"build": "tsc",
|
8
|
-
"start": "node
|
8
|
+
"start": "node bin/index.js"
|
9
9
|
},
|
10
10
|
"repository": {
|
11
11
|
"type": "git",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"author": "bumpkin-pi",
|
26
26
|
"license": "ISC",
|
27
27
|
"bin": {
|
28
|
-
"
|
28
|
+
"ani-cli-npm": "/bin/index.js"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
31
|
"@types/node-fetch": "^2.6.2",
|
@@ -35,7 +35,6 @@
|
|
35
35
|
"media-player-controller": "^1.5.3",
|
36
36
|
"node-fetch": "^2.6.6",
|
37
37
|
"open": "^8.4.0",
|
38
|
-
"persistent-cache": "^0.1.0",
|
39
38
|
"simple-input": "^1.0.1",
|
40
39
|
"typescript": "^4.9.3"
|
41
40
|
},
|