@irfanshadikrishad/anilist 1.7.0 → 2.0.0-forbidden

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.
@@ -18,31 +18,31 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
- import fs from "fs";
22
- import { readdir, writeFile } from "fs/promises";
23
- import inquirer from "inquirer";
24
- import { createRequire } from "module";
25
- import open from "open";
26
- import { homedir } from "os";
27
- import Papa from "papaparse";
28
- import { join } from "path";
29
- import process from "process";
30
- import Spinner from "tiny-spinner";
31
- import { Auth } from "./auth.js";
32
- import { fetcher } from "./fetcher.js";
33
- import { animeSearchQuery } from "./queries.js";
34
- import { MALAnimeStatus, MALMangaStatus, } from "./types.js";
21
+ import fs from 'fs';
22
+ import { readdir, writeFile } from 'fs/promises';
23
+ import inquirer from 'inquirer';
24
+ import { createRequire } from 'module';
25
+ import open from 'open';
26
+ import { homedir } from 'os';
27
+ import Papa from 'papaparse';
28
+ import { join } from 'path';
29
+ import process from 'process';
30
+ import Spinner from 'tiny-spinner';
31
+ import { Auth } from './auth.js';
32
+ import { fetcher } from './fetcher.js';
33
+ import { animeSearchQuery } from './queries.js';
34
+ import { MALAnimeStatus, MALMangaStatus, } from './types.js';
35
35
  const aniListEndpoint = `https://graphql.anilist.co`;
36
- const redirectUri = "https://anilist.co/api/v2/oauth/pin";
36
+ const redirectUri = 'https://anilist.co/api/v2/oauth/pin';
37
37
  const spinner = new Spinner();
38
38
  function getTitle(title) {
39
- return (title === null || title === void 0 ? void 0 : title.english) || (title === null || title === void 0 ? void 0 : title.romaji) || "???";
39
+ return (title === null || title === void 0 ? void 0 : title.english) || (title === null || title === void 0 ? void 0 : title.romaji) || '???';
40
40
  }
41
41
  function formatDateObject(dateObj) {
42
42
  if (!dateObj)
43
- return "null";
44
- return ([dateObj.day, dateObj.month, dateObj.year].filter(Boolean).join("/") ||
45
- "null");
43
+ return 'null';
44
+ return ([dateObj.day, dateObj.month, dateObj.year].filter(Boolean).join('/') ||
45
+ 'null');
46
46
  }
