ani-cli-npm 1.4.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/curl.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.curl = void 0;
4
+ const fetch = require("node-fetch");
5
+ async function curl(url, method = "GET", redirect = false) {
6
+ //try{
7
+ let response = await fetch(url, {
8
+ //"agent": proxyAgent,
9
+ "headers": {
10
+ 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0',
11
+ "X-Requested-With": "XMLHttpRequest"
12
+ },
13
+ "referrerPolicy": "origin",
14
+ "body": null,
15
+ "method": method,
16
+ "redirect": 'follow',
17
+ // "follow": 10,
18
+ }); /*.catch(async function(err) {
19
+ console.warn(colors.Red, `Something went wrong connecting to ${url}.`);
20
+ await search();
21
+ process.exit()
22
+ })*/
23
+ if (redirect) {
24
+ return response.url;
25
+ }
26
+ else {
27
+ return await response.text();
28
+ }
29
+ /*}catch{
30
+ console.log(colors.Red, "Something went wrong in curl()")
31
+ await main()
32
+ }*/
33
+ }
34
+ exports.curl = curl;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.download = void 0;
7
+ const search_anime_1 = require("./search_anime");
8
+ const Anime_1 = require("./Anime");
9
+ const input_1 = require("./input");
10
+ const libs_1 = require("./libs");
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ async function download(cache_folder, config) {
13
+ try {
14
+ console.clear();
15
+ let download_id = await (0, search_anime_1.search)();
16
+ let download = new Anime_1.Anime();
17
+ await download.init(download_id, cache_folder);
18
+ let start_ep_number;
19
+ let end_ep_number;
20
+ if (download.episode_list.length <= 1) {
21
+ start_ep_number = 1;
22
+ end_ep_number = 0;
23
+ }
24
+ else {
25
+ console.log(`Select start episode [1-${download.episode_list.length}]`);
26
+ start_ep_number = await (0, input_1.number_input)(download.episode_list.length);
27
+ console.log(`Select end episode [${start_ep_number}-${download.episode_list.length}]`);
28
+ end_ep_number = await (0, input_1.number_input)(download.episode_list.length, start_ep_number) - 1;
29
+ }
30
+ let to_do = (0, libs_1.range)(start_ep_number, end_ep_number + 1);
31
+ do {
32
+ for (let x in to_do) {
33
+ try {
34
+ await download.download(to_do[x] - 1, config.download_folder);
35
+ to_do.splice(Number(x), 1);
36
+ }
37
+ catch {
38
+ console.log(chalk_1.default.red("Failed to download episode " + to_do[x]));
39
+ }
40
+ }
41
+ if (to_do[0] !== undefined) { //TODO fix buggy downloads
42
+ console.log(chalk_1.default.red("Failed to download episodes: " + to_do) + "\nRetrying...");
43
+ }
44
+ } while (to_do[0] !== undefined);
45
+ }
46
+ catch {
47
+ return 1;
48
+ }
49
+ return 0;
50
+ }
51
+ exports.download = download;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate_link = void 0;
4
+ const gogohd_url = "https://gogohd.net/";
5
+ const base_url = "https://animixplay.to";
6
+ const curl_1 = require("./curl");
7
+ const regex_1 = require("./regex");
8
+ async function generate_link(provider, id, player) {
9
+ let html_ = "";
10
+ let provider_name = "";
11
+ switch (provider) {
12
+ case 1:
13
+ html_ = await (0, curl_1.curl)(`${gogohd_url}streaming.php?id=${id}`);
14
+ provider_name = 'Xstreamcdn';
15
+ console.log(`Fetching ${provider_name} links...`);
16
+ let html = html_.split("\n");
17
+ let fb_id = "";
18
+ for (let x in html) {
19
+ if ((0, regex_1.RegexParse)(html[x], "*<li class=\"linkserver\" data-status=\"1\" data-video=\"https://fembed9hd.com/v/*")) {
20
+ fb_id = html[x].slice(html[x].indexOf("/v/") + 3, html[x].indexOf("\">X"));
21
+ break;
22
+ }
23
+ }
24
+ if (!fb_id) {
25
+ console.log("Error, no fb_id found.");
26
+ return 0;
27
+ }
28
+ //let refr = "https://fembed-hd.com/v/"+fb_id
29
+ let post = await (0, curl_1.curl)("https://fembed-hd.com/api/source/" + fb_id, "POST");
30
+ post = post.slice(post.indexOf(",\"data\":[{\"file\":\"") + 18, post.length);
31
+ post = post.slice(0, post.indexOf("\"")).replaceAll("\\/", "/");
32
+ return post;
33
+ case 2:
34
+ provider_name = 'Animixplay';
35
+ let buffer = new Buffer(id);
36
+ let enc_id = buffer.toString("base64");
37
+ buffer = new Buffer(id + "LTXs3GrU8we9O" + enc_id);
38
+ let ani_id = buffer.toString("base64");
39
+ buffer = Buffer.from((await (0, curl_1.curl)(`${base_url}/api/live${ani_id}`, "GET", true)).split("#")[1], "base64");
40
+ if (player === "BROWSER") {
41
+ return `${base_url}/api/live${ani_id}`;
42
+ }
43
+ return buffer.toString("utf-8");
44
+ }
45
+ }
46
+ exports.generate_link = generate_link;