ani-cli-npm 2.1.1 → 2.1.3

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/Anime.js CHANGED
@@ -24,8 +24,14 @@ class Anime {
24
24
  id = "";
25
25
  episode_list = [];
26
26
  most_recent = 0;
27
- player = 0;
27
+ player = new class {
28
+ play(episode_link) {
29
+ return {};
30
+ }
31
+ player;
32
+ };
28
33
  current_pos = 0;
34
+ current_episode = 0;
29
35
  async init(anime_id, cache_folder) {
30
36
  /*
31
37
  Initiate Anime object
@@ -100,7 +106,7 @@ class Anime {
100
106
  let json = JSON.parse(lines);
101
107
  for (const value of Object.entries(json)) {
102
108
  if (typeof value[1] == "string") {
103
- this.episode_list.push(value[1]);
109
+ this.episode_list.push(value[1].replace("//gogohd.net/streaming.php?id=", ""));
104
110
  }
105
111
  }
106
112
  }
@@ -109,7 +115,7 @@ class Anime {
109
115
  # Starts play cascade.
110
116
 
111
117
  ## Takes in:
112
- ### Episode number, counding from 0
118
+ ### Episode number, counting from 0
113
119
  ### Config object
114
120
  ### Config save directory
115
121
 
@@ -120,115 +126,174 @@ class Anime {
120
126
  - If set to Link, it will simply print the media stream link to console, primarily for debuting peruses.
121
127
  */
122
128
  console.clear();
123
- console.log(`Playing ${this.id} episode ${episode + 1} from ${new Date(this.current_pos * 1000).toISOString().slice(11, 19)}`);
129
+ console.log(`Playing ${this.id} episode ${episode + 1}`); // from ${new Date(this.current_pos * 1000).toISOString().slice(11, 19)}`)
130
+ if (this.current_pos != 0) {
131
+ console.log(`Most recent position: ${new Date(this.current_pos * 1000).toISOString().slice(11, 19)}`);
132
+ }
124
133
  switch (config.player) {
125
134
  case "MPV":
126
135
  console.log(("Opening MPV.."));
127
- this.player = await new PlayerController({
136
+ this.player.player = await new PlayerController({
128
137
  app: 'mpv',
129
- args: ['--fullscreen', '--keep-open=yes', `--start=+${this.current_pos}`],
138
+ args: ['--fullscreen', '--keep-open=yes'],
130
139
  media: await this.get_episode_link(episode, config.player),
131
140
  ipcPath: config.mpv_socket_path
132
141
  });
142
+ this.player.play = (async (episode_link) => {
143
+ this.player.player.load(episode_link);
144
+ });
145
+ this.player.player.on('playback', (data) => {
146
+ if (data.name == "time-pos" && data.value >= 0) {
147
+ this.current_pos = data.value;
148
+ }
149
+ //console.log(data)
150
+ });
151
+ this.player.player.on('app-exit', (code) => {
152
+ config.most_recent.anime_id = this.id;
153
+ config.most_recent.episode_number = episode;
154
+ config.most_recent.episode_second = this.current_pos;
155
+ (0, load_config_1.write_config)(config_dir, config);
156
+ this.most_recent = episode;
157
+ (0, cache_1.new_cache)(config_dir, {
158
+ id: this.id,
159
+ episode_list: this.episode_list,
160
+ most_recent: this.most_recent,
161
+ position: this.current_pos
162
+ });
163
+ });
133
164
  // @ts-ignore
134
- await this.player.launch(err => {
165
+ await this.player.player.launch(err => {
135
166
  if (err)
136
167
  return console.error(err.message);
137
168
  });
138
169
  break;
139
170
  case "VLC":
140
171
  console.log(("Opening VLC.."));
141
- this.player = await new PlayerController({
172
+ this.player.player = await new PlayerController({
142
173
  app: 'vlc',
143
- args: ['--fullscreen', `--start-time ${this.current_pos}`],
174
+ args: ['--fullscreen'],
144
175
  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)
176
+ //httpPort: (config.vlc_socket !== 0)? config.vlc_socket : null,
146
177
  //httpPass: (config.vlc_pass !== "")? config.vlc_socket : null,
147
178
  });
148
179
  // @ts-ignore
149
- await this.player.launch(err => {
180
+ await this.player.player.launch(err => {
150
181
  if (err)
151
182
  return console.error(err.message);
152
183
  });
184
+ this.player.play = (async (episode_link) => {
185
+ this.player.player.quit();
186
+ this.player.player = await new PlayerController({
187
+ app: 'vlc',
188
+ args: ['--fullscreen'],
189
+ media: episode_link
190
+ //httpPort: (config.vlc_socket !== 0)? config.vlc_socket : null,
191
+ //httpPass: (config.vlc_pass !== "")? config.vlc_socket : null,
192
+ });
193
+ this.player.player.on('playback', (data) => {
194
+ if (data.name == "time-pos" && data.value >= 0) {
195
+ this.current_pos = data.value;
196
+ }
197
+ //console.log(data)
198
+ });
199
+ this.player.player.on('app-exit', (code) => {
200
+ config.most_recent.anime_id = this.id;
201
+ config.most_recent.episode_number = episode;
202
+ config.most_recent.episode_second = this.current_pos;
203
+ (0, load_config_1.write_config)(config_dir, config);
204
+ this.most_recent = episode;
205
+ (0, cache_1.new_cache)(config_dir, {
206
+ id: this.id,
207
+ episode_list: this.episode_list,
208
+ most_recent: this.most_recent,
209
+ position: this.current_pos
210
+ });
211
+ });
212
+ // @ts-ignore
213
+ await this.player.player.launch(err => {
214
+ if (err)
215
+ return console.error(err.message);
216
+ });
217
+ });
153
218
  break;
154
219
  case "BROWSER":
220
+ this.player.play = (async (episode_link) => {
221
+ console.log(("Opening browser..."));
222
+ await open(episode_link);
223
+ });
155
224
  console.log(("Opening browser..."));
156
225
  await open(await this.get_episode_link(episode, config.player));
157
226
  break;
158
227
  case "W2G":
159
228
  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()));
229
+ this.player.player = new W2GClient.W2GClient(config.w2g_api_key);
230
+ await this.player.player.create(await this.get_episode_link(episode, config.player));
231
+ console.log(chalk.green("Room link: " + await this.player.player.getLink()));
163
232
  }
164
233
  catch {
165
234
  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
235
  process.exit();
167
236
  }
168
- await open(await this.player.getLink());
237
+ this.player.play = (async (episode_link) => {
238
+ console.log(("Updating W2G room..."));
239
+ console.log(chalk.green("Room link: " + await this.player.player.getLink()));
240
+ try {
241
+ await this.player.player.update(episode_link);
242
+ }
243
+ catch {
244
+ console.log(chalk.red("Error updating W2G room. Very sorry, w2g functionality is a bit broken at present. Worst case you should be able to just restart with a new room for each episode."));
245
+ }
246
+ });
247
+ console.log("Opening W2G.tv...");
248
+ await open(await this.player.player.getLink());
169
249
  break;
170
250
  case "LINK":
171
- this.player = 1;
172
- console.log(await this.get_episode_link(episode, config.player));
173
- break;
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
251
+ this.player.play = (async (episode_link) => {
252
+ console.log(chalk.green(episode_link));
192
253
  });
193
- });
254
+ this.player.play(await this.get_episode_link(episode));
255
+ break;
194
256
  }
195
- await this.play(episode, config, config_dir, true);
257
+ await this.play_controller(episode, config, config_dir, true);
196
258
  }
197
- async play(episode, config, config_dir, first = false) {
198
- /*
199
- # Continues play cascade
200
- ## Continues on from play_head()
201
- */
202
- if (!first) {
203
- console.clear();
204
- console.log(chalk.blue(`Playing ${this.id} episode ${episode + 1}`));
205
- if (this.player == 0) {
206
- await open(await this.get_episode_link(episode, "BROWSER"));
207
- }
208
- else if (this.player == 1) {
209
- console.log(await this.get_episode_link(episode));
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
- }
215
- else if (this.player.opts.app == "mpv") {
216
- await this.player.load(await this.get_episode_link(episode));
217
- }
218
- else {
219
- this.player.quit();
220
- this.player = await new PlayerController({
221
- app: 'vlc',
222
- args: ['--fullscreen'],
223
- media: await this.get_episode_link(episode, config.player)
224
- });
225
- // @ts-ignore
226
- await this.player.launch(err => {
227
- if (err)
228
- return console.error(err.message);
229
- });
230
- }
231
- }
259
+ async next(player) {
260
+ this.current_episode += 1;
261
+ this.current_pos = 0;
262
+ this.player.play(await this.get_episode_link(this.current_episode, player));
263
+ }
264
+ async previous(player) {
265
+ this.current_episode -= 1;
266
+ this.current_pos = 0;
267
+ this.player.play(await this.get_episode_link(this.current_episode, player));
268
+ }
269
+ async play_controller(episode, config, config_dir, first = false) {
270
+ console.log(`Playing ${this.id} episode ${episode + 1}`); // from ${new Date(this.current_pos * 1000).toISOString().slice(11, 19)}`)
271
+ // if (!first){
272
+ // console.clear()
273
+ // console.log(chalk.blue(`Playing ${this.id} episode ${episode+1}`))
274
+ // if (this.player == 0){
275
+ // await open(await this.get_episode_link(episode, "BROWSER"))
276
+ // }else if(this.player == 1){
277
+ // console.log(await this.get_episode_link(episode))
278
+ // } else if (this.player.roomID != undefined){
279
+ // console.log(chalk.green("Room link: "+ await this.player.getLink()));
280
+ // this.player.update(await this.get_episode_link(episode))
281
+ // } else if (this.player.opts.app == "mpv"){
282
+ // await this.player.load(await this.get_episode_link(episode))
283
+ // }else{
284
+ // this.player.quit()
285
+ // this.player = await new PlayerController({
286
+ // app: 'vlc',
287
+ // args: ['--fullscreen'],
288
+ // media: await this.get_episode_link(episode, config.player)
289
+ // });
290
+ // // @ts-ignore
291
+ // await this.player.launch(err => {
292
+ // if (err) return console.error(err.message);
293
+ // });
294
+ // }
295
+ // }
296
+ this.current_episode = episode;
232
297
  config.most_recent.anime_id = this.id;
233
298
  config.most_recent.episode_number = episode;
234
299
  config.most_recent.episode_second = this.current_pos;
@@ -252,25 +317,31 @@ class Anime {
252
317
  switch (selected) {
253
318
  case 0:
254
319
  if (episode >= this.episode_list.length - 1) {
255
- await this.play(episode - 1, config, config_dir);
320
+ await this.next(config.player);
321
+ await this.play_controller(episode - 1, config, config_dir);
256
322
  }
257
323
  else {
258
- await this.play(episode + 1, config, config_dir);
324
+ await this.next(config.player);
325
+ await this.play_controller(episode + 1, config, config_dir);
259
326
  }
260
327
  break;
261
328
  case 1:
262
329
  if ((episode >= this.episode_list.length - 1) || (episode <= 0)) {
263
330
  break;
264
331
  }
265
- await this.play(episode - 1, config, config_dir);
332
+ await this.previous(config.player);
333
+ await this.play_controller(episode - 1, config, config_dir);
266
334
  break;
267
335
  case 2:
268
336
  if (this.episode_list.length == 1) {
269
- await this.play(0, config, config_dir);
337
+ this.player.play(await this.get_episode_link(0, config.player));
338
+ await this.play_controller(0, config, config_dir);
270
339
  }
271
340
  else {
272
341
  console.log(`Select episode [1-${this.episode_list.length}]`);
273
- await this.play(await (0, input_1.number_input)(this.episode_list.length, 1) - 1, config, config_dir);
342
+ let episode = await (0, input_1.number_input)(this.episode_list.length, 1) - 1;
343
+ this.player.play(await this.get_episode_link(episode, config.player));
344
+ await this.play_controller(episode, config, config_dir);
274
345
  }
275
346
  break;
276
347
  case 3:
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -22,21 +22,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.search_cache = exports.new_cache = exports.clear_cache = void 0;
27
30
  const fs = __importStar(require("fs"));
28
- function clear_cache(location, show) {
31
+ const chalk_1 = __importDefault(require("chalk"));
32
+ async function clear_cache(location) {
29
33
  try {
30
- console.log("ye sorry that doesnt exist yet.");
31
- if (show) {
32
- console.log("Cleared cache");
33
- }
34
+ await fs.readdir(location, (err, files) => {
35
+ if (err)
36
+ throw err;
37
+ for (const file of files) {
38
+ if (file.includes(".cache")) {
39
+ fs.unlinkSync(location + "/" + file);
40
+ }
41
+ }
42
+ });
34
43
  }
35
44
  catch {
36
- if (show) {
37
- console.log("Failed to clear cache.");
38
- }
45
+ console.log(chalk_1.default.red("Error clearing cache."));
39
46
  }
47
+ return 0;
40
48
  }
41
49
  exports.clear_cache = clear_cache;
42
50
  function new_cache(location, anime) {
@@ -63,6 +63,27 @@ const configs = [
63
63
  // @ts-ignore
64
64
  return temp, 0;
65
65
  }),
66
+ (async (temp) => {
67
+ let config = {
68
+ player: "BROWSER",
69
+ proxy: "",
70
+ user_agent: "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
71
+ most_recent: {
72
+ episode_number: 0,
73
+ episode_second: 0,
74
+ anime_id: ""
75
+ },
76
+ download_folder: ".",
77
+ debug_mode: false,
78
+ mpv_socket_path: "",
79
+ vlc_socket: 0,
80
+ vlc_pass: "",
81
+ w2g_api_key: ""
82
+ };
83
+ console.log(config);
84
+ // @ts-ignore
85
+ return config, 0;
86
+ }),
66
87
  (async (temp) => {
67
88
  // @ts-ignore
68
89
  return temp, 1;
@@ -92,6 +113,7 @@ async function config_(temp) {
92
113
  "VLC socket; " + temp.vlc_socket,
93
114
  "VLC pass; " + temp.vlc_pass,
94
115
  "W2G api token: " + temp.w2g_api_key,
116
+ "Reset to defaults",
95
117
  "Save and exit",
96
118
  "Exit without saving"
97
119
  ], [], ((item) => { return chalk.cyan(item); }), ((item) => { return chalk.cyan(item); }))](temp);
package/bin/index.js CHANGED
@@ -1,10 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
3
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
28
  };
6
29
  Object.defineProperty(exports, "__esModule", { value: true });
7
- process.removeAllListeners(); // Ignore warning
30
+ const process = __importStar(require("process"));
31
+ //process.removeAllListeners() // Ignore warning
8
32
  // External
9
33
  const appdata_path_1 = __importDefault(require("appdata-path"));
10
34
  const chalk = require("chalk");
@@ -14,6 +38,7 @@ const search_anime_1 = require("./search_anime");
14
38
  const load_config_1 = require("./file_managment/load_config");
15
39
  const input_1 = require("./input");
16
40
  const change_config_1 = require("./file_managment/change_config");
41
+ const cache_1 = require("./file_managment/cache");
17
42
  const download_1 = require("./download");
18
43
  const help_1 = require("./help");
19
44
  const app_data_folder = (0, appdata_path_1.default)();
@@ -31,9 +56,10 @@ async function main() {
31
56
  "Continue",
32
57
  "Download",
33
58
  "Option",
59
+ "Clear cache",
34
60
  "Help",
35
61
  "Quit",
36
- ], ["s", "c", "d", "o", "h", "q"], ((thing) => { return chalk.magenta(thing); }), ((thing) => { return chalk.magenta(thing); }));
62
+ ], ["s", "c", "d", "o", " ", "h", "q"], ((thing) => { return chalk.magenta(thing); }), ((thing) => { return chalk.magenta(thing); }));
37
63
  switch (choice) {
38
64
  case 0: // Search
39
65
  let temp_ = await (0, search_anime_1.search)();
@@ -46,7 +72,7 @@ async function main() {
46
72
  await anime.init(anime_id, cache_folder);
47
73
  let episode_number;
48
74
  if (anime.episode_list.length == 1) {
49
- episode_number = 0;
75
+ episode_number = 1;
50
76
  }
51
77
  else {
52
78
  console.log(`Select episode [1-${anime.episode_list.length}] ${(anime.most_recent != 0) ? `Or C to continue from ep${anime.most_recent + 1}` : ""}`);
@@ -54,7 +80,7 @@ async function main() {
54
80
  }
55
81
  await anime.play_head(episode_number - 1, config, cache_folder);
56
82
  if (anime.player.hasOwnProperty("quit")) {
57
- await anime.player.quit();
83
+ await anime.player.player.quit();
58
84
  }
59
85
  await main();
60
86
  break;
@@ -68,9 +94,10 @@ async function main() {
68
94
  let continue_anime = new Anime_1.Anime();
69
95
  await continue_anime.init(config.most_recent.anime_id, cache_folder);
70
96
  await continue_anime.play_head(config.most_recent.episode_number, config, cache_folder);
71
- if (continue_anime.player.hasOwnProperty("quit")) {
72
- await continue_anime.player.quit();
97
+ try {
98
+ await continue_anime.player.player.quit();
73
99
  }
100
+ catch { }
74
101
  await main();
75
102
  break;
76
103
  case 2: // Download
@@ -108,9 +135,22 @@ async function main() {
108
135
  await main();
109
136
  break;
110
137
  case 4:
138
+ console.clear();
139
+ console.log(chalk.yellow("Warning, this will also clear your current position in each anime, are you sure you want to do this?"));
140
+ if (await (0, input_1.selection)(["yes", "no"], ["y", "n"]) == 0) {
141
+ await (0, cache_1.clear_cache)(cache_folder);
142
+ console.clear();
143
+ console.log(chalk.grey("Cache cleared"));
144
+ }
145
+ else {
146
+ console.clear();
147
+ }
148
+ await main();
149
+ break;
150
+ case 5:
111
151
  await (0, help_1.help)();
112
152
  break;
113
- case 5: // Quit
153
+ case 6: // Quit
114
154
  console.log("Exit");
115
155
  }
116
156
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ani-cli-npm",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "ani-cli tool rewritten as npm package",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {