@irfanshadikrishad/anilist 1.9.8 → 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 +1 -1
- package/LICENSE.md +382 -0
- package/README.md +33 -42
- package/bin/helpers/auth.d.ts +31 -6
- package/bin/helpers/auth.js +536 -252
- package/bin/helpers/fetcher.d.ts +2 -2
- package/bin/helpers/fetcher.js +7 -6
- package/bin/helpers/lists.d.ts +41 -5
- package/bin/helpers/lists.js +356 -848
- package/bin/helpers/mutations.d.ts +2 -2
- package/bin/helpers/mutations.js +6 -9
- package/bin/helpers/queries.d.ts +4 -1
- package/bin/helpers/queries.js +35 -1
- package/bin/helpers/types.d.ts +53 -15
- package/bin/helpers/validation.d.ts +13 -4
- package/bin/helpers/validation.js +47 -56
- package/bin/helpers/workers.d.ts +9 -7
- package/bin/helpers/workers.js +34 -10
- package/bin/index.js +69 -93
- package/package.json +89 -92
- package/CITATION.cff +0 -8
- /package/bin/{lib → helpers/lib}/colorize.d.ts +0 -0
- /package/bin/{lib → helpers/lib}/colorize.js +0 -0
|
@@ -4,8 +4,8 @@ declare const deleteActivityMutation = "\nmutation($id: Int!) { DeleteActivity(i
|
|
|
4
4
|
declare const saveTextActivityMutation = "\nmutation SaveTextActivity($status: String!) { SaveTextActivity(text: $status) { id text userId createdAt } }\n";
|
|
5
5
|
declare const saveAnimeWithProgressMutation = "\nmutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean) {\n SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists) {\n id progress hiddenFromStatusLists\n }\n}\n";
|
|
6
6
|
declare const saveMangaWithProgressMutation = "\nmutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean, $private: Boolean) {\n SaveMediaListEntry( mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists, private: $private\n ) { id progress hiddenFromStatusLists private }\n}\n";
|
|
7
|
+
declare const likeActivityMutation = "\nmutation($activityId: Int!) {\n ToggleLike(id: $activityId, type: ACTIVITY) { id }\n}\n";
|
|
7
8
|
declare const toggleFollowMutation = "mutation ($userId: Int!) { ToggleFollow(userId: $userId) { id name isFollower isFollowing } }";
|
|
8
9
|
declare const deleteMediaEntryMutation = "mutation($id: Int!) { DeleteMediaListEntry(id: $id) { deleted } }";
|
|
9
10
|
declare const deleteMangaEntryMutation = "mutation($id: Int) {\n DeleteMediaListEntry(id: $id) { deleted }\n}";
|
|
10
|
-
|
|
11
|
-
export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, moveListMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, toggleFollowMutation, };
|
|
11
|
+
export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, likeActivityMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, toggleFollowMutation, };
|
package/bin/helpers/mutations.js
CHANGED
|
@@ -29,17 +29,14 @@ mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromSt
|
|
|
29
29
|
) { id progress hiddenFromStatusLists private }
|
|
30
30
|
}
|
|
31
31
|
`;
|
|
32
|
+
const likeActivityMutation = `
|
|
33
|
+
mutation($activityId: Int!) {
|
|
34
|
+
ToggleLike(id: $activityId, type: ACTIVITY) { id }
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
32
37
|
const toggleFollowMutation = `mutation ($userId: Int!) { ToggleFollow(userId: $userId) { id name isFollower isFollowing } }`;
|
|
33
38
|
const deleteMediaEntryMutation = `mutation($id: Int!) { DeleteMediaListEntry(id: $id) { deleted } }`;
|
|
34
39
|
const deleteMangaEntryMutation = `mutation($id: Int) {
|
|
35
40
|
DeleteMediaListEntry(id: $id) { deleted }
|
|
36
41
|
}`;
|
|
37
|
-
|
|
38
|
-
SaveMediaListEntry(
|
|
39
|
-
mediaId: $mediaId
|
|
40
|
-
status: $status
|
|
41
|
-
customLists: [$customList]
|
|
42
|
-
hiddenFromStatusLists: true
|
|
43
|
-
) { id status hiddenFromStatusLists customLists media { title { romaji english native userPreferred } } }
|
|
44
|
-
}`;
|
|
45
|
-
export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, moveListMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, toggleFollowMutation, };
|
|
42
|
+
export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, likeActivityMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, toggleFollowMutation, };
|
package/bin/helpers/queries.d.ts
CHANGED
|
@@ -17,7 +17,10 @@ declare const activityAllQuery = "query ($userId: Int, $page: Int, $perPage: Int
|
|
|
17
17
|
declare const activityMediaList = "query ($userId: Int, $page: Int, $perPage: Int, $type: ActivityType) {\n Page(page: $page, perPage: $perPage) {\n pageInfo { total currentPage lastPage hasNextPage perPage }\n activities(userId: $userId, type: $type, sort: ID_DESC) {\n ... on ListActivity { id type status progress media { id title { romaji english native } format } createdAt }\n }\n }\n}";
|
|
18
18
|
declare const malIdToAnilistAnimeId = "query ($malId: Int) {\n Media(idMal: $malId, type: ANIME) { id title { romaji english } } }\n";
|
|
19
19
|
declare const malIdToAnilistMangaId = "query ($malId: Int) {\n Media(idMal: $malId, type: MANGA) { id title { romaji english } } }\n";
|
|
20
|
+
declare const followingActivitiesQuery = "\nquery ($page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(isFollowing: true, sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
|
|
21
|
+
declare const globalActivitiesQuery = "\nquery ($page: Int, $perPage: Int) {\n Page(page: $page, perPage: $perPage) {\n activities(sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
|
|
22
|
+
declare const specificUserActivitiesQuery = "\nquery ($page: Int, $perPage: Int, $userId: Int) {\n Page(page: $page, perPage: $perPage) {\n pageInfo { total perPage currentPage lastPage hasNextPage }\n activities(userId: $userId, sort: ID_DESC) {\n ... on TextActivity { id type isLiked createdAt user { id name } }\n ... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }\n ... on MessageActivity { messenger { name } id type isLiked message createdAt recipient { id name } }\n }\n }\n}\n";
|
|
20
23
|
declare const userFollowingQuery = "query ($userId: Int!, $page: Int) {\n Page (page: $page) {\n pageInfo { total perPage currentPage lastPage hasNextPage }\n following(userId: $userId, sort: [USERNAME]) { id name avatar { large medium } bannerImage isFollowing isFollower }\n }\n}\n";
|
|
21
24
|
declare const userFollowersQuery = "query ($userId: Int!, $page: Int) {\n Page (page: $page) {\n pageInfo { total perPage currentPage lastPage hasNextPage }\n followers(userId: $userId, sort: [USERNAME]) { id name avatar { large medium } bannerImage isFollowing isFollower }\n }\n}\n";
|
|
22
25
|
declare const mangaDetailsQuery = "query ($id: Int) {\n Media(id: $id, type: MANGA) {\n id title { romaji english native userPreferred } coverImage { color medium large extraLarge } \n bannerImage description chapters volumes status genres\n startDate { year month day } endDate { year month day }\n }\n}\n";
|
|
23
|
-
export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaDetailsQuery, mangaSearchQuery, popularQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, };
|
|
26
|
+
export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, followingActivitiesQuery, globalActivitiesQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaDetailsQuery, mangaSearchQuery, popularQuery, specificUserActivitiesQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, };
|
package/bin/helpers/queries.js
CHANGED
|
@@ -119,6 +119,40 @@ const malIdToAnilistAnimeId = `query ($malId: Int) {
|
|
|
119
119
|
const malIdToAnilistMangaId = `query ($malId: Int) {
|
|
120
120
|
Media(idMal: $malId, type: MANGA) { id title { romaji english } } }
|
|
121
121
|
`;
|
|
122
|
+
const followingActivitiesQuery = `
|
|
123
|
+
query ($page: Int, $perPage: Int) {
|
|
124
|
+
Page(page: $page, perPage: $perPage) {
|
|
125
|
+
activities(isFollowing: true, sort: ID_DESC) {
|
|
126
|
+
... on TextActivity { id type isLiked createdAt user { id name } }
|
|
127
|
+
... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }
|
|
128
|
+
... on MessageActivity { id type isLiked message createdAt recipient { id name } }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
const globalActivitiesQuery = `
|
|
134
|
+
query ($page: Int, $perPage: Int) {
|
|
135
|
+
Page(page: $page, perPage: $perPage) {
|
|
136
|
+
activities(sort: ID_DESC) {
|
|
137
|
+
... on TextActivity { id type isLiked createdAt user { id name } }
|
|
138
|
+
... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }
|
|
139
|
+
... on MessageActivity { id type isLiked message createdAt recipient { id name } }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
const specificUserActivitiesQuery = `
|
|
145
|
+
query ($page: Int, $perPage: Int, $userId: Int) {
|
|
146
|
+
Page(page: $page, perPage: $perPage) {
|
|
147
|
+
pageInfo { total perPage currentPage lastPage hasNextPage }
|
|
148
|
+
activities(userId: $userId, sort: ID_DESC) {
|
|
149
|
+
... on TextActivity { id type isLiked createdAt user { id name } }
|
|
150
|
+
... on ListActivity { id type isLiked status progress media { title { userPreferred } } createdAt user { id name } }
|
|
151
|
+
... on MessageActivity { messenger { name } id type isLiked message createdAt recipient { id name } }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
122
156
|
const userFollowingQuery = `query ($userId: Int!, $page: Int) {
|
|
123
157
|
Page (page: $page) {
|
|
124
158
|
pageInfo { total perPage currentPage lastPage hasNextPage }
|
|
@@ -141,4 +175,4 @@ const mangaDetailsQuery = `query ($id: Int) {
|
|
|
141
175
|
}
|
|
142
176
|
}
|
|
143
177
|
`;
|
|
144
|
-
export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaDetailsQuery, mangaSearchQuery, popularQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, };
|
|
178
|
+
export { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, followingActivitiesQuery, globalActivitiesQuery, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaDetailsQuery, mangaSearchQuery, popularQuery, specificUserActivitiesQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, };
|
package/bin/helpers/types.d.ts
CHANGED
|
@@ -323,6 +323,58 @@ type Activity = {
|
|
|
323
323
|
};
|
|
324
324
|
createdAt: number;
|
|
325
325
|
};
|
|
326
|
+
interface TheActivity {
|
|
327
|
+
type: string;
|
|
328
|
+
id: number;
|
|
329
|
+
message?: string;
|
|
330
|
+
createdAt: number;
|
|
331
|
+
recipient?: {
|
|
332
|
+
id: number;
|
|
333
|
+
name: string;
|
|
334
|
+
};
|
|
335
|
+
isLiked?: boolean;
|
|
336
|
+
user?: {
|
|
337
|
+
id?: number;
|
|
338
|
+
name?: string;
|
|
339
|
+
};
|
|
340
|
+
messenger?: {
|
|
341
|
+
name: string;
|
|
342
|
+
};
|
|
343
|
+
media?: {
|
|
344
|
+
title?: {
|
|
345
|
+
userPreferred: string;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
progress?: string | null;
|
|
349
|
+
status?: string;
|
|
350
|
+
}
|
|
351
|
+
type LikeActivityResponse = {
|
|
352
|
+
data?: {
|
|
353
|
+
ToggleLike: {
|
|
354
|
+
id: number;
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
errors?: {
|
|
358
|
+
message: string;
|
|
359
|
+
}[];
|
|
360
|
+
};
|
|
361
|
+
type SpecificUserActivitiesResponse = {
|
|
362
|
+
data?: {
|
|
363
|
+
Page: {
|
|
364
|
+
pageInfo: {
|
|
365
|
+
total: number;
|
|
366
|
+
perPage: number;
|
|
367
|
+
currentPage: number;
|
|
368
|
+
lastPage: number;
|
|
369
|
+
hasNextPage: boolean;
|
|
370
|
+
};
|
|
371
|
+
activities: TheActivity[];
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
errors?: {
|
|
375
|
+
message: string;
|
|
376
|
+
}[];
|
|
377
|
+
};
|
|
326
378
|
type CoverImage = {
|
|
327
379
|
color: string;
|
|
328
380
|
medium: string;
|
|
@@ -347,18 +399,4 @@ type MangaDetails = {
|
|
|
347
399
|
};
|
|
348
400
|
errors?: Error;
|
|
349
401
|
};
|
|
350
|
-
|
|
351
|
-
data?: {
|
|
352
|
-
SaveMediaListEntry: {
|
|
353
|
-
id: 474487691;
|
|
354
|
-
status: 'COMPLETED';
|
|
355
|
-
hiddenFromStatusLists: true;
|
|
356
|
-
customLists: Record<string, boolean>;
|
|
357
|
-
media: {
|
|
358
|
-
title: MediaTitle;
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
errors?: Error;
|
|
363
|
-
};
|
|
364
|
-
export { Activity, AniListMediaStatus, AnimeDetails, AnimeList, AnimeSearchResponse, DateMonthYear, DeleteMangaResponse, DeleteMediaListResponse, List, MALAnimeStatus, MALAnimeXML, MALMangaStatus, MalIdToAnilistIdResponse, MangaDetails, MediaEntry, MediaList, MediaListCollectionResponse, MediaListEntry, MediaTitle, MediaWithProgress, MoveListsResponse, Myself, SaveMediaListEntryResponse, SaveTextActivityResponse, ToggleFollowResponse, User, UserActivitiesResponse, UserFollower, UserFollowing, UserResponse, saveAnimeWithProgressResponse, };
|
|
402
|
+
export { Activity, AniListMediaStatus, AnimeDetails, AnimeList, AnimeSearchResponse, DateMonthYear, DeleteMangaResponse, DeleteMediaListResponse, LikeActivityResponse, List, MALAnimeStatus, MALAnimeXML, MALMangaStatus, MalIdToAnilistIdResponse, MangaDetails, MediaEntry, MediaList, MediaListCollectionResponse, MediaListEntry, MediaTitle, MediaWithProgress, Myself, SaveMediaListEntryResponse, SaveTextActivityResponse, SpecificUserActivitiesResponse, TheActivity, ToggleFollowResponse, User, UserActivitiesResponse, UserFollower, UserFollowing, UserResponse, saveAnimeWithProgressResponse, };
|
|
@@ -7,18 +7,27 @@ 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
|
-
* @param
|
|
13
|
-
* @returns
|
|
21
|
+
* @param xmlData string
|
|
22
|
+
* @returns boolean
|
|
14
23
|
*/
|
|
15
|
-
static Import_AnimeXML(xmlData: string): boolean
|
|
24
|
+
static Import_AnimeXML(xmlData: string): Promise<boolean>;
|
|
16
25
|
/**
|
|
17
26
|
* Validate if MyAnimeList Manga XML file is valid or not
|
|
18
27
|
* @param xmlData string
|
|
19
28
|
* @returns boolean
|
|
20
29
|
*/
|
|
21
|
-
static Import_MangaXML(xmlData: string): boolean
|
|
30
|
+
static Import_MangaXML(xmlData: string): Promise<boolean>;
|
|
22
31
|
/**
|
|
23
32
|
* Validate AniDB json-large file
|
|
24
33
|
* @param file string of anidb json-large
|
|
@@ -7,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
const parser = new XMLParser({ ignoreAttributes: false });
|
|
10
|
+
import { parseStringPromise } from 'xml2js';
|
|
12
11
|
class Validate {
|
|
13
12
|
/**
|
|
14
13
|
* Validate importable JSON file
|
|
@@ -20,37 +19,52 @@ class Validate {
|
|
|
20
19
|
data.every((item) => typeof item === 'object' && item !== null && 'id' in item));
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
* Validate if MyAnimeList
|
|
24
|
-
* @param
|
|
25
|
-
* @
|
|
22
|
+
* Validate if a MyAnimeList anime/manga export XML file is valid or not
|
|
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)
|
|
27
|
+
* @returns boolean
|
|
26
28
|
*/
|
|
27
|
-
static
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
static Import_MALXML(xmlData, listKey, idField, titleField) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
try {
|
|
32
|
+
const result = yield parseStringPromise(xmlData, { explicitArray: false });
|
|
33
|
+
if (!result || !result.myanimelist) {
|
|
34
|
+
console.error("Invalid XML structure: Missing 'myanimelist' root element.");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const list = result.myanimelist[listKey];
|
|
38
|
+
if (!list) {
|
|
39
|
+
console.error(`Invalid XML structure: Missing '${listKey}' elements.`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
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;
|
|
46
|
+
return isValidId && hasRequiredFields;
|
|
47
|
+
});
|
|
48
|
+
if (!isValid) {
|
|
49
|
+
console.error(`Validation failed: Some ${listKey} entries are missing required fields or have invalid IDs.`);
|
|
50
|
+
}
|
|
51
|
+
return isValid;
|
|
33
52
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.error("Invalid XML structure: Missing 'anime' elements.");
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error parsing or validating XML:', error);
|
|
37
55
|
return false;
|
|
38
56
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error('Error parsing or validating XML:', error);
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validate if MyAnimeList Anime XML file is valid or not
|
|
61
|
+
* @param xmlData string
|
|
62
|
+
* @returns boolean
|
|
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
|
+
});
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
56
70
|
* Validate if MyAnimeList Manga XML file is valid or not
|
|
@@ -58,32 +72,9 @@ class Validate {
|
|
|
58
72
|
* @returns boolean
|
|
59
73
|
*/
|
|
60
74
|
static Import_MangaXML(xmlData) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
console.error("Invalid XML structure: Missing 'myanimelist' root element.");
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const mangaList = result.myanimelist.manga;
|
|
68
|
-
if (!mangaList) {
|
|
69
|
-
console.error("Invalid XML structure: Missing 'manga' elements.");
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const mangaArray = Array.isArray(mangaList) ? mangaList : [mangaList];
|
|
73
|
-
const isValid = mangaArray.every((manga) => {
|
|
74
|
-
const isValidId = manga.manga_mangadb_id && !isNaN(Number(manga.manga_mangadb_id));
|
|
75
|
-
const hasRequiredFields = manga.manga_title && manga.my_status;
|
|
76
|
-
return isValidId && hasRequiredFields;
|
|
77
|
-
});
|
|
78
|
-
if (!isValid) {
|
|
79
|
-
console.error('Validation failed: Some manga entries are missing required fields or have invalid IDs.');
|
|
80
|
-
}
|
|
81
|
-
return isValid;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error('Error parsing or validating XML:', error);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
return Validate.Import_MALXML(xmlData, 'manga', 'manga_mangadb_id', 'manga_title');
|
|
77
|
+
});
|
|
87
78
|
}
|
|
88
79
|
/**
|
|
89
80
|
* Validate AniDB json-large file
|
|
@@ -97,7 +88,7 @@ class Validate {
|
|
|
97
88
|
console.error('File content is empty or invalid.');
|
|
98
89
|
return false;
|
|
99
90
|
}
|
|
100
|
-
const obj3ct =
|
|
91
|
+
const obj3ct = JSON.parse(file);
|
|
101
92
|
if (!obj3ct || !Array.isArray(obj3ct.anime)) {
|
|
102
93
|
console.error("Invalid JSON structure: Missing or malformed 'anime' array.");
|
|
103
94
|
return false;
|
package/bin/helpers/workers.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DateMonthYear, MALAnimeStatus, MALMangaStatus, MediaWithProgress, User } from './types.js';
|
|
1
|
+
import { DateMonthYear, MALAnimeStatus, MALMangaStatus, MediaWithProgress, TheActivity, User } 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
|
-
declare function getTitle(title
|
|
4
|
+
declare function getTitle(title: {
|
|
5
5
|
english?: string;
|
|
6
6
|
romaji?: string;
|
|
7
7
|
}): string;
|
|
8
8
|
declare function formatDateObject(dateObj: {
|
|
9
|
-
day?: number
|
|
10
|
-
month?: number
|
|
11
|
-
year?: number
|
|
9
|
+
day?: number;
|
|
10
|
+
month?: number;
|
|
11
|
+
year?: number;
|
|
12
12
|
} | null): string;
|
|
13
13
|
declare function getNextSeasonAndYear(): {
|
|
14
14
|
nextSeason: string;
|
|
@@ -30,7 +30,7 @@ declare function saveJSONasJSON(js0n: object, dataType: string): Promise<void>;
|
|
|
30
30
|
*/
|
|
31
31
|
declare function saveJSONasCSV(js0n: MediaWithProgress[], dataType: string): Promise<void>;
|
|
32
32
|
declare function saveJSONasXML(js0n: MediaWithProgress[], data_type: 0 | 1): Promise<void>;
|
|
33
|
-
declare function selectFile(fileType: string): Promise<string
|
|
33
|
+
declare function selectFile(fileType: string): Promise<string>;
|
|
34
34
|
declare function createAnimeXML(malId: number, progress: number, status: MALAnimeStatus, episodes: number, title: string, format: string): string;
|
|
35
35
|
declare function createMangaXML(malId: number, progress: number, status: MALMangaStatus, chapters: number, title: string): string;
|
|
36
36
|
declare function createAnimeListXML(mediaWithProgress: MediaWithProgress[]): Promise<string>;
|
|
@@ -38,6 +38,7 @@ declare function createMangaListXML(mediaWithProgress: MediaWithProgress[]): Pro
|
|
|
38
38
|
declare function getCurrentPackageVersion(): string | null;
|
|
39
39
|
declare function timestampToTimeAgo(timestamp: number): string;
|
|
40
40
|
declare const anidbToanilistMapper: (romanjiName: string, year: number, englishName?: string) => Promise<number | null>;
|
|
41
|
+
declare function activityBy(activity: TheActivity, count?: number): string;
|
|
41
42
|
/**
|
|
42
43
|
* Extract the save file path
|
|
43
44
|
* @param data_type - anime|manga
|
|
@@ -46,6 +47,7 @@ declare const anidbToanilistMapper: (romanjiName: string, year: number, englishN
|
|
|
46
47
|
*/
|
|
47
48
|
declare function saveToPath(data_type: string, file_format: string): Promise<string>;
|
|
48
49
|
declare function simpleDateFormat(date: DateMonthYear): string;
|
|
50
|
+
declare function sleep(ms: number): Promise<void>;
|
|
49
51
|
declare function handleRateLimitRetry(retryCount: number): Promise<void>;
|
|
50
52
|
declare function logUserDetails(user: User, followersCount: number, followingCount: number): void;
|
|
51
|
-
export { 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
|
@@ -47,8 +47,8 @@ function formatDateObject(dateObj) {
|
|
|
47
47
|
function getNextSeasonAndYear() {
|
|
48
48
|
const currentMonth = new Date().getMonth() + 1;
|
|
49
49
|
const currentYear = new Date().getFullYear();
|
|
50
|
-
let nextSeason
|
|
51
|
-
let nextYear
|
|
50
|
+
let nextSeason;
|
|
51
|
+
let nextYear;
|
|
52
52
|
// Determine the current season
|
|
53
53
|
if (currentMonth >= 12 || currentMonth <= 2) {
|
|
54
54
|
nextSeason = 'SPRING';
|
|
@@ -174,16 +174,17 @@ function selectFile(fileType) {
|
|
|
174
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
175
|
try {
|
|
176
176
|
const files = yield listFilesInDownloadFolder();
|
|
177
|
+
console.log(getDownloadFolderPath());
|
|
177
178
|
// Filter to include only files, not directories, with the specified extension
|
|
178
179
|
const onlyFiles = files.filter((file) => {
|
|
179
|
-
const filePath = `${getDownloadFolderPath()}/${file}`;
|
|
180
|
+
const filePath = `${getDownloadFolderPath()}/${file}`; // Adjust this to the correct path
|
|
180
181
|
const isFile = fs.lstatSync(filePath).isFile(); // Check if it's a file
|
|
181
182
|
return isFile && file.endsWith(fileType);
|
|
182
183
|
});
|
|
183
184
|
if (onlyFiles.length > 0) {
|
|
184
185
|
const answers = yield inquirer.prompt([
|
|
185
186
|
{
|
|
186
|
-
type: '
|
|
187
|
+
type: 'list',
|
|
187
188
|
name: 'fileName',
|
|
188
189
|
message: 'Select a file to import:',
|
|
189
190
|
choices: onlyFiles,
|
|
@@ -260,14 +261,13 @@ function createAnimeListXML(mediaWithProgress) {
|
|
|
260
261
|
// Filter out anime without malId
|
|
261
262
|
const filteredMedia = mediaWithProgress.filter((anime) => anime.malId);
|
|
262
263
|
const xmlEntries = filteredMedia.map((anime) => {
|
|
263
|
-
console.log(anime);
|
|
264
264
|
const malId = anime.malId;
|
|
265
265
|
const progress = anime.progress;
|
|
266
266
|
const episodes = anime.episodes;
|
|
267
267
|
const title = getTitle(anime.title);
|
|
268
268
|
const status = statusMap[anime.status];
|
|
269
269
|
const format = anime.format ? anime.format : '';
|
|
270
|
-
return createAnimeXML(malId
|
|
270
|
+
return createAnimeXML(malId, progress, status, episodes, title, format);
|
|
271
271
|
});
|
|
272
272
|
return `<myanimelist>
|
|
273
273
|
<myinfo>
|
|
@@ -302,7 +302,7 @@ function createMangaListXML(mediaWithProgress) {
|
|
|
302
302
|
const chapters = manga.chapters;
|
|
303
303
|
const title = getTitle(manga.title);
|
|
304
304
|
const status = statusMap[manga.status];
|
|
305
|
-
return createMangaXML(malId
|
|
305
|
+
return createMangaXML(malId, progress, status, chapters, title);
|
|
306
306
|
});
|
|
307
307
|
return `<myanimelist>
|
|
308
308
|
<myinfo>
|
|
@@ -361,7 +361,7 @@ const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void
|
|
|
361
361
|
search,
|
|
362
362
|
perPage: 50,
|
|
363
363
|
});
|
|
364
|
-
return ((_a = response
|
|
364
|
+
return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.Page.media) || [];
|
|
365
365
|
}
|
|
366
366
|
catch (error) {
|
|
367
367
|
console.error('Error fetching AniList data:', error);
|
|
@@ -382,6 +382,27 @@ const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void
|
|
|
382
382
|
}
|
|
383
383
|
return null;
|
|
384
384
|
});
|
|
385
|
+
function activityBy(activity, count) {
|
|
386
|
+
var _a, _b, _c, _d;
|
|
387
|
+
const countStr = `[${count ? count : '?'}]`.padEnd(6);
|
|
388
|
+
if ((_a = activity === null || activity === void 0 ? void 0 : activity.messenger) === null || _a === void 0 ? void 0 : _a.name) {
|
|
389
|
+
return `${countStr}${activity.messenger.name} >> messaged ${activity.recipient.name}`;
|
|
390
|
+
}
|
|
391
|
+
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) {
|
|
392
|
+
if (activity.progress) {
|
|
393
|
+
return `${countStr}${activity.user.name} >> ${activity.status} ${activity.progress} of ${activity.media.title.userPreferred}`;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
return `${countStr}${activity.user.name} >> ${activity.status} ${activity.media.title.userPreferred}`;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if ((_d = activity === null || activity === void 0 ? void 0 : activity.user) === null || _d === void 0 ? void 0 : _d.name) {
|
|
400
|
+
return `${countStr}${activity.user.name}`;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
return `${countStr}???`;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
385
406
|
/**
|
|
386
407
|
* Extract the save file path
|
|
387
408
|
* @param data_type - anime|manga
|
|
@@ -399,6 +420,9 @@ function simpleDateFormat(date) {
|
|
|
399
420
|
}
|
|
400
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}`;
|
|
401
422
|
}
|
|
423
|
+
function sleep(ms) {
|
|
424
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
425
|
+
}
|
|
402
426
|
function handleRateLimitRetry(retryCount) {
|
|
403
427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
404
428
|
let seconds = Math.pow(2, retryCount) * 1000;
|
|
@@ -412,7 +436,7 @@ function handleRateLimitRetry(retryCount) {
|
|
|
412
436
|
if (remainingTime <= 0)
|
|
413
437
|
clearInterval(interval);
|
|
414
438
|
}, 1000);
|
|
415
|
-
yield
|
|
439
|
+
yield sleep(seconds);
|
|
416
440
|
clearInterval(interval);
|
|
417
441
|
spinner.stop();
|
|
418
442
|
});
|
|
@@ -452,4 +476,4 @@ function logUserDetails(user, followersCount, followingCount) {
|
|
|
452
476
|
'Volumes Read': ((_p = (_o = user.statistics) === null || _o === void 0 ? void 0 : _o.manga) === null || _p === void 0 ? void 0 : _p.volumesRead) || 0,
|
|
453
477
|
});
|
|
454
478
|
}
|
|
455
|
-
export { 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, };
|