47
47
  function getNextSeasonAndYear() {
48
48
  const currentMonth = new Date().getMonth() + 1;
@@ -51,59 +51,59 @@ function getNextSeasonAndYear() {
51
51
  let nextYear;
52
52
  // Determine the current season
53
53
  if (currentMonth >= 12 || currentMonth <= 2) {
54
- nextSeason = "SPRING";
54
+ nextSeason = 'SPRING';
55
55
  nextYear = currentMonth === 12 ? currentYear + 1 : currentYear;
56
56
  }
57
57
  else if (currentMonth >= 3 && currentMonth <= 5) {
58
- nextSeason = "SUMMER";
58
+ nextSeason = 'SUMMER';
59
59
  nextYear = currentYear;
60
60
  }
61
61
  else if (currentMonth >= 6 && currentMonth <= 8) {
62
- nextSeason = "FALL";
62
+ nextSeason = 'FALL';
63
63
  nextYear = currentYear;
64
64
  }
65
65
  else if (currentMonth >= 9 && currentMonth <= 11) {
66
- nextSeason = "WINTER";
66
+ nextSeason = 'WINTER';
67
67
  nextYear = currentYear + 1;
68
68
  }
69
69
  return { nextSeason, nextYear };
70
70
  }
71
71
  function removeHtmlAndMarkdown(input) {
72
72
  if (input) {
73
- input = input.replace(/<\/?[^>]+(>|$)/g, "");
74
- input = input.replace(/(^|\n)#{1,6}\s+(.+?)(\n|$)/g, "$2 ");
75
- input = input.replace(/(\*\*|__)(.*?)\1/g, "$2");
76
- input = input.replace(/(\*|_)(.*?)\1/g, "$2");
77
- input = input.replace(/`(.+?)`/g, "$1");
78
- input = input.replace(/\[(.*?)\]\(.*?\)/g, "$1");
79
- input = input.replace(/!\[(.*?)\]\(.*?\)/g, "$1");
80
- input = input.replace(/(^|\n)>\s+(.+?)(\n|$)/g, "$2 ");
81
- input = input.replace(/(^|\n)-\s+(.+?)(\n|$)/g, "$2 ");
82
- input = input.replace(/(^|\n)\d+\.\s+(.+?)(\n|$)/g, "$2 ");
83
- input = input.replace(/(^|\n)\s*([-*_]){3,}\s*(\n|$)/g, "$1");
84
- input = input.replace(/~~(.*?)~~/g, "$1");
85
- input = input.replace(/\s+/g, " ").trim();
73
+ input = input.replace(/<\/?[^>]+(>|$)/g, '');
74
+ input = input.replace(/(^|\n)#{1,6}\s+(.+?)(\n|$)/g, '$2 ');
75
+ input = input.replace(/(\*\*|__)(.*?)\1/g, '$2');
76
+ input = input.replace(/(\*|_)(.*?)\1/g, '$2');
77
+ input = input.replace(/`(.+?)`/g, '$1');
78
+ input = input.replace(/\[(.*?)\]\(.*?\)/g, '$1');
79
+ input = input.replace(/!\[(.*?)\]\(.*?\)/g, '$1');
80
+ input = input.replace(/(^|\n)>\s+(.+?)(\n|$)/g, '$2 ');
81
+ input = input.replace(/(^|\n)-\s+(.+?)(\n|$)/g, '$2 ');
82
+ input = input.replace(/(^|\n)\d+\.\s+(.+?)(\n|$)/g, '$2 ');
83
+ input = input.replace(/(^|\n)\s*([-*_]){3,}\s*(\n|$)/g, '$1');
84
+ input = input.replace(/~~(.*?)~~/g, '$1');
85
+ input = input.replace(/\s+/g, ' ').trim();
86
86
  }
87
87
  return input;
88
88
  }
89
89
  function getDownloadFolderPath() {
90
90
  const homeDirectory = homedir();
91
91
  // Determine the Downloads folder path based on the platform
92
- if (process.platform === "win32") {
93
- return join(homeDirectory, "Downloads");
92
+ if (process.platform === 'win32') {
93
+ return join(homeDirectory, 'Downloads');
94
94
  }
95
- else if (process.platform === "darwin" || process.platform === "linux") {
96
- return join(homeDirectory, "Downloads");
95
+ else if (process.platform === 'darwin' || process.platform === 'linux') {
96
+ return join(homeDirectory, 'Downloads');
97
97
  }
98
98
  return homeDirectory;
99
99
  }
100
100
  function getFormattedDate() {
101
101
  const date = new Date();
102
- const day = String(date.getDate()).padStart(2, "0");
103
- const month = String(date.getMonth() + 1).padStart(2, "0");
102
+ const day = String(date.getDate()).padStart(2, '0');
103
+ const month = String(date.getMonth() + 1).padStart(2, '0');
104
104
  const year = date.getFullYear();
105
- const hours = String(date.getHours()).padStart(2, "0");
106
- const minutes = String(date.getMinutes()).padStart(2, "0");
105
+ const hours = String(date.getHours()).padStart(2, '0');
106
+ const minutes = String(date.getMinutes()).padStart(2, '0');
107
107
  // Format as DD-MM-YYYY-HH-MM
108
108
  return `${day}-${month}-${year}-${hours}-${minutes}`;
109
109
  }
@@ -116,13 +116,13 @@ function saveJSONasJSON(js0n, dataType) {
116
116
  return __awaiter(this, void 0, void 0, function* () {
117
117
  try {
118
118
  const jsonData = JSON.stringify(js0n, null, 2);
119
- const path = yield saveToPath(dataType, ".json");
120
- yield writeFile(path, jsonData, "utf8");
119
+ const path = yield saveToPath(dataType, '.json');
120
+ yield writeFile(path, jsonData, 'utf8');
121
121
  console.log(`\nSaved as JSON successfully.`);
122
122
  open(getDownloadFolderPath());
123
123
  }
124
124
  catch (error) {
125
- console.error("\nError saving JSON data:", error);
125
+ console.error('\nError saving JSON data:', error);
126
126
  }
127
127
  });
128
128
  }
@@ -139,13 +139,13 @@ function saveJSONasCSV(js0n, dataType) {
139
139
  return (Object.assign(Object.assign({}, rest), { title: getTitle(title) }));
140
140
  });
141
141
  const csvData = Papa.unparse(js0n_WTAS);
142
- const path = yield saveToPath(dataType, ".csv");
143
- yield writeFile(path, csvData, "utf8");
142
+ const path = yield saveToPath(dataType, '.csv');
143
+ yield writeFile(path, csvData, 'utf8');
144
144
  console.log(`\nSaved as CSV successfully.`);
145
145
  open(getDownloadFolderPath());
146
146
  }
147
147
  catch (error) {
148
- console.error("\nError saving CSV data:", error);
148
+ console.error('\nError saving CSV data:', error);
149
149
  }
150
150
  });
151
151
  }
