@irfanshadikrishad/anilist 1.2.3 → 1.2.5
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/LICENSE +115 -124
- package/README.md +23 -20
- package/bin/helpers/auth.d.ts +35 -6
- package/bin/helpers/auth.js +49 -55
- package/bin/helpers/fetcher.d.ts +1 -1
- package/bin/helpers/lists.d.ts +5 -2
- package/bin/helpers/lists.js +181 -142
- package/bin/helpers/queries.d.ts +5 -3
- package/bin/helpers/queries.js +17 -3
- package/bin/helpers/types.d.ts +231 -8
- package/bin/helpers/workers.d.ts +6 -4
- package/bin/helpers/workers.js +60 -2
- package/bin/index.js +2 -2
- package/package.json +8 -7
package/bin/helpers/auth.js
CHANGED
|
@@ -14,10 +14,10 @@ import open from "open";
|
|
|
14
14
|
import os from "os";
|
|
15
15
|
import path from "path";
|
|
16
16
|
import { fetcher } from "./fetcher.js";
|
|
17
|
-
import { AniList, MyAnimeList } from "./lists.js";
|
|
17
|
+
import { AniDB, AniList, MyAnimeList } from "./lists.js";
|
|
18
18
|
import { deleteActivityMutation, saveTextActivityMutation, } from "./mutations.js";
|
|
19
|
-
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, userActivityQuery, } from "./queries.js";
|
|
20
|
-
import { aniListEndpoint, getTitle, redirectUri } from "./workers.js";
|
|
19
|
+
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, userActivityQuery, userFollowersQuery, userFollowingQuery, } from "./queries.js";
|
|
20
|
+
import { aniListEndpoint, getTitle, redirectUri, timestampToTimeAgo, } from "./workers.js";
|
|
21
21
|
const home_dir = os.homedir();
|
|
22
22
|
const save_path = path.join(home_dir, ".anilist_token");
|
|
23
23
|
class Auth {
|
|
@@ -109,7 +109,7 @@ class Auth {
|
|
|
109
109
|
}
|
|
110
110
|
static Myself() {
|
|
111
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
112
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
113
113
|
try {
|
|
114
114
|
if (yield Auth.isLoggedIn()) {
|
|
115
115
|
const headers = {
|
|
@@ -130,33 +130,47 @@ class Auth {
|
|
|
130
130
|
perPage: 10,
|
|
131
131
|
});
|
|
132
132
|
const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
|
|
133
|
+
// Get follower/following information
|
|
134
|
+
const req_followers = yield fetcher(userFollowersQuery, {
|
|
135
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
136
|
+
});
|
|
137
|
+
const req_following = yield fetcher(userFollowingQuery, {
|
|
138
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
139
|
+
});
|
|
140
|
+
const followersCount = ((_e = (_d = (_c = req_followers === null || req_followers === void 0 ? void 0 : req_followers.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.pageInfo) === null || _e === void 0 ? void 0 : _e.total) || 0;
|
|
141
|
+
const followingCount = ((_h = (_g = (_f = req_following === null || req_following === void 0 ? void 0 : req_following.data) === null || _f === void 0 ? void 0 : _f.Page) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.total) || 0;
|
|
133
142
|
console.log(`
|
|
134
143
|
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
135
144
|
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
136
145
|
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
137
|
-
profileColor: ${(
|
|
138
|
-
timeZone: ${(
|
|
139
|
-
activityMergeTime: ${(
|
|
146
|
+
profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
|
|
147
|
+
timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
|
|
148
|
+
activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
|
|
140
149
|
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
141
150
|
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
142
151
|
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
143
152
|
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
144
153
|
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
154
|
+
|
|
155
|
+
Followers: ${followersCount}
|
|
156
|
+
Following: ${followingCount}
|
|
145
157
|
|
|
146
158
|
Statistics (Anime):
|
|
147
|
-
Count: ${(
|
|
148
|
-
Mean Score: ${(
|
|
149
|
-
Minutes Watched: ${(
|
|
159
|
+
Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.anime) === null || _o === void 0 ? void 0 : _o.count}
|
|
160
|
+
Mean Score: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.anime) === null || _q === void 0 ? void 0 : _q.meanScore}
|
|
161
|
+
Minutes Watched: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.anime) === null || _s === void 0 ? void 0 : _s.minutesWatched}
|
|
162
|
+
Episodes Watched: ${(_u = (_t = user === null || user === void 0 ? void 0 : user.statistics) === null || _t === void 0 ? void 0 : _t.anime) === null || _u === void 0 ? void 0 : _u.episodesWatched}
|
|
150
163
|
|
|
151
164
|
Statistics (Manga):
|
|
152
|
-
Count: ${(
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
Count: ${(_w = (_v = user === null || user === void 0 ? void 0 : user.statistics) === null || _v === void 0 ? void 0 : _v.manga) === null || _w === void 0 ? void 0 : _w.count}
|
|
166
|
+
Mean Score: ${(_y = (_x = user === null || user === void 0 ? void 0 : user.statistics) === null || _x === void 0 ? void 0 : _x.manga) === null || _y === void 0 ? void 0 : _y.meanScore}
|
|
167
|
+
Chapters Read: ${(_0 = (_z = user === null || user === void 0 ? void 0 : user.statistics) === null || _z === void 0 ? void 0 : _z.manga) === null || _0 === void 0 ? void 0 : _0.chaptersRead}
|
|
168
|
+
Volumes Read: ${(_2 = (_1 = user === null || user === void 0 ? void 0 : user.statistics) === null || _1 === void 0 ? void 0 : _1.manga) === null || _2 === void 0 ? void 0 : _2.volumesRead}
|
|
155
169
|
`);
|
|
156
170
|
console.log(`\nRecent Activities:`);
|
|
157
171
|
if (activities.length > 0) {
|
|
158
|
-
activities.map(({ status, progress, media }) => {
|
|
159
|
-
console.log(`${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
172
|
+
activities.map(({ status, progress, media, createdAt }) => {
|
|
173
|
+
console.log(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
160
174
|
});
|
|
161
175
|
}
|
|
162
176
|
return user;
|
|
@@ -217,7 +231,7 @@ Statistics (Manga):
|
|
|
217
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
232
|
var _a, _b;
|
|
219
233
|
if (!(yield Auth.isLoggedIn())) {
|
|
220
|
-
console.
|
|
234
|
+
console.warn(`\nUser not logged in.`);
|
|
221
235
|
return null;
|
|
222
236
|
}
|
|
223
237
|
const token = yield Auth.RetriveAccessToken();
|
|
@@ -281,8 +295,6 @@ Statistics (Manga):
|
|
|
281
295
|
],
|
|
282
296
|
},
|
|
283
297
|
]);
|
|
284
|
-
const userId = yield Auth.MyUserId();
|
|
285
|
-
const variables = { page: 1, perPage: 100, userId };
|
|
286
298
|
const queryMap = {
|
|
287
299
|
0: activityAllQuery,
|
|
288
300
|
1: activityTextQuery,
|
|
@@ -293,6 +305,7 @@ Statistics (Manga):
|
|
|
293
305
|
};
|
|
294
306
|
const query = queryMap[activityType];
|
|
295
307
|
let hasMoreActivities = true;
|
|
308
|
+
let totalCount = 0;
|
|
296
309
|
while (hasMoreActivities) {
|
|
297
310
|
const response = yield fetcher(query, {
|
|
298
311
|
page: 1,
|
|
@@ -315,7 +328,8 @@ Statistics (Manga):
|
|
|
315
328
|
});
|
|
316
329
|
const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
|
|
317
330
|
count++;
|
|
318
|
-
|
|
331
|
+
totalCount++;
|
|
332
|
+
console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
319
333
|
// Avoiding rate-limit
|
|
320
334
|
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
321
335
|
}
|
|
@@ -360,7 +374,7 @@ Statistics (Manga):
|
|
|
360
374
|
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
361
375
|
if (selectedEntries) {
|
|
362
376
|
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
363
|
-
for (const [
|
|
377
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
364
378
|
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
365
379
|
yield Auth.DeleteAnimeById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
366
380
|
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
@@ -396,19 +410,8 @@ Statistics (Manga):
|
|
|
396
410
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
411
|
var _a, _b, _c;
|
|
398
412
|
try {
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
headers: {
|
|
402
|
-
"content-type": "application/json",
|
|
403
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
404
|
-
},
|
|
405
|
-
body: JSON.stringify({
|
|
406
|
-
query: deleteMediaEntryMutation,
|
|
407
|
-
variables: { id },
|
|
408
|
-
}),
|
|
409
|
-
});
|
|
410
|
-
const response = yield request.json();
|
|
411
|
-
if (request.status === 200) {
|
|
413
|
+
const response = yield fetcher(deleteMediaEntryMutation, { id: id });
|
|
414
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
412
415
|
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
413
416
|
console.log(`del ${title ? getTitle(title) : ""} ${deleted ? "✅" : "❌"}`);
|
|
414
417
|
}
|
|
@@ -445,7 +448,7 @@ Statistics (Manga):
|
|
|
445
448
|
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
446
449
|
if (selectedEntries) {
|
|
447
450
|
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
448
|
-
for (const [
|
|
451
|
+
for (const [, entry] of selectedEntries.entries.entries()) {
|
|
449
452
|
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
450
453
|
yield Auth.DeleteMangaById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
451
454
|
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
@@ -477,33 +480,22 @@ Statistics (Manga):
|
|
|
477
480
|
}
|
|
478
481
|
}
|
|
479
482
|
catch (error) {
|
|
480
|
-
console.error(`\nError deleting manga
|
|
483
|
+
console.error(`\nError deleting manga. ${error.message}`);
|
|
481
484
|
}
|
|
482
485
|
});
|
|
483
486
|
}
|
|
484
487
|
static DeleteMangaById(id, title) {
|
|
485
488
|
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
-
var _a, _b;
|
|
489
|
+
var _a, _b, _c, _d;
|
|
487
490
|
try {
|
|
488
|
-
const
|
|
489
|
-
method: "POST",
|
|
490
|
-
headers: {
|
|
491
|
-
"Content-Type": "application/json",
|
|
492
|
-
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
493
|
-
},
|
|
494
|
-
body: JSON.stringify({
|
|
495
|
-
query: deleteMangaEntryMutation,
|
|
496
|
-
variables: { id },
|
|
497
|
-
}),
|
|
498
|
-
});
|
|
499
|
-
const { data, errors } = yield request.json();
|
|
491
|
+
const response = yield fetcher(deleteMangaEntryMutation, { id });
|
|
500
492
|
const statusMessage = title ? getTitle(title) : "";
|
|
501
|
-
if (
|
|
502
|
-
const deleted = (_a =
|
|
493
|
+
if (response === null || response === void 0 ? void 0 : response.data) {
|
|
494
|
+
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
503
495
|
console.log(`del ${statusMessage} ${deleted ? "✅" : "❌"}`);
|
|
504
496
|
}
|
|
505
497
|
else {
|
|
506
|
-
console.error(`Error deleting manga. ${(
|
|
498
|
+
console.error(`Error deleting manga. ${(_d = (_c = response === null || response === void 0 ? void 0 : response.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
507
499
|
}
|
|
508
500
|
}
|
|
509
501
|
catch (error) {
|
|
@@ -519,12 +511,10 @@ Statistics (Manga):
|
|
|
519
511
|
console.error(`\nPlease login to use this feature.`);
|
|
520
512
|
return;
|
|
521
513
|
}
|
|
522
|
-
const
|
|
523
|
-
const variables = {
|
|
514
|
+
const data = yield fetcher(saveTextActivityMutation, {
|
|
524
515
|
status: status +
|
|
525
516
|
`<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
|
|
526
|
-
};
|
|
527
|
-
const data = yield fetcher(query, variables);
|
|
517
|
+
});
|
|
528
518
|
if (!data) {
|
|
529
519
|
console.error(`\nSomething went wrong. ${data}.`);
|
|
530
520
|
return;
|
|
@@ -550,6 +540,7 @@ Statistics (Manga):
|
|
|
550
540
|
choices: [
|
|
551
541
|
{ name: "Exported JSON file.", value: 1 },
|
|
552
542
|
{ name: "MyAnimeList (XML)", value: 2 },
|
|
543
|
+
{ name: "AniDB (json-large)", value: 3 },
|
|
553
544
|
],
|
|
554
545
|
pageSize: 10,
|
|
555
546
|
},
|
|
@@ -561,6 +552,9 @@ Statistics (Manga):
|
|
|
561
552
|
case 2:
|
|
562
553
|
yield MyAnimeList.importAnime();
|
|
563
554
|
break;
|
|
555
|
+
case 3:
|
|
556
|
+
yield AniDB.importAnime();
|
|
557
|
+
break;
|
|
564
558
|
default:
|
|
565
559
|
console.log(`\nInvalid Choice.`);
|
|
566
560
|
break;
|
package/bin/helpers/fetcher.d.ts
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* @param {object} variables - An object containing the variables for the query.
|
|
10
10
|
* @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
|
|
11
11
|
*/
|
|
12
|
-
declare function fetcher(query: string, variables: object): Promise<
|
|
12
|
+
declare function fetcher(query: string, variables: object): Promise<object | null>;
|
|
13
13
|
export { fetcher };
|
package/bin/helpers/lists.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare class AniList {
|
|
|
5
5
|
static exportManga(): Promise<void>;
|
|
6
6
|
static MyAnime(): Promise<void>;
|
|
7
7
|
static MyManga(): Promise<void>;
|
|
8
|
-
static getTrendingAnime(count: number): Promise<
|
|
8
|
+
static getTrendingAnime(count: number): Promise<void>;
|
|
9
9
|
static getPopularAnime(count: number): Promise<void>;
|
|
10
10
|
static getUpcomingAnime(count: number): Promise<void>;
|
|
11
11
|
static getUserByUsername(username: string): Promise<void>;
|
|
@@ -19,4 +19,7 @@ declare class MyAnimeList {
|
|
|
19
19
|
static exportAnime(): Promise<void>;
|
|
20
20
|
static exportManga(): Promise<void>;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
declare class AniDB {
|
|
23
|
+
static importAnime(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export { AniDB, AniList, MyAnimeList };
|