@irfanshadikrishad/anilist 2.0.0-forbidden → 2.0.0-forbidden.0
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/.husky/pre-commit +3 -0
- package/README.md +26 -21
- package/bin/helpers/auth.d.ts +22 -2
- package/bin/helpers/auth.js +223 -236
- package/bin/helpers/lists.d.ts +40 -0
- package/bin/helpers/lists.js +339 -705
- package/bin/helpers/validation.d.ts +10 -1
- package/bin/helpers/validation.js +24 -36
- package/bin/helpers/workers.d.ts +2 -1
- package/bin/helpers/workers.js +5 -2
- package/bin/index.js +57 -67
- package/package.json +4 -2
|
@@ -7,6 +7,15 @@ declare class Validate {
|
|
|
7
7
|
static Import_JSON(data: {
|
|
8
8
|
id: number;
|
|
9
9
|
}[]): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validate if a MyAnimeList anime/manga export XML file is valid or not
|
|
12
|
+
* @param xmlData string
|
|
13
|
+
* @param listKey 'anime' | 'manga'
|
|
14
|
+
* @param idField the MAL id field name for the list item (eg: series_animedb_id)
|
|
15
|
+
* @param titleField the title field name for the list item (eg: series_title)
|
|
16
|
+
* @returns boolean
|
|
17
|
+
*/
|
|
18
|
+
private static Import_MALXML;
|
|
10
19
|
/**
|
|
11
20
|
* Validate if MyAnimeList Anime XML file is valid or not
|
|
12
21
|
* @param xmlData string
|
|
@@ -14,7 +23,7 @@ declare class Validate {
|
|
|
14
23
|
*/
|
|
15
24
|
static Import_AnimeXML(xmlData: string): Promise<boolean>;
|
|
16
25
|
/**
|
|
17
|
-
* Validate if MyAnimeList
|
|
26
|
+
* Validate if MyAnimeList Manga XML file is valid or not
|
|
18
27
|
* @param xmlData string
|
|
19
28
|
* @returns boolean
|
|
20
29
|
*/
|
|
@@ -19,11 +19,14 @@ class Validate {
|
|
|
19
19
|
data.every((item) => typeof item === 'object' && item !== null && 'id' in item));
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Validate if MyAnimeList
|
|
22
|
+
* Validate if a MyAnimeList anime/manga export XML file is valid or not
|
|
23
23
|
* @param xmlData string
|
|
24
|
+
* @param listKey 'anime' | 'manga'
|
|
25
|
+
* @param idField the MAL id field name for the list item (eg: series_animedb_id)
|
|
26
|
+
* @param titleField the title field name for the list item (eg: series_title)
|
|
24
27
|
* @returns boolean
|
|
25
28
|
*/
|
|
26
|
-
static
|
|
29
|
+
static Import_MALXML(xmlData, listKey, idField, titleField) {
|
|
27
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
31
|
try {
|
|
29
32
|
const result = yield parseStringPromise(xmlData, { explicitArray: false });
|
|
@@ -31,19 +34,19 @@ class Validate {
|
|
|
31
34
|
console.error("Invalid XML structure: Missing 'myanimelist' root element.");
|
|
32
35
|
return false;
|
|
33
36
|
}
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
console.error(
|
|
37
|
+
const list = result.myanimelist[listKey];
|
|
38
|
+
if (!list) {
|
|
39
|
+
console.error(`Invalid XML structure: Missing '${listKey}' elements.`);
|
|
37
40
|
return false;
|
|
38
41
|
}
|
|
39
|
-
const
|
|
40
|
-
const isValid =
|
|
41
|
-
const isValidId =
|
|
42
|
-
const hasRequiredFields =
|
|
42
|
+
const array = Array.isArray(list) ? list : [list];
|
|
43
|
+
const isValid = array.every((item) => {
|
|
44
|
+
const isValidId = item[idField] && !isNaN(Number(item[idField]));
|
|
45
|
+
const hasRequiredFields = item[titleField] && item.my_status;
|
|
43
46
|
return isValidId && hasRequiredFields;
|
|
44
47
|
});
|
|
45
48
|
if (!isValid) {
|
|
46
|
-
console.error(
|
|
49
|
+
console.error(`Validation failed: Some ${listKey} entries are missing required fields or have invalid IDs.`);
|
|
47
50
|
}
|
|
48
51
|
return isValid;
|
|
49
52
|
}
|
|
@@ -58,34 +61,19 @@ class Validate {
|
|
|
58
61
|
* @param xmlData string
|
|
59
62
|
* @returns boolean
|
|
60
63
|
*/
|
|
64
|
+
static Import_AnimeXML(xmlData) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return Validate.Import_MALXML(xmlData, 'anime', 'series_animedb_id', 'series_title');
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Validate if MyAnimeList Manga XML file is valid or not
|
|
71
|
+
* @param xmlData string
|
|
72
|
+
* @returns boolean
|
|
73
|
+
*/
|
|
61
74
|
static Import_MangaXML(xmlData) {
|
|
62
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
const result = yield parseStringPromise(xmlData, { explicitArray: false });
|
|
65
|
-
if (!result || !result.myanimelist) {
|
|
66
|
-
console.error("Invalid XML structure: Missing 'myanimelist' root element.");
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
const mangaList = result.myanimelist.manga;
|
|
70
|
-
if (!mangaList) {
|
|
71
|
-
console.error("Invalid XML structure: Missing 'manga' elements.");
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
const mangaArray = Array.isArray(mangaList) ? mangaList : [mangaList];
|
|
75
|
-
const isValid = mangaArray.every((manga) => {
|
|
76
|
-
const isValidId = manga.manga_mangadb_id && !isNaN(Number(manga.manga_mangadb_id));
|
|
77
|
-
const hasRequiredFields = manga.manga_title && manga.my_status;
|
|
78
|
-
return isValidId && hasRequiredFields;
|
|
79
|
-
});
|
|
80
|
-
if (!isValid) {
|
|
81
|
-
console.error('Validation failed: Some manga entries are missing required fields or have invalid IDs.');
|
|
82
|
-
}
|
|
83
|
-
return isValid;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
console.error('Error parsing or validating XML:', error);
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
76
|
+
return Validate.Import_MALXML(xmlData, 'manga', 'manga_mangadb_id', 'manga_title');
|
|
89
77
|
});
|
|
90
78
|
}
|
|
91
79
|
/**
|
package/bin/helpers/workers.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ declare function activityBy(activity: TheActivity, count?: number): string;
|
|
|
47
47
|
*/
|
|
48
48
|
declare function saveToPath(data_type: string, file_format: string): Promise<string>;
|
|
49
49
|
declare function simpleDateFormat(date: DateMonthYear): string;
|
|
50
|
+
declare function sleep(ms: number): Promise<void>;
|
|
50
51
|
declare function handleRateLimitRetry(retryCount: number): Promise<void>;
|
|
51
52
|
declare function logUserDetails(user: User, followersCount: number, followingCount: number): void;
|
|
52
|
-
export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, handleRateLimitRetry, logUserDetails, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, timestampToTimeAgo, };
|
|
53
|
+
export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, handleRateLimitRetry, logUserDetails, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, sleep, timestampToTimeAgo, };
|
package/bin/helpers/workers.js
CHANGED
|
@@ -420,6 +420,9 @@ function simpleDateFormat(date) {
|
|
|
420
420
|
}
|
|
421
421
|
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}`;
|
|
422
422
|
}
|
|
423
|
+
function sleep(ms) {
|
|
424
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
425
|
+
}
|
|
423
426
|
function handleRateLimitRetry(retryCount) {
|
|
424
427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
425
428
|
let seconds = Math.pow(2, retryCount) * 1000;
|
|
@@ -433,7 +436,7 @@ function handleRateLimitRetry(retryCount) {
|
|
|
433
436
|
if (remainingTime <= 0)
|
|
434
437
|
clearInterval(interval);
|
|
435
438
|
}, 1000);
|
|
436
|
-
yield
|
|
439
|
+
yield sleep(seconds);
|
|
437
440
|
clearInterval(interval);
|
|
438
441
|
spinner.stop();
|
|
439
442
|
});
|
|
@@ -473,4 +476,4 @@ function logUserDetails(user, followersCount, followingCount) {
|
|
|
473
476
|
'Volumes Read': ((_p = (_o = user.statistics) === null || _o === void 0 ? void 0 : _o.manga) === null || _p === void 0 ? void 0 : _p.volumesRead) || 0,
|
|
474
477
|
});
|
|
475
478
|
}
|
|
476
|
-
export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, handleRateLimitRetry, logUserDetails, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, timestampToTimeAgo, };
|
|
479
|
+
export { activityBy, anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, handleRateLimitRetry, logUserDetails, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, sleep, timestampToTimeAgo, };
|
package/bin/index.js
CHANGED
|
@@ -14,6 +14,28 @@ 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();
|
|
17
|
+
/**
|
|
18
|
+
* Dispatch to exactly one handler out of a set of mutually-exclusive options
|
|
19
|
+
* (eg: --anime/--manga, --follow/--unfollow/--inactive), optionally requiring login.
|
|
20
|
+
*/
|
|
21
|
+
function dispatchOneOf(options_1) {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (options, { requireLogin = false } = {}) {
|
|
23
|
+
const selected = options.filter(({ flag }) => flag);
|
|
24
|
+
if (selected.length !== 1) {
|
|
25
|
+
const names = options.map(({ name }) => `--${name}`);
|
|
26
|
+
const optionList = names.length <= 2
|
|
27
|
+
? names.join(' or ')
|
|
28
|
+
: `${names.slice(0, -1).join(', ')} or ${names[names.length - 1]}`;
|
|
29
|
+
console.error(`\nMust select an option, either ${optionList}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (requireLogin && !(yield Auth.isLoggedIn())) {
|
|
33
|
+
console.error(`\nPlease login to use this feature.`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
yield selected[0].handler();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
17
39
|
cli
|
|
18
40
|
.name('anilist')
|
|
19
41
|
.description('Minimalist unofficial AniList CLI for Anime and Manga Enthusiasts.')
|
|
@@ -72,15 +94,10 @@ cli
|
|
|
72
94
|
.option('-a, --anime', 'For anime list of authenticated user', false)
|
|
73
95
|
.option('-m, --manga', 'For manga list of authenticated user', false)
|
|
74
96
|
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
yield AniList.MyAnime();
|
|
80
|
-
}
|
|
81
|
-
else if (manga) {
|
|
82
|
-
yield AniList.MyManga();
|
|
83
|
-
}
|
|
97
|
+
return dispatchOneOf([
|
|
98
|
+
{ flag: anime, name: 'anime', handler: AniList.MyAnime },
|
|
99
|
+
{ flag: manga, name: 'manga', handler: AniList.MyManga },
|
|
100
|
+
]);
|
|
84
101
|
}));
|
|
85
102
|
cli
|
|
86
103
|
.command('delete')
|
|
@@ -144,20 +161,18 @@ cli
|
|
|
144
161
|
.option('-m, --manga', 'To get the manga search results.', false)
|
|
145
162
|
.option('-c, --count <number>', 'Number of search results to show.', '10')
|
|
146
163
|
.action((query_1, _a) => __awaiter(void 0, [query_1, _a], void 0, function* (query, { anime, manga, count }) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
164
|
+
return dispatchOneOf([
|
|
165
|
+
{
|
|
166
|
+
flag: anime,
|
|
167
|
+
name: 'anime',
|
|
168
|
+
handler: () => AniList.searchAnime(query, Number(count)),
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
flag: manga,
|
|
172
|
+
name: 'manga',
|
|
173
|
+
handler: () => AniList.searchManga(query, Number(count)),
|
|
174
|
+
},
|
|
175
|
+
]);
|
|
161
176
|
}));
|
|
162
177
|
cli
|
|
163
178
|
.command('status <status>')
|
|
@@ -174,17 +189,10 @@ cli
|
|
|
174
189
|
.option('-a, --anime', 'To get the anime search results.', false)
|
|
175
190
|
.option('-m, --manga', 'To get the manga search results.', false)
|
|
176
191
|
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (anime) {
|
|
182
|
-
yield AniList.exportAnime();
|
|
183
|
-
}
|
|
184
|
-
else if (manga) {
|
|
185
|
-
yield AniList.exportManga();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
192
|
+
return dispatchOneOf([
|
|
193
|
+
{ flag: anime, name: 'anime', handler: AniList.exportAnime },
|
|
194
|
+
{ flag: manga, name: 'manga', handler: AniList.exportManga },
|
|
195
|
+
]);
|
|
188
196
|
}));
|
|
189
197
|
cli
|
|
190
198
|
.command('import')
|
|
@@ -193,22 +201,10 @@ cli
|
|
|
193
201
|
.option('-a, --anime', 'To get the anime search results.', false)
|
|
194
202
|
.option('-m, --manga', 'To get the manga search results.', false)
|
|
195
203
|
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (yield Auth.isLoggedIn()) {
|
|
201
|
-
if (anime) {
|
|
202
|
-
yield Auth.callAnimeImporter();
|
|
203
|
-
}
|
|
204
|
-
else if (manga) {
|
|
205
|
-
yield Auth.callMangaImporter();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
console.error(`\nPlease login to use this feature.`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
204
|
+
return dispatchOneOf([
|
|
205
|
+
{ flag: anime, name: 'anime', handler: Auth.callAnimeImporter },
|
|
206
|
+
{ flag: manga, name: 'manga', handler: Auth.callMangaImporter },
|
|
207
|
+
], { requireLogin: true });
|
|
212
208
|
}));
|
|
213
209
|
cli
|
|
214
210
|
.command('autolike')
|
|
@@ -223,22 +219,16 @@ cli
|
|
|
223
219
|
.description('Automate your process')
|
|
224
220
|
.option('-f, --follow', 'Follow the user whos following you.', false)
|
|
225
221
|
.option('-u, --unfollow', 'Unfollow the user whos not following you.', false)
|
|
226
|
-
.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
console.error(`\nPlease login to use this feature.`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
222
|
+
.option('-i, --inactive <months>', 'Unfollow users you follow with no activity in this many months')
|
|
223
|
+
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ follow, unfollow, inactive }) {
|
|
224
|
+
return dispatchOneOf([
|
|
225
|
+
{ flag: follow, name: 'follow', handler: Social.follow },
|
|
226
|
+
{ flag: unfollow, name: 'unfollow', handler: Social.unfollow },
|
|
227
|
+
{
|
|
228
|
+
flag: inactive !== undefined,
|
|
229
|
+
name: 'inactive <months>',
|
|
230
|
+
handler: () => Social.unfollowInactive(Number(inactive)),
|
|
231
|
+
},
|
|
232
|
+
], { requireLogin: true });
|
|
243
233
|
}));
|
|
244
234
|
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": "2.0.0-forbidden",
|
|
5
|
+
"version": "2.0.0-forbidden.0",
|
|
6
6
|
"main": "./bin/index.js",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./bin/index.d.ts",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"lint": "eslint ./dist",
|
|
21
21
|
"lint:fix": "eslint ./dist --fix",
|
|
22
22
|
"all": "npm run build && npm run lint && npm run lint:fix && npm run format && npm test",
|
|
23
|
-
"test": "jest ./tests"
|
|
23
|
+
"test": "jest ./tests",
|
|
24
|
+
"prepare": "husky"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|
|
26
27
|
"anilist",
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
66
67
|
"eslint": "^9.31.0",
|
|
67
68
|
"globals": "^16.3.0",
|
|
69
|
+
"husky": "^9.1.7",
|
|
68
70
|
"jest": "^30.0.4",
|
|
69
71
|
"prettier": "^3.6.2",
|
|
70
72
|
"prettier-plugin-organize-imports": "^4.1.0",
|