@@ -153,8 +153,8 @@ function saveJSONasXML(js0n, data_type) {
153
153
  return __awaiter(this, void 0, void 0, function* () {
154
154
  try {
155
155
  const xmlContent = data_type === 0 ? createAnimeListXML(js0n) : createMangaListXML(js0n);
156
- const path = yield saveToPath(data_type === 0 ? "anime" : "manga", ".xml");
157
- yield writeFile(path, yield xmlContent, "utf8");
156
+ const path = yield saveToPath(data_type === 0 ? 'anime' : 'manga', '.xml');
157
+ yield writeFile(path, yield xmlContent, 'utf8');
158
158
  console.log(`\nGenerated XML for MyAnimeList.`);
159
159
  open(getDownloadFolderPath());
160
160
  }
@@ -184,9 +184,9 @@ function selectFile(fileType) {
184
184
  if (onlyFiles.length > 0) {
185
185
  const answers = yield inquirer.prompt([
186
186
  {
187
- type: "list",
188
- name: "fileName",
189
- message: "Select a file to import:",
187
+ type: 'list',
188
+ name: 'fileName',
189
+ message: 'Select a file to import:',
190
190
  choices: onlyFiles,
191
191
  },
192
192
  ]);
@@ -198,7 +198,7 @@ function selectFile(fileType) {
198
198
  }
199
199
  }
200
200
  catch (error) {
201
- console.error("\nError selecting file:", error);
201
+ console.error('\nError selecting file:', error);
202
202
  return null;
203
203
  }
204
204
  });
@@ -233,7 +233,7 @@ function createMangaXML(malId, progress, status, chapters, title) {
233
233
  return `
234
234
  <manga>
235
235
  <manga_mangadb_id>${malId}</manga_mangadb_id>
236
- <manga_title><![CDATA[${title ? title : "unknown"}]]></manga_title>
236
+ <manga_title><![CDATA[${title ? title : 'unknown'}]]></manga_title>
237
237
  <manga_volumes>0</manga_volumes>
238
238
  <manga_chapters>${chapters ? chapters : 0}</manga_chapters>
239
239
  <my_id>0</my_id>
@@ -261,13 +261,12 @@ function createAnimeListXML(mediaWithProgress) {
261
261
  // Filter out anime without malId
262
262
  const filteredMedia = mediaWithProgress.filter((anime) => anime.malId);
263
263
  const xmlEntries = filteredMedia.map((anime) => {
264
- console.log(anime);
265
264
  const malId = anime.malId;
266
265
  const progress = anime.progress;
267
266
  const episodes = anime.episodes;
268
267
  const title = getTitle(anime.title);
269
268
  const status = statusMap[anime.status];
270
- const format = anime.format ? anime.format : "";
269
+ const format = anime.format ? anime.format : '';
271
270
  return createAnimeXML(malId, progress, status, episodes, title, format);
272
271
  });
273
272
  return `<myanimelist>
@@ -282,7 +281,7 @@ function createAnimeListXML(mediaWithProgress) {
282
281
  <user_total_dropped>0</user_total_dropped>
283
282
  <user_total_plantowatch>0</user_total_plantowatch>
284
283
  </myinfo>
285
- \n${xmlEntries.join("\n")}\n
284
+ \n${xmlEntries.join('\n')}\n
286
285
  </myanimelist>`;
287
286
  });
288
287
  }
@@ -317,13 +316,13 @@ function createMangaListXML(mediaWithProgress) {
317
316
  <user_total_dropped>1</user_total_dropped>
318
317
  <user_total_plantoread>1</user_total_plantoread>
319
318
  </myinfo>
320
- \n${xmlEntries.join("\n")}\n
319
+ \n${xmlEntries.join('\n')}\n
321
320
  </myanimelist>`;
322
321
  });
323
322
  }
324
323
  function getCurrentPackageVersion() {
325
324
  const require = createRequire(import.meta.url);
326
- const packageJson = require("../../package.json");
325
+ const packageJson = require('../../package.json');
327
326
  const version = packageJson.version;
328
327
  return version || null;
329
328
  }
@@ -331,27 +330,27 @@ function timestampToTimeAgo(timestamp) {
331
330
  const now = Math.floor(Date.now() / 1000);
332
331
  const elapsed = now - timestamp;
333
332
  if (elapsed < 60) {
334
- return `${elapsed} second${elapsed === 1 ? "" : "s"} ago`;
333
+ return `${elapsed} second${elapsed === 1 ? '' : 's'} ago`;
335
334
  }
336
335
  else if (elapsed < 3600) {
337
336
  const minutes = Math.floor(elapsed / 60);
338
- return `${minutes} minute${minutes === 1 ? "" : "s"} ago`;
337
+ return `${minutes} minute${minutes === 1 ? '' : 's'} ago`;
339
338
  }
340
339
  else if (elapsed < 86400) {
341
340
  const hours = Math.floor(elapsed / 3600);
342
- return `${hours} hour${hours === 1 ? "" : "s"} ago`;
341
+ return `${hours} hour${hours === 1 ? '' : 's'} ago`;
343
342
  }
344
343
  else if (elapsed < 2592000) {
345
344
  const days = Math.floor(elapsed / 86400);
346
- return `${days} day${days === 1 ? "" : "s"} ago`;
345
+ return `${days} day${days === 1 ? '' : 's'} ago`;
347
346
  }
348
347
  else if (elapsed < 31536000) {
349
348
  const months = Math.floor(elapsed / 2592000);
350
- return `${months} month${months === 1 ? "" : "s"} ago`;
349
+ return `${months} month${months === 1 ? '' : 's'} ago`;
351
350
  }
352
351
  else {
353
352
  const years = Math.floor(elapsed / 31536000);
354
- return `${years} year${years === 1 ? "" : "s"} ago`;
353
+ return `${years} year${years === 1 ? '' : 's'} ago`;
355
354
  }
356
355
  }
357
356
  const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void 0, void 0, void 0, function* () {
@@ -365,7 +364,7 @@ const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void
365
364
  return ((_a = response.data) === null || _a === void 0 ? void 0 : _a.Page.media) || [];
366
365
  }
367
366
  catch (error) {
368
- console.error("Error fetching AniList data:", error);
367
+ console.error('Error fetching AniList data:', error);
369
368
  return [];
370
369
  }
371
370
  });
@@ -383,6 +382,27 @@ const anidbToanilistMapper = (romanjiName, year, englishName) => __awaiter(void
383
382
  }
384
383
  return null;
385
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
+ }
386
406
  /**
387
407
  * Extract the save file path
388
408
  * @param data_type - anime|manga
@@ -419,38 +439,38 @@ function handleRateLimitRetry(retryCount) {
419
439
  });
420
440
  }
421
441
  function formatDate(timestamp) {
422
- return timestamp ? new Date(timestamp * 1000).toUTCString() : "N/A";
442
+ return timestamp ? new Date(timestamp * 1000).toUTCString() : 'N/A';
423
443
  }
424
444
  function logUserDetails(user, followersCount, followingCount) {
425
445
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
426
- console.log("\nšŸ“Œ User Information:");
446
+ console.log('\nšŸ“Œ User Information:');
427
447
  console.table({
428
- "ID": user.id,
429
- "Name": user.name,
430
- "Site URL": user.siteUrl,
431
- "Donator Tier": user.donatorTier,
432
- "Donator Badge": user.donatorBadge,
433
- "Account Created": formatDate(user.createdAt),
434
- "Account Updated": formatDate(user.updatedAt),
435
- "Blocked": user.isBlocked,
436
- "isFollower": user.isFollower,
437
- "isFollowing": user.isFollowing,
438
- "Profile Color": ((_a = user.options) === null || _a === void 0 ? void 0 : _a.profileColor) || "N/A",
439
- "Timezone": ((_b = user.options) === null || _b === void 0 ? void 0 : _b.timezone) || "N/A",
440
- "Followers": followersCount,
441
- "Following": followingCount,
448
+ 'ID': user.id,
449
+ 'Name': user.name,
450
+ 'Site URL': user.siteUrl,
451
+ 'Donator Tier': user.donatorTier,
452
+ 'Donator Badge': user.donatorBadge,
453
+ 'Account Created': formatDate(user.createdAt),
454
+ 'Account Updated': formatDate(user.updatedAt),
455
+ 'Blocked': user.isBlocked,
456
+ 'isFollower': user.isFollower,
457
+ 'isFollowing': user.isFollowing,
458
+ 'Profile Color': ((_a = user.options) === null || _a === void 0 ? void 0 : _a.profileColor) || 'N/A',
459
+ 'Timezone': ((_b = user.options) === null || _b === void 0 ? void 0 : _b.timezone) || 'N/A',
460
+ 'Followers': followersCount,
461
+ 'Following': followingCount,
442
462
  });
443
- console.log("\nšŸ“Š Anime Statistics:");
463
+ console.log('\nšŸ“Š Anime Statistics:');
444
464
  console.table({
445
- "Count": ((_d = (_c = user.statistics) === null || _c === void 0 ? void 0 : _c.anime) === null || _d === void 0 ? void 0 : _d.count) || 0,
446
- "Episodes Watched": ((_f = (_e = user.statistics) === null || _e === void 0 ? void 0 : _e.anime) === null || _f === void 0 ? void 0 : _f.episodesWatched) || 0,
447
- "Minutes Watched": ((_h = (_g = user.statistics) === null || _g === void 0 ? void 0 : _g.anime) === null || _h === void 0 ? void 0 : _h.minutesWatched) || 0,
465
+ 'Count': ((_d = (_c = user.statistics) === null || _c === void 0 ? void 0 : _c.anime) === null || _d === void 0 ? void 0 : _d.count) || 0,
466
+ 'Episodes Watched': ((_f = (_e = user.statistics) === null || _e === void 0 ? void 0 : _e.anime) === null || _f === void 0 ? void 0 : _f.episodesWatched) || 0,
467
+ 'Minutes Watched': ((_h = (_g = user.statistics) === null || _g === void 0 ? void 0 : _g.anime) === null || _h === void 0 ? void 0 : _h.minutesWatched) || 0,
448
468
  });
449
- console.log("\nšŸ“– Manga Statistics:");
469
+ console.log('\nšŸ“– Manga Statistics:');
450
470
  console.table({
451
- "Count": ((_k = (_j = user.statistics) === null || _j === void 0 ? void 0 : _j.manga) === null || _k === void 0 ? void 0 : _k.count) || 0,
452
- "Chapters Read": ((_m = (_l = user.statistics) === null || _l === void 0 ? void 0 : _l.manga) === null || _m === void 0 ? void 0 : _m.chaptersRead) || 0,
453
- "Volumes Read": ((_p = (_o = user.statistics) === null || _o === void 0 ? void 0 : _o.manga) === null || _p === void 0 ? void 0 : _p.volumesRead) || 0,
471
+ 'Count': ((_k = (_j = user.statistics) === null || _j === void 0 ? void 0 : _j.manga) === null || _k === void 0 ? void 0 : _k.count) || 0,
472
+ 'Chapters Read': ((_m = (_l = user.statistics) === null || _l === void 0 ? void 0 : _l.manga) === null || _m === void 0 ? void 0 : _m.chaptersRead) || 0,
473
+ 'Volumes Read': ((_p = (_o = user.statistics) === null || _o === void 0 ? void 0 : _o.manga) === null || _p === void 0 ? void 0 : _p.volumesRead) || 0,
454
474
  });
455
475
  }
456
- export { anidbToanilistMapper, aniListEndpoint, createAnimeListXML, createAnimeXML, createMangaListXML, createMangaXML, formatDateObject, getCurrentPackageVersion, getDownloadFolderPath, getFormattedDate, getNextSeasonAndYear, getTitle, handleRateLimitRetry, logUserDetails, redirectUri, removeHtmlAndMarkdown, saveJSONasCSV, saveJSONasJSON, saveJSONasXML, saveToPath, selectFile, simpleDateFormat, timestampToTimeAgo, };
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, };