@irfanshadikrishad/anilist 1.0.1-forbidden.2 → 1.0.1-forbidden.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.
@@ -13,6 +13,7 @@ import fetch from "node-fetch";
13
13
  import open from "open";
14
14
  import os from "os";
15
15
  import path from "path";
16
+ import { exit } from "process";
16
17
  import Spinner from "tiny-spinner";
17
18
  import { fetcher } from "./fetcher.js";
18
19
  import { AniDB, AniList, MyAnimeList } from "./lists.js";
@@ -151,33 +152,33 @@ class Auth {
151
152
  });
152
153
  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;
153
154
  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;
154
- console.log(`
155
- ID: ${user === null || user === void 0 ? void 0 : user.id}
156
- Name: ${user === null || user === void 0 ? void 0 : user.name}
157
- siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
158
- profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
159
- timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
160
- activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
161
- donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
162
- donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
163
- unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
164
- Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
165
- Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
166
-
167
- Followers: ${followersCount}
168
- Following: ${followingCount}
169
-
170
- Statistics (Anime):
171
- 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}
172
- 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}
173
- 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}
174
- 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}
175
-
176
- Statistics (Manga):
177
- 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}
178
- 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}
179
- 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}
180
- 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
+ console.log(`
156
+ ID: ${user === null || user === void 0 ? void 0 : user.id}
157
+ Name: ${user === null || user === void 0 ? void 0 : user.name}
158
+ siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
159
+ profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
160
+ timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
161
+ activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
162
+ donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
163
+ donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
164
+ unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
165
+ Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
166
+ Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
167
+
168
+ Followers: ${followersCount}
169
+ Following: ${followingCount}
170
+
171
+ Statistics (Anime):
172
+ 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}
173
+ 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}
174
+ 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}
175
+ 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}
176
+
177
+ Statistics (Manga):
178
+ 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}
179
+ 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}
180
+ 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}
181
+ 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}
181
182
  `);
182
183
  console.log(`\nRecent Activities:`);
183
184
  if (activities.length > 0) {
@@ -570,7 +571,7 @@ Statistics (Manga):
570
571
  }
571
572
  static LikeFollowing() {
572
573
  return __awaiter(this, void 0, void 0, function* () {
573
- var _a, _b, _c, _d;
574
+ var _a, _b, _c, _d, _e, _f;
574
575
  try {
575
576
  let page = 1;
576
577
  let hasMoreActivities = true;
@@ -582,8 +583,9 @@ Statistics (Manga):
582
583
  perPage: 50,
583
584
  });
584
585
  if (activities && ((_b = (_a = activities === null || activities === void 0 ? void 0 : activities.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities.length) > 0) {
586
+ spinner.success(`Got ${(_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities.length} activities..`);
585
587
  retryCount = 0; // Reset retry count on successful fetch
586
- const activiti = (_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
588
+ const activiti = (_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities;
587
589
  for (let activ of activiti) {
588
590
  if (!activ.isLiked && activ.id) {
589
591
  try {
@@ -608,13 +610,13 @@ Statistics (Manga):
608
610
  }
609
611
  else {
610
612
  if (retryCount < maxRetries) {
613
+ spinner.start("Getting activities...");
611
614
  retryCount++;
612
- console.warn(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
613
- yield new Promise((resolve) => setTimeout(resolve, 3000));
615
+ spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
616
+ yield new Promise((resolve) => setTimeout(resolve, 2000));
614
617
  }
615
618
  else {
616
- console.log(`\nProbably the end of activities after ${maxRetries} retries.`);
617
- console.info(activities);
619
+ spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
618
620
  hasMoreActivities = false;
619
621
  }
620
622
  }
@@ -625,24 +627,22 @@ Statistics (Manga):
625
627
  }
626
628
  });
627
629
  }
628
- static Like(type) {
630
+ static LikeGlobal() {
629
631
  return __awaiter(this, void 0, void 0, function* () {
630
- var _a, _b, _c, _d;
632
+ var _a, _b, _c, _d, _e, _f;
631
633
  try {
632
634
  let page = 1;
633
635
  let hasMoreActivities = true;
634
- let activity = type === 0
635
- ? followingActivitiesQuery
636
- : type === 1
637
- ? globalActivitiesQuery
638
- : followingActivitiesQuery;
636
+ let likedCount = 0;
637
+ spinner.start(`Getting global activities...`);
639
638
  while (hasMoreActivities) {
640
- const activities = yield fetcher(activity, {
639
+ const activities = yield fetcher(globalActivitiesQuery, {
641
640
  page,
642
641
  perPage: 50,
643
642
  });
644
643
  if (activities && ((_b = (_a = activities === null || activities === void 0 ? void 0 : activities.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities.length) > 0) {
645
644
  const activiti = (_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
645
+ spinner.success(`Got ${activiti.length} activities...`);
646
646
  for (let activ of activiti) {
647
647
  if (!activ.isLiked && activ.id) {
648
648
  try {
@@ -650,7 +650,8 @@ Statistics (Manga):
650
650
  activityId: activ.id,
651
651
  });
652
652
  // const ToggleLike = like?.data?.ToggleLike
653
- console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
653
+ likedCount++;
654
+ console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
654
655
  }
655
656
  catch (error) {
656
657
  console.error(`Activity possibly deleted. ${error.message}`);
@@ -668,8 +669,7 @@ Statistics (Manga):
668
669
  }
669
670
  else {
670
671
  // No more activities to like
671
- console.log(`\nProbably the end of activities.`);
672
- console.info(activities);
672
+ spinner.error(`Probably the end of activities. ${(_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities}`);
673
673
  hasMoreActivities = false;
674
674
  }
675
675
  }
@@ -681,7 +681,7 @@ Statistics (Manga):
681
681
  }
682
682
  static LikeSpecificUser() {
683
683
  return __awaiter(this, void 0, void 0, function* () {
684
- var _a, _b, _c, _d;
684
+ var _a, _b, _c, _d, _e, _f;
685
685
  try {
686
686
  const { username } = yield inquirer.prompt([
687
687
  {
@@ -691,10 +691,12 @@ Statistics (Manga):
691
691
  },
692
692
  ]);
693
693
  const userDetails = yield fetcher(userQuery, { username: username });
694
- if (userDetails) {
694
+ spinner.start(`Getting activities by ${username}`);
695
+ if ((_b = (_a = userDetails === null || userDetails === void 0 ? void 0 : userDetails.data) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.id) {
695
696
  let page = 1;
696
697
  const perPage = 50;
697
- const userId = (_b = (_a = userDetails === null || userDetails === void 0 ? void 0 : userDetails.data) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.id;
698
+ const userId = (_d = (_c = userDetails === null || userDetails === void 0 ? void 0 : userDetails.data) === null || _c === void 0 ? void 0 : _c.User) === null || _d === void 0 ? void 0 : _d.id;
699
+ let likedCount = 0;
698
700
  if (userId) {
699
701
  while (true) {
700
702
  const activities = yield fetcher(specificUserActivitiesQuery, {
@@ -702,19 +704,21 @@ Statistics (Manga):
702
704
  perPage,
703
705
  userId,
704
706
  });
705
- const activiti = (_d = (_c = activities === null || activities === void 0 ? void 0 : activities.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
707
+ const activiti = (_f = (_e = activities === null || activities === void 0 ? void 0 : activities.data) === null || _e === void 0 ? void 0 : _e.Page) === null || _f === void 0 ? void 0 : _f.activities;
706
708
  // Break the loop if no more activities are found
707
709
  if (!activiti || activiti.length === 0) {
708
- console.log("No more activities found.");
710
+ spinner.error("No more activities found.");
709
711
  break;
710
712
  }
713
+ spinner.success(`Got ${activiti.length} activities...`);
711
714
  for (let activ of activiti) {
712
715
  if (!activ.isLiked && activ.id) {
713
716
  try {
714
717
  const like = yield fetcher(likeActivityMutation, {
715
718
  activityId: activ.id,
716
719
  });
717
- console.info(`${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
720
+ likedCount++;
721
+ console.info(`${activityBy(activ, likedCount)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
718
722
  }
719
723
  catch (error) {
720
724
  console.error(`Activity possibly deleted. ${error.message}`);
@@ -733,6 +737,10 @@ Statistics (Manga):
733
737
  }
734
738
  }
735
739
  }
740
+ else {
741
+ spinner.error(`User ${username} does not exist.`);
742
+ exit(1);
743
+ }
736
744
  }
737
745
  catch (error) {
738
746
  console.error(`\nError from LikeSpecificUser. ${error.message}`);
@@ -750,8 +758,11 @@ Statistics (Manga):
750
758
  const allFollowingUsers = [];
751
759
  let hasNextPage = true;
752
760
  let page = 1;
761
+ let liked = 0;
753
762
  // Fetch all following users
763
+ spinner.start(`Gathering following information...`);
754
764
  while (hasNextPage) {
765
+ spinner.update(`Fetched page ${page}...`);
755
766
  const followingUsers = yield fetcher(userFollowingQuery, {
756
767
  userId: yield Auth.MyUserId(),
757
768
  page,
@@ -764,6 +775,7 @@ Statistics (Manga):
764
775
  hasNextPage = followingUsers.data.Page.pageInfo.hasNextPage;
765
776
  page++;
766
777
  }
778
+ spinner.stop(`Got ${allFollowingUsers.length} following user.`);
767
779
  // Extract the IDs of all following users
768
780
  const followingUserIds = allFollowingUsers.map((user) => user.id);
769
781
  console.log(`\nTotal Following: ${followingUserIds.length}\nApproximately ${followingUserIds.length * perPage} activities to like.\nWill take around ${((followingUserIds.length * perPage * 1200) /
@@ -793,6 +805,9 @@ Statistics (Manga):
793
805
  activityId: activ.id,
794
806
  });
795
807
  console.info(`[${userNumber}/${i + 1}/${activiti.length}] ${activityBy(activ)} ${(like === null || like === void 0 ? void 0 : like.data) ? "✅" : "❌"}`);
808
+ if (like === null || like === void 0 ? void 0 : like.data) {
809
+ liked++;
810
+ }
796
811
  }
797
812
  catch (error) {
798
813
  console.error(`[${userNumber}/${i + 1}/${activiti.length}] Activity possibly deleted. ${error.message}`);
@@ -805,7 +820,7 @@ Statistics (Manga):
805
820
  yield new Promise((resolve) => setTimeout(resolve, 1200));
806
821
  }
807
822
  }
808
- console.log(`\n✅ All activities liked successfully.`);
823
+ console.log(`\n✅ All ${liked} activities liked successfully.`);
809
824
  }
810
825
  catch (error) {
811
826
  console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
@@ -837,7 +852,7 @@ Statistics (Manga):
837
852
  yield this.LikeFollowing();
838
853
  break;
839
854
  case 2:
840
- yield this.Like(1);
855
+ yield this.LikeGlobal();
841
856
  break;
842
857
  case 3:
843
858
  yield this.LikeSpecificUser();
@@ -858,11 +873,12 @@ class Social {
858
873
  */
859
874
  static follow() {
860
875
  return __awaiter(this, void 0, void 0, function* () {
861
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
876
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
862
877
  try {
863
878
  let pager = 1;
864
879
  let hasNextPage = true;
865
880
  let allFollowerUsers = [];
881
+ let followedBack = 0;
866
882
  spinner.start("Fetching all the followers...");
867
883
  while (hasNextPage) {
868
884
  const followerUsers = yield fetcher(userFollowersQuery, {
@@ -895,12 +911,16 @@ class Social {
895
911
  console.log(`${String(`[${nf.id}]`).padEnd(maxIdLength)}` +
896
912
  `\t${String(`[${(_k = (_j = follow === null || follow === void 0 ? void 0 : follow.data) === null || _j === void 0 ? void 0 : _j.ToggleFollow) === null || _k === void 0 ? void 0 : _k.name}]`).padEnd(maxNameLength)}` +
897
913
  `\t${((_m = (_l = follow === null || follow === void 0 ? void 0 : follow.data) === null || _l === void 0 ? void 0 : _l.ToggleFollow) === null || _m === void 0 ? void 0 : _m.id) ? "✅" : "🈵"}`);
914
+ // Count the followed back users
915
+ if ((_p = (_o = follow === null || follow === void 0 ? void 0 : follow.data) === null || _o === void 0 ? void 0 : _o.ToggleFollow) === null || _p === void 0 ? void 0 : _p.id) {
916
+ followedBack++;
917
+ }
898
918
  }
899
919
  catch (error) {
900
920
  console.log(`automate_follow_toggle_follow: ${error.message}`);
901
921
  }
902
922
  }
903
- console.log(`\n✅ Followed back ${notFollowing.length} users.`);
923
+ console.log(`\n✅ Followed back ${followedBack} users.`);
904
924
  }
905
925
  catch (error) {
906
926
  console.log(`\nautomate_follow ${error.message}`);
@@ -912,18 +932,19 @@ class Social {
912
932
  */
913
933
  static unfollow() {
914
934
  return __awaiter(this, void 0, void 0, function* () {
915
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
935
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
916
936
  try {
917
937
  let pager = 1;
918
938
  let hasNextPage = true;
919
939
  let allFollowingUsers = [];
940
+ let unfollowedUsers = 0;
920
941
  spinner.start("Fetching all following users...");
921
942
  while (hasNextPage) {
922
943
  const followingUsers = yield fetcher(userFollowingQuery, {
923
944
  userId: yield Auth.MyUserId(),
924
945
  page: pager,
925
946
  });
926
- spinner.update(`Fetched page ${pager} of ${(_c = (_b = (_a = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.lastPage} ...`);
947
+ spinner.update(`Fetched page ${pager} of ${(_c = (_b = (_a = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.pageInfo) === null || _c === void 0 ? void 0 : _c.lastPage}...`);
927
948
  if (!((_f = (_e = (_d = followingUsers === null || followingUsers === void 0 ? void 0 : followingUsers.data) === null || _d === void 0 ? void 0 : _d.Page) === null || _e === void 0 ? void 0 : _e.pageInfo) === null || _f === void 0 ? void 0 : _f.hasNextPage)) {
928
949
  hasNextPage = false;
929
950
  }
@@ -936,8 +957,7 @@ class Social {
936
957
  .filter((user) => !user.isFollower)
937
958
  .map((u3r) => ({ id: u3r.id, name: u3r.name }));
938
959
  if (notFollowingMe.length <= 0) {
939
- console.warn(`\nNot following list is empty!`);
940
- spinner.stop(`No users to unfollow. Aborting process...`);
960
+ spinner.stop(`No users to unfollow. Exiting operation...`);
941
961
  return;
942
962
  }
943
963
  spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
@@ -950,12 +970,16 @@ class Social {
950
970
  userId: nfm.id,
951
971
  });
952
972
  console.log(`[${nfm.id}]\t[${(_k = (_j = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _j === void 0 ? void 0 : _j.ToggleFollow) === null || _k === void 0 ? void 0 : _k.name}]\t${((_m = (_l = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _l === void 0 ? void 0 : _l.ToggleFollow) === null || _m === void 0 ? void 0 : _m.id) ? "✅" : "🈵"}`);
973
+ // Count the unfollowed users
974
+ if ((_p = (_o = unfollow === null || unfollow === void 0 ? void 0 : unfollow.data) === null || _o === void 0 ? void 0 : _o.ToggleFollow) === null || _p === void 0 ? void 0 : _p.id) {
975
+ unfollowedUsers++;
976
+ }
953
977
  }
954
978
  catch (error) {
955
979
  console.log(`unfollow_toggle_follow. ${error.message}`);
956
980
  }
957
981
  }
958
- console.log(`\nTotal Unfollowed: ${nfmCount}`);
982
+ console.log(`\nTotal Unfollowed: ${unfollowedUsers} of ${nfmCount} users.`);
959
983
  }
960
984
  catch (error) {
961
985
  console.error(`\nautomate_unfollow: ${error.message}`);
@@ -8,25 +8,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { XMLParser } from "fast-xml-parser";
11
- import { readFile, writeFile } from "fs/promises";
11
+ import { readFile } from "fs/promises";
12
12
  import inquirer from "inquirer";
13
13
  import { jsonrepair } from "jsonrepair";
14
- import open from "open";
15
14
  import { join } from "path";
16
15
  import { Auth } from "./auth.js";
17
16
  import { fetcher } from "./fetcher.js";
18
17
  import { addAnimeToListMutation, addMangaToListMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, } from "./mutations.js";
19
18
  import { animeDetailsQuery, animeSearchQuery, currentUserAnimeList, currentUserMangaList, malIdToAnilistAnimeId, malIdToAnilistMangaId, mangaSearchQuery, popularQuery, trendingQuery, upcomingAnimesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from "./queries.js";
20
19
  import { AniListMediaStatus, } from "./types.js";
21
- import { anidbToanilistMapper, createAnimeListXML, createMangaListXML, formatDateObject, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, selectFile, timestampToTimeAgo, } from "./workers.js";
20
+ import { Validate } from "./validation.js";
21
+ import { anidbToanilistMapper, formatDateObject, getDownloadFolderPath, getNextSeasonAndYear, getTitle, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, selectFile, timestampToTimeAgo, } from "./workers.js";
22
22
  class AniList {
23
23
  static importAnime() {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  try {
26
26
  const filename = yield selectFile(".json");
27
+ if (!filename) {
28
+ return;
29
+ }
27
30
  const filePath = join(getDownloadFolderPath(), filename);
28
31
  const fileContent = yield readFile(filePath, "utf8");
29
32
  const importedData = JSON.parse(fileContent);
33
+ if (!Validate.Import_JSON(importedData)) {
34
+ console.error(`\nInvalid JSON file.`);
35
+ return;
36
+ }
30
37
  let count = 0;
31
38
  const batchSize = 1; // Number of requests in each batch
32
39
  const delay = 1100; // delay to avoid rate-limiting
@@ -70,9 +77,16 @@ class AniList {
70
77
  return __awaiter(this, void 0, void 0, function* () {
71
78
  try {
72
79
  const filename = yield selectFile(".json");
80
+ if (!filename) {
81
+ return;
82
+ }
73
83
  const filePath = join(getDownloadFolderPath(), filename);
74
84
  const fileContent = yield readFile(filePath, "utf8");
75
85
  const importedData = JSON.parse(fileContent);
86
+ if (!Validate.Import_JSON(importedData)) {
87
+ console.error(`\nInvalid JSON file.`);
88
+ return;
89
+ }
76
90
  let count = 0;
77
91
  const batchSize = 1; // Adjust batch size as per rate-limit constraints
78
92
  const delay = 1100; // 2 seconds delay to avoid rate-limit
@@ -137,14 +151,12 @@ class AniList {
137
151
  if (animeList) {
138
152
  const lists = (_c = (_b = (_a = animeList === null || animeList === void 0 ? void 0 : animeList.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists) !== null && _c !== void 0 ? _c : [];
139
153
  const mediaWithProgress = lists.flatMap((list) => list.entries.map((entry) => {
140
- var _a, _b, _c, _d, _e;
154
+ var _a, _b, _c, _d;
141
155
  return ({
142
156
  id: (_a = entry === null || entry === void 0 ? void 0 : entry.media) === null || _a === void 0 ? void 0 : _a.id,
143
- title: exportType === 1
144
- ? getTitle((_b = entry === null || entry === void 0 ? void 0 : entry.media) === null || _b === void 0 ? void 0 : _b.title)
145
- : (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title,
146
- episodes: (_d = entry === null || entry === void 0 ? void 0 : entry.media) === null || _d === void 0 ? void 0 : _d.episodes,
147
- siteUrl: (_e = entry === null || entry === void 0 ? void 0 : entry.media) === null || _e === void 0 ? void 0 : _e.siteUrl,
157
+ title: (_b = entry === null || entry === void 0 ? void 0 : entry.media) === null || _b === void 0 ? void 0 : _b.title,
158
+ episodes: (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.episodes,
159
+ siteUrl: (_d = entry === null || entry === void 0 ? void 0 : entry.media) === null || _d === void 0 ? void 0 : _d.siteUrl,
148
160
  progress: entry.progress,
149
161
  status: entry === null || entry === void 0 ? void 0 : entry.status,
150
162
  hiddenFromStatusLists: entry.hiddenFromStatusLists,
@@ -200,12 +212,10 @@ class AniList {
200
212
  },
201
213
  ]);
202
214
  const mediaWithProgress = lists.flatMap((list) => list.entries.map((entry) => {
203
- var _a, _b, _c;
215
+ var _a, _b;
204
216
  return ({
205
217
  id: (_a = entry === null || entry === void 0 ? void 0 : entry.media) === null || _a === void 0 ? void 0 : _a.id,
206
- title: exportType === 1
207
- ? getTitle((_b = entry === null || entry === void 0 ? void 0 : entry.media) === null || _b === void 0 ? void 0 : _b.title)
208
- : (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title,
218
+ title: (_b = entry === null || entry === void 0 ? void 0 : entry.media) === null || _b === void 0 ? void 0 : _b.title,
209
219
  private: entry.private,
210
220
  chapters: entry.media.chapters,
211
221
  progress: entry.progress,
@@ -813,8 +823,15 @@ class MyAnimeList {
813
823
  var _a, _b, _c, _d, _e;
814
824
  try {
815
825
  const filename = yield selectFile(".xml");
826
+ if (!filename) {
827
+ return;
828
+ }
816
829
  const filePath = join(getDownloadFolderPath(), filename);
817
830
  const fileContent = yield readFile(filePath, "utf8");
831
+ if (!(yield Validate.Import_AnimeXML(fileContent))) {
832
+ console.error(`\nInvalid XML file.`);
833
+ return;
834
+ }
818
835
  const parser = new XMLParser();
819
836
  if (fileContent) {
820
837
  const XMLObject = parser.parse(fileContent);
@@ -878,8 +895,15 @@ class MyAnimeList {
878
895
  var _a, _b, _c, _d, _e;
879
896
  try {
880
897
  const filename = yield selectFile(".xml");
898
+ if (!filename) {
899
+ return;
900
+ }
881
901
  const filePath = join(getDownloadFolderPath(), filename);
882
902
  const fileContent = yield readFile(filePath, "utf8");
903
+ if (!(yield Validate.Import_MangaXML(fileContent))) {
904
+ console.error(`\nInvalid XML file.`);
905
+ return;
906
+ }
883
907
  const parser = new XMLParser();
884
908
  if (fileContent) {
885
909
  const XMLObject = parser.parse(fileContent);
@@ -950,7 +974,7 @@ class MyAnimeList {
950
974
  if (((_b = (_a = animeList === null || animeList === void 0 ? void 0 : animeList.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists.length) > 0) {
951
975
  const lists = (_d = (_c = animeList === null || animeList === void 0 ? void 0 : animeList.data) === null || _c === void 0 ? void 0 : _c.MediaListCollection) === null || _d === void 0 ? void 0 : _d.lists;
952
976
  const mediaWithProgress = lists.flatMap((list) => list.entries.map((entry) => {
953
- var _a, _b, _c, _d, _e;
977
+ var _a, _b, _c, _d, _e, _f;
954
978
  return ({
955
979
  id: (_a = entry === null || entry === void 0 ? void 0 : entry.media) === null || _a === void 0 ? void 0 : _a.id,
956
980
  malId: (_b = entry === null || entry === void 0 ? void 0 : entry.media) === null || _b === void 0 ? void 0 : _b.idMal,
@@ -960,13 +984,10 @@ class MyAnimeList {
960
984
  progress: entry.progress,
961
985
  status: entry === null || entry === void 0 ? void 0 : entry.status,
962
986
  hiddenFromStatusLists: false,
987
+ format: (_f = entry === null || entry === void 0 ? void 0 : entry.media) === null || _f === void 0 ? void 0 : _f.format,
963
988
  });
964
989
  }));
965
- const xmlContent = createAnimeListXML(mediaWithProgress);
966
- const path = join(getDownloadFolderPath(), `${yield Auth.MyUserName()}@irfanshadikrishad-anilist-myanimelist(anime)-${getFormattedDate()}.xml`);
967
- yield writeFile(path, yield xmlContent, "utf8");
968
- console.log(`Generated XML for MyAnimeList.`);
969
- open(getDownloadFolderPath());
990
+ yield saveJSONasXML(mediaWithProgress, 0);
970
991
  }
971
992
  else {
972
993
  console.log(`\nHey, ${yield Auth.MyUserName()}. Your anime list seems to be empty.`);
@@ -1001,11 +1022,7 @@ class MyAnimeList {
1001
1022
  status: entry.status,
1002
1023
  hiddenFromStatusLists: entry.hiddenFromStatusLists,
1003
1024
  })));
1004
- const XMLContent = createMangaListXML(mediaWithProgress);
1005
- const path = join(getDownloadFolderPath(), `${yield Auth.MyUserName()}@irfanshadikrishad-anilist-myanimelist(manga)-${getFormattedDate()}.xml`);
1006
- yield writeFile(path, yield XMLContent, "utf8");
1007
- console.log(`Generated XML for MyAnimeList.`);
1008
- open(getDownloadFolderPath());
1025
+ yield saveJSONasXML(mediaWithProgress, 1);
1009
1026
  }
1010
1027
  else {
1011
1028
  console.log(`\nHey, ${yield Auth.MyUserName()}. Your anime list seems to be empty.`);
@@ -1023,10 +1040,17 @@ class AniDB {
1023
1040
  var _a, _b;
1024
1041
  try {
1025
1042
  const filename = yield selectFile(".json");
1043
+ if (!filename) {
1044
+ return;
1045
+ }
1026
1046
  const filePath = join(getDownloadFolderPath(), filename);
1027
1047
  const fileContent = yield readFile(filePath, "utf8");
1028
1048
  const js0n_repaired = jsonrepair(fileContent);
1029
- if (fileContent) {
1049
+ if (!(yield Validate.Import_AniDBJSONLarge(js0n_repaired))) {
1050
+ console.error(`\nInvalid JSON Large file.`);
1051
+ return;
1052
+ }
1053
+ if (js0n_repaired) {
1030
1054
  const obj3ct = yield JSON.parse(js0n_repaired);
1031
1055
  const animeList = obj3ct === null || obj3ct === void 0 ? void 0 : obj3ct.anime;
1032
1056
  if ((animeList === null || animeList === void 0 ? void 0 : animeList.length) > 0) {
@@ -1068,7 +1092,7 @@ class AniDB {
1068
1092
  const entryId = (_b = (_a = saveResponse === null || saveResponse === void 0 ? void 0 : saveResponse.data) === null || _a === void 0 ? void 0 : _a.SaveMediaListEntry) === null || _b === void 0 ? void 0 : _b.id;
1069
1093
  if (entryId) {
1070
1094
  count++;
1071
- console.log(`[${count}]\t${entryId} ✅\t${anidbId}\t${anilistId}\t(${ownEpisodes}/${totalEpisodes})\t${status}→${getStatus(status, ownEpisodes)}`);
1095
+ console.log(`[${count}]\t${entryId} ✅\t${anidbId}\t${anilistId}\t(${ownEpisodes}/${totalEpisodes})\t${status}–>${getStatus(status, ownEpisodes)}`);
1072
1096
  }
1073
1097
  // Rate limit each API call to avoid server overload
1074
1098
  // await new Promise((resolve) => setTimeout(resolve, 1100))
@@ -1,43 +1,43 @@
1
- const addAnimeToListMutation = `
2
- mutation($mediaId: Int, $status: MediaListStatus) {
3
- SaveMediaListEntry(mediaId: $mediaId, status: $status) { id status }
4
- }
1
+ const addAnimeToListMutation = `
2
+ mutation($mediaId: Int, $status: MediaListStatus) {
3
+ SaveMediaListEntry(mediaId: $mediaId, status: $status) { id status }
4
+ }
5
5
  `;
6
- const addMangaToListMutation = `
7
- mutation($mediaId: Int, $status: MediaListStatus) {
8
- SaveMediaListEntry(mediaId: $mediaId, status: $status) {
9
- id
10
- status
11
- media { id title { romaji english } }
12
- }
13
- }
6
+ const addMangaToListMutation = `
7
+ mutation($mediaId: Int, $status: MediaListStatus) {
8
+ SaveMediaListEntry(mediaId: $mediaId, status: $status) {
9
+ id
10
+ status
11
+ media { id title { romaji english } }
12
+ }
13
+ }
14
14
  `;
15
- const deleteActivityMutation = `
16
- mutation($id: Int!) {
17
- DeleteActivity(id: $id) { deleted }
18
- }
15
+ const deleteActivityMutation = `
16
+ mutation($id: Int!) {
17
+ DeleteActivity(id: $id) { deleted }
18
+ }
19
19
  `;
20
- const saveTextActivityMutation = `
21
- mutation SaveTextActivity($status: String!) {
22
- SaveTextActivity(text: $status) { id text userId createdAt }
23
- }
20
+ const saveTextActivityMutation = `
21
+ mutation SaveTextActivity($status: String!) {
22
+ SaveTextActivity(text: $status) { id text userId createdAt }
23
+ }
24
24
  `;
25
- const saveAnimeWithProgressMutation = `
26
- mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean) {
27
- SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists) {
28
- id progress hiddenFromStatusLists
29
- }
30
- }
25
+ const saveAnimeWithProgressMutation = `
26
+ mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean) {
27
+ SaveMediaListEntry(mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists) {
28
+ id progress hiddenFromStatusLists
29
+ }
30
+ }
31
31
  `;
32
- const saveMangaWithProgressMutation = `
33
- mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean, $private: Boolean) {
34
- SaveMediaListEntry( mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists, private: $private
35
- ) { id progress hiddenFromStatusLists private }
36
- }
32
+ const saveMangaWithProgressMutation = `
33
+ mutation ($mediaId: Int, $progress: Int, $status: MediaListStatus, $hiddenFromStatusLists: Boolean, $private: Boolean) {
34
+ SaveMediaListEntry( mediaId: $mediaId, progress: $progress, status: $status, hiddenFromStatusLists: $hiddenFromStatusLists, private: $private
35
+ ) { id progress hiddenFromStatusLists private }
36
+ }
37
37
  `;
38
- const likeActivityMutation = `
39
- mutation($activityId: Int!) {
40
- ToggleLike(id: $activityId, type: ACTIVITY) { id }
41
- }
38
+ const likeActivityMutation = `
39
+ mutation($activityId: Int!) {
40
+ ToggleLike(id: $activityId, type: ACTIVITY) { id }
41
+ }
42
42
  `;
43
43
  export { addAnimeToListMutation, addMangaToListMutation, deleteActivityMutation, likeActivityMutation, saveAnimeWithProgressMutation, saveMangaWithProgressMutation, saveTextActivityMutation, };