@irfanshadikrishad/anilist 1.2.0-forbidden.1 → 1.2.0-forbidden.6

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.
@@ -1,4 +1,4 @@
1
- import { MALAnimeStatus, MALMangaStatus, MediaWithProgress } from "./types.js";
1
+ import { DateMonthYear, MALAnimeStatus, MALMangaStatus, MediaWithProgress, TheActivity } from "./types.js";
2
2
  declare const aniListEndpoint = "https://graphql.anilist.co";
3
3
  declare const redirectUri = "https://anilist.co/api/v2/oauth/pin";
4
4
  declare function getTitle(title: {
@@ -6,9 +6,9 @@ declare function getTitle(title: {
6
6
  romaji?: string;
7
7
  }): string;
8
8
  declare function formatDateObject(dateObj: {
9
- day?: string;
10
- month?: string;
11
- year?: string;
9
+ day?: number;
10
+ month?: number;
11
+ year?: number;
12
12
  } | null): string;
13
13
  declare function getNextSeasonAndYear(): {
14
14
  nextSeason: string;
@@ -20,19 +20,31 @@ declare function getFormattedDate(): string;
20
20
  /**
21
21
  * Export JSON as JSON
22
22
  * @param js0n
23
- * @param dataType (eg: anime/manga)
23
+ * @param dataType (eg: anime|manga)
24
24
  */
25
25
  declare function saveJSONasJSON(js0n: object, dataType: string): Promise<void>;
26
26
  /**
27
27
  * Export JSON as CSV
28
28
  * @param js0n
29
- * @param dataType (eg: anime/manga)
29
+ * @param dataType (eg: anime|manga)
30
30
  */
31
- declare function saveJSONasCSV(js0n: object, dataType: string): Promise<void>;
31
+ declare function saveJSONasCSV(js0n: MediaWithProgress[], dataType: string): Promise<void>;
32
+ declare function saveJSONasXML(js0n: MediaWithProgress[], data_type: 0 | 1): Promise<void>;
32
33
  declare function selectFile(fileType: string): Promise<string>;
33
- declare function createAnimeXML(malId: number, progress: number, status: MALAnimeStatus, episodes: number, title: string): string;
34
+ declare function createAnimeXML(malId: number, progress: number, status: MALAnimeStatus, episodes: number, title: string, format: string): string;
34
35
  declare function createMangaXML(malId: number, progress: number, status: MALMangaStatus, chapters: number, title: string): string;
35
36
  declare function createAnimeListXML(mediaWithProgress: MediaWithProgress[]): Promise<string>;
36
37
  declare function createMangaListXML(mediaWithProgress: MediaWithProgress[]): Promise<string>;
37
38
  declare function getCurrentPackageVersion(): string | null;
38
- export { aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, selectFile, };
39
+ declare function timestampToTimeAgo(timestamp: number): string;
40
+ declare const anidbToanilistMapper: (romanjiName: string, year: number, englishName?: string) => Promise<number | null>;
41
+ declare function activityBy(activity: TheActivity, count?: number): string;
42
+ /**
43
+ * Extract the save file path
44
+ * @param data_type - anime|manga
45
+ * @param file_format - save format (eg: .json|.csv)
46
+ * @returns string of file path
47
+ */
48
+ declare function saveToPath(data_type: string, file_format: string): Promise<string>;
49
+ declare function simpleDateFormat(date: DateMonthYear): string;
50
+ export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, timestampToTimeAgo, };
@@ -7,17 +7,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  import fs from "fs";
11
22
  import { readdir, writeFile } from "fs/promises";
12
23
  import inquirer from "inquirer";
13
- import { parse } from "json2csv";
14
24
  import { createRequire } from "module";
15
25
  import open from "open";
16
26
  import { homedir } from "os";
27
+ import Papa from "papaparse";
17
28
  import { join } from "path";
18
29
  import process from "process";
19
30
  import { Auth } from "./auth.js";
20
- import { MALAnimeStatus, MALMangaStatus } from "./types.js";
31
+ import { fetcher } from "./fetcher.js";
32
+ import { animeSearchQuery } from "./queries.js";
33
+ import { MALAnimeStatus, MALMangaStatus, } from "./types.js";
21
34
  const aniListEndpoint = `https://graphql.anilist.co`;
22
35
  const redirectUri = "https://anilist.co/api/v2/oauth/pin";
23
36
  function getTitle(title) {
@@ -95,13 +108,13 @@ function getFormattedDate() {
95
108
  /**
96
109
  * Export JSON as JSON
97
110
  * @param js0n
98
- * @param dataType (eg: anime/manga)
111
+ * @param dataType (eg: anime|manga)
99
112
  */
100
113
  function saveJSONasJSON(js0n, dataType) {
101
114
  return __awaiter(this, void 0, void 0, function* () {
102
115
  try {
103
116
  const jsonData = JSON.stringify(js0n, null, 2);
104
- const path = join(getDownloadFolderPath(), `${yield Auth.MyUserName()}@irfanshadikrishad-anilist-${dataType}-${getFormattedDate()}.json`);
117
+ const path = yield saveToPath(dataType, ".json");
105
118
  yield writeFile(path, jsonData, "utf8");
106
119
  console.log(`\nSaved as JSON successfully.`);
107
120
  open(getDownloadFolderPath());
@@ -114,13 +127,17 @@ function saveJSONasJSON(js0n, dataType) {
114
127
  /**
115
128
  * Export JSON as CSV
116
129
  * @param js0n
117
- * @param dataType (eg: anime/manga)
130
+ * @param dataType (eg: anime|manga)
118
131
  */
119
132
  function saveJSONasCSV(js0n, dataType) {
120
133
  return __awaiter(this, void 0, void 0, function* () {
121
134
  try {
122
- const csvData = parse(js0n);
123
- const path = join(getDownloadFolderPath(), `${yield Auth.MyUserName()}@irfanshadikrishad-anilist-${dataType}-${getFormattedDate()}.csv`);
135
+ const js0n_WTAS = js0n.map((_a) => {
136
+ var { title } = _a, rest = __rest(_a, ["title"]);
137
+ return (Object.assign(Object.assign({}, rest), { title: getTitle(title) }));
138
+ });
139
+ const csvData = Papa.unparse(js0n_WTAS);
140
+ const path = yield saveToPath(dataType, ".csv");
124
141
  yield writeFile(path, csvData, "utf8");
125
142
  console.log(`\nSaved as CSV successfully.`);
126
143
  open(getDownloadFolderPath());
@@ -130,6 +147,20 @@ function saveJSONasCSV(js0n, dataType) {
130
147
  }
131
148
  });
132
149
  }
150
+ function saveJSONasXML(js0n, data_type) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ try {
153
+ const xmlContent = data_type === 0 ? createAnimeListXML(js0n) : createMangaListXML(js0n);
154
+ const path = yield saveToPath(data_type === 0 ? "anime" : "manga", ".xml");
155
+ yield writeFile(path, yield xmlContent, "utf8");
156
+ console.log(`\nGenerated XML for MyAnimeList.`);
157
+ open(getDownloadFolderPath());
158
+ }
159
+ catch (error) {
160
+ console.error(`Error saving XML data:`, error);
161
+ }
162
+ });
163
+ }
133
164
  function listFilesInDownloadFolder() {
134
165
  return __awaiter(this, void 0, void 0, function* () {
135
166
  const downloadFolderPath = getDownloadFolderPath();
@@ -160,21 +191,22 @@ function selectFile(fileType) {
160
191
  return answers.fileName;
161
192
  }
162
193
  else {
163
- throw new Error(`\nNo importable ${fileType} file(s) found in download folder.`);
194
+ console.error(`\nNo importable ${fileType} file(s) found in download folder.`);
195
+ return null;
164
196
  }
165
197
  }
166
198
  catch (error) {
167
199
  console.error("\nError selecting file:", error);
168
- throw error;
200
+ return null;
169
201
  }
170
202
  });
171
203
  }
172
- function createAnimeXML(malId, progress, status, episodes, title) {
204
+ function createAnimeXML(malId, progress, status, episodes, title, format) {
173
205
  return `
174
206
  <anime>
175
207
  <series_animedb_id>${malId}</series_animedb_id>
176
208
  <series_title><![CDATA[${title}]]></series_title>
177
- <series_type>""</series_type>
209
+ <series_type>${format}</series_type>
178
210
  <series_episodes>${episodes}</series_episodes>
179
211
  <my_id>0</my_id>
180
212
  <my_watched_episodes>${progress}</my_watched_episodes>
@@ -224,13 +256,16 @@ function createAnimeListXML(mediaWithProgress) {
224
256
  PAUSED: MALAnimeStatus.ON_HOLD,
225
257
  DROPPED: MALAnimeStatus.DROPPED,
226
258
  };
227
- const xmlEntries = mediaWithProgress.map((anime) => {
259
+ // Filter out anime without malId
260
+ const filteredMedia = mediaWithProgress.filter((anime) => anime.malId);
261
+ const xmlEntries = filteredMedia.map((anime) => {
228
262
  const malId = anime.malId;
229
263
  const progress = anime.progress;
230
264
  const episodes = anime.episodes;
231
265
  const title = getTitle(anime.title);
232
266
  const status = statusMap[anime.status];
233
- return createAnimeXML(malId, progress, status, episodes, title);
267
+ const format = anime.format ? anime.format : "";
268
+ return createAnimeXML(malId, progress, status, episodes, title, format);
234
269
  });
235
270
  return `<myanimelist>
236
271
  <myinfo>
@@ -257,7 +292,9 @@ function createMangaListXML(mediaWithProgress) {
257
292
  PAUSED: MALMangaStatus.ON_HOLD,
258
293
  DROPPED: MALMangaStatus.DROPPED,
259
294
  };
260
- const xmlEntries = mediaWithProgress.map((manga) => {
295
+ // Filter out manga without malId
296
+ const filteredMedia = mediaWithProgress.filter((manga) => manga.malId);
297
+ const xmlEntries = filteredMedia.map((manga) => {
261
298
  const malId = manga.malId;
262
299
  const progress = manga.progress;
263
300
  const chapters = manga.chapters;
@@ -287,4 +324,98 @@ function getCurrentPackageVersion() {
287
324
  const version = packageJson.version;
288
325
  return version || null;
289
326
  }
290
- export { aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, selectFile, };
327
+ function timestampToTimeAgo(timestamp) {
328
+ const now = Math.floor(Date.now() / 1000);
329
+ const elapsed = now - timestamp;
330
+ if (elapsed < 60) {
331
+ return `${elapsed} second${elapsed === 1 ? "" : "s"} ago`;
332
+ }
333
+ else if (elapsed < 3600) {
334
+ const minutes = Math.floor(elapsed / 60);
335
+ return `${minutes} minute${minutes === 1 ? "" : "s"} ago`;
336
+ }
337
+ else if (elapsed < 86400) {
338
+ const hours = Math.floor(elapsed / 3600);
339
+ return `${hours} hour${hours === 1 ? "" : "s"} ago`;
340
+ }
341
+ else if (elapsed < 2592000) {
342
+ const days = Math.floor(elapsed / 86400);
343
+ return `${days} day${days === 1 ? "" : "s"} ago`;
344
+ }
345
+ else if (elapsed < 31536000) {
346
+ const months = Math.floor(elapsed / 2592000);
347
+ return `${months} month${months === 1 ? "" : "s"} ago`;
348
+ }
349
+ else {
350
+ const years = Math.floor(elapsed / 31536000);
351
+ return `${years} year${years === 1 ? "" : "s"} ago`;
352
+ }
353
+ }
354
+ const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void 0, void 0, void 0, function* () {
355
+ const fetchAnime = (search) => __awaiter(void 0, void 0, void 0, function* () {
356
+ var _a;
357
+ try {
358
+ const response = yield fetcher(animeSearchQuery, {
359
+ search,
360
+ perPage: 50,
361
+ });
362
+ return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.Page.media) || [];
363
+ }
364
+ catch (error) {
365
+ console.error("Error fetching AniList data:", error);
366
+ return [];
367
+ }
368
+ });
369
+ // Search using romanjiName first
370
+ let results = yield fetchAnime(romanjiName);
371
+ // If no results, fallback to englishName
372
+ if (!results.length && englishName) {
373
+ results = yield fetchAnime(englishName);
374
+ }
375
+ // Match using year
376
+ for (const anime of results) {
377
+ if (anime.startDate.year === year) {
378
+ return anime.id;
379
+ }
380
+ }
381
+ return null;
382
+ });
383
+ function activityBy(activity, count) {
384
+ var _a, _b, _c, _d;
385
+ const countStr = `[${count ? count : "?"}]`.padEnd(6);
386
+ if ((_a = activity === null || activity === void 0 ? void 0 : activity.messenger) === null || _a === void 0 ? void 0 : _a.name) {
387
+ return `${countStr}${activity.messenger.name} >> messaged ${activity.recipient.name}`;
388
+ }
389
+ else if ((_c = (_b = activity === null || activity === void 0 ? void 0 : activity.media) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.userPreferred) {
390
+ if (activity.progress) {
391
+ return `${countStr}${activity.user.name} >> ${activity.status} ${activity.progress} of ${activity.media.title.userPreferred}`;
392
+ }
393
+ else {
394
+ return `${countStr}${activity.user.name} >> ${activity.status} ${activity.media.title.userPreferred}`;
395
+ }
396
+ }
397
+ else if ((_d = activity === null || activity === void 0 ? void 0 : activity.user) === null || _d === void 0 ? void 0 : _d.name) {
398
+ return `${countStr}${activity.user.name}`;
399
+ }
400
+ else {
401
+ return `${countStr}???`;
402
+ }
403
+ }
404
+ /**
405
+ * Extract the save file path
406
+ * @param data_type - anime|manga
407
+ * @param file_format - save format (eg: .json|.csv)
408
+ * @returns string of file path
409
+ */
410
+ function saveToPath(data_type, file_format) {
411
+ return __awaiter(this, void 0, void 0, function* () {
412
+ return join(getDownloadFolderPath(), `${yield Auth.MyUserName()}@irfanshadikrishad-anilist-${data_type}-${getFormattedDate()}.${file_format}`);
413
+ });
414
+ }
415
+ function simpleDateFormat(date) {
416
+ if (!date.day && !date.month && !date.year) {
417
+ return `null`;
418
+ }
419
+ return `${date === null || date === void 0 ? void 0 : date.day}/${date === null || date === void 0 ? void 0 : date.month}/${date === null || date === void 0 ? void 0 : date.year}`;
420
+ }
421
+ export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, timestampToTimeAgo, };
package/bin/index.js CHANGED
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  import { Command } from "commander";
12
12
  import process from "process";
13
- import { Auth } from "./helpers/auth.js";
13
+ import { Auth, Social } from "./helpers/auth.js";
14
14
  import { AniList } from "./helpers/lists.js";
15
15
  import { getCurrentPackageVersion } from "./helpers/workers.js";
16
16
  const cli = new Command();
@@ -32,7 +32,7 @@ cli
32
32
  }
33
33
  }));
34
34
  cli
35
- .command("me")
35
+ .command("whoami")
36
36
  .description("Get details of the logged in user")
37
37
  .action(() => __awaiter(void 0, void 0, void 0, function* () {
38
38
  yield Auth.Myself();
@@ -88,7 +88,7 @@ cli
88
88
  .description("Delete entire collections of anime or manga")
89
89
  .option("-a, --anime", "For anime list of authenticated user", false)
90
90
  .option("-m, --manga", "For manga list of authenticated user", false)
91
- .option("-ac, --activity", "For activity of authenticated user", false)
91
+ .option("-s, --activity", "For activity of authenticated user", false)
92
92
  .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga, activity }) {
93
93
  const selectedOptions = [anime, manga, activity].filter(Boolean).length;
94
94
  if (selectedOptions === 0) {
@@ -128,6 +128,13 @@ cli
128
128
  console.error(`\nInvalid or missing ID (${id}). Please provide a valid numeric ID.`);
129
129
  }
130
130
  }));
131
+ cli
132
+ .command("manga <id>")
133
+ .description("Get manga details by their ID")
134
+ .option("-c, --count <number>", "Number of items to get", "10")
135
+ .action((id) => __awaiter(void 0, void 0, void 0, function* () {
136
+ yield AniList.getMangaDetailsByID(id);
137
+ }));
131
138
  cli
132
139
  .command("search <query>")
133
140
  .alias("srch")
@@ -206,8 +213,39 @@ cli
206
213
  cli
207
214
  .command("autolike")
208
215
  .alias("al")
216
+ .option("-2, --v2", "Like the activities", false)
217
+ .option("-c, --count <number>", "Number of activities to like", "25")
209
218
  .description("Autolike following or global activities.")
210
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
211
- yield Auth.AutoLike();
219
+ .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ v2, count }) {
220
+ if (v2) {
221
+ yield Auth.LikeFollowingActivityV2(count);
222
+ }
223
+ else {
224
+ yield Auth.AutoLike();
225
+ }
226
+ }));
227
+ cli
228
+ .command("social")
229
+ .alias("sol")
230
+ .description("Automate your process")
231
+ .option("-f, --follow", "Follow the user whos following you.", false)
232
+ .option("-u, --unfollow", "Unfollow the user whos not following you.", false)
233
+ .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ follow, unfollow }) {
234
+ if (!follow && !unfollow) {
235
+ console.error(`\nMust select an option, either --follow or --unfollow`);
236
+ }
237
+ else {
238
+ if (yield Auth.isLoggedIn()) {
239
+ if (follow) {
240
+ yield Social.follow();
241
+ }
242
+ else if (unfollow) {
243
+ yield Social.unfollow();
244
+ }
245
+ }
246
+ else {
247
+ console.error(`\nPlease login to use this feature.`);
248
+ }
249
+ }
212
250
  }));
213
251
  cli.parse(process.argv);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@irfanshadikrishad/anilist",
3
3
  "description": "Minimalist unofficial AniList CLI for Anime and Manga Enthusiasts",
4
4
  "author": "Irfan Shadik Rishad",
5
- "version": "1.2.0-forbidden.1",
5
+ "version": "1.2.0-forbidden.6",
6
6
  "main": "./bin/index.js",
7
7
  "type": "module",
8
8
  "types": "./bin/index.d.ts",
@@ -14,12 +14,12 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "rm -rf ./bin && tsc",
17
- "buildw": "rm -rf ./bin && tsc -w",
17
+ "build:watch": "rm -rf ./bin && tsc -w",
18
18
  "format": "prettier . --write",
19
19
  "format:check": "prettier . --check",
20
20
  "lint": "eslint ./dist",
21
21
  "lint:fix": "eslint ./dist --fix",
22
- "all": "npm run lint && npm run lint:fix && npm run format",
22
+ "all": "npm run build && npm run lint && npm run lint:fix && npm run format && npm test",
23
23
  "test": "jest ./tests"
24
24
  },
25
25
  "keywords": [
@@ -54,27 +54,33 @@
54
54
  },
55
55
  "license": "MPL-2.0",
56
56
  "devDependencies": {
57
- "@eslint/js": "^9.17.0",
57
+ "@babel/preset-env": "^7.26.9",
58
+ "@eslint/js": "^9.21.0",
58
59
  "@types/jest": "^29.5.14",
59
- "@types/json2csv": "^5.0.7",
60
- "@types/node": "^22.10.3",
61
- "eslint": "^9.17.0",
62
- "globals": "^15.14.0",
60
+ "@types/node": "^22.13.5",
61
+ "@types/papaparse": "^5.3.15",
62
+ "@types/xml2js": "^0.4.14",
63
+ "@typescript-eslint/eslint-plugin": "^8.24.1",
64
+ "eslint": "^9.21.0",
65
+ "globals": "^16.0.0",
63
66
  "jest": "^29.7.0",
64
- "prettier": "^3.4.2",
67
+ "prettier": "^3.5.2",
65
68
  "prettier-plugin-organize-imports": "^4.1.0",
66
- "ts-jest": "^29.2.5",
69
+ "ts-jest": "^29.2.6",
67
70
  "ts-node": "^10.9.2",
68
- "typescript": "^5.7.2",
69
- "@babel/preset-env": "^7.26.0",
70
- "@typescript-eslint/eslint-plugin": "^8.19.0"
71
+ "typescript": "^5.7.3"
71
72
  },
72
73
  "dependencies": {
73
- "commander": "^12.1.0",
74
- "fast-xml-parser": "^4.5.1",
75
- "inquirer": "^12.3.0",
76
- "json2csv": "^6.0.0-alpha.2",
74
+ "@irfanshadikrishad/cipher": "^1.0.1",
75
+ "cli-truncate": "^4.0.0",
76
+ "commander": "^13.1.0",
77
+ "fast-xml-parser": "^5.0.6",
78
+ "inquirer": "^12.4.2",
79
+ "jsonrepair": "^3.12.0",
77
80
  "node-fetch": "^3.3.2",
78
- "open": "^10.1.0"
81
+ "open": "^10.1.0",
82
+ "papaparse": "^5.5.2",
83
+ "tiny-spinner": "^2.0.5",
84
+ "xml2js": "^0.6.2"
79
85
  }
80
86
  }
Binary file