UNPKG

@irfanshadikrishad/anilist

Version:

Minimalist unofficial AniList CLI for Anime and Manga Enthusiasts

259 lines (258 loc) 9.33 kB
#!/usr/bin/env node var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Command } from 'commander'; import process from 'process'; import { Auth, Social } from './helpers/auth.js'; import { AniList, MoveTo } from './helpers/lists.js'; import { getCurrentPackageVersion } from './helpers/workers.js'; const cli = new Command(); cli .name('anilist') .description('Minimalist unofficial AniList CLI for Anime and Manga Enthusiasts.') .version(getCurrentPackageVersion()); cli .command('login') .description('Login with AniList') .requiredOption('-i, --id <number>', null) .requiredOption('-s, --secret <string>', null) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ id, secret }) { if (id && secret) { yield Auth.Login(id, secret); } else { console.log('\nMust provide both ClientId and ClientSecret!'); } })); cli .command('whoami') .description('Get details of the logged in user') .action(() => __awaiter(void 0, void 0, void 0, function* () { yield Auth.Myself(); })); cli .command('trending') .alias('tr') .description('Get the trending list from AniList') .option('-c, --count <number>', 'Number of list items to get', '10') .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ count }) { yield AniList.getTrendingAnime(Number(count)); })); cli .command('popular') .alias('plr') .description('Get the popular list from AniList') .option('-c, --count <number>', 'Number of list items to get', '10') .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ count }) { yield AniList.getPopularAnime(Number(count)); })); cli .command('user <username>') .description('Get user information') .action((username) => __awaiter(void 0, void 0, void 0, function* () { yield AniList.getUserByUsername(username); })); cli .command('logout') .description('Log out the current user.') .action(() => __awaiter(void 0, void 0, void 0, function* () { yield Auth.Logout(); })); cli .command('lists') .alias('ls') .description('Get anime or manga list of authenticated user.') .option('-a, --anime', 'For anime list of authenticated user', false) .option('-m, --manga', 'For manga list of authenticated user', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) { if ((!anime && !manga) || (anime && manga)) { console.error(`\nMust select an option, either --anime or --manga`); } else if (anime) { yield AniList.MyAnime(); } else if (manga) { yield AniList.MyManga(); } })); cli .command('delete') .alias('del') .description('Delete entire collections of anime or manga') .option('-a, --anime', 'For anime list of authenticated user', false) .option('-m, --manga', 'For manga list of authenticated user', false) .option('-s, --activity', 'For activity of authenticated user', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga, activity }) { const selectedOptions = [anime, manga, activity].filter(Boolean).length; if (selectedOptions === 0) { console.error(`\nMust select one option: either --anime, --manga, or --activity`); process.exit(1); } if (selectedOptions > 1) { console.error(`\nOnly one option can be selected at a time: --anime, --manga, or --activity`); process.exit(1); } if (anime) { yield Auth.DeleteMyAnimeList(); } else if (manga) { yield Auth.DeleteMyMangaList(); } else if (activity) { yield Auth.DeleteMyActivities(); } })); cli .command('upcoming') .alias('up') .description('Anime that will be released in upcoming season') .option('-c, --count <number>', 'Number of items to get', '10') .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ count }) { yield AniList.getUpcomingAnime(Number(count)); })); cli .command('anime <id>') .description('Get anime details by their ID') .action((id) => __awaiter(void 0, void 0, void 0, function* () { if (id && !Number.isNaN(Number(id))) { yield AniList.getAnimeDetailsByID(Number(id)); } else { console.error(`\nInvalid or missing ID (${id}). Please provide a valid numeric ID.`); } })); cli .command('manga <id>') .description('Get manga details by their ID') .option('-c, --count <number>', 'Number of items to get', '10') .action((id) => __awaiter(void 0, void 0, void 0, function* () { yield AniList.getMangaDetailsByID(id); })); cli .command('search <query>') .alias('srch') .alias('find') .description('Search anime or manga.') .option('-a, --anime', 'To get the anime search results.', false) .option('-m, --manga', 'To get the manga search results.', false) .option('-c, --count <number>', 'Number of search results to show.', '10') .action((query_1, _a) => __awaiter(void 0, [query_1, _a], void 0, function* (query, { anime, manga, count }) { if ((!anime && !manga) || (anime && manga)) { console.error(`\nMust select an option, either --anime or --manga`); } else { if (anime) { yield AniList.searchAnime(query, Number(count)); } else if (manga) { yield AniList.searchManga(query, Number(count)); } else { console.error(`\nMust select an option, either --anime or --manga`); } } })); cli .command('status <status>') .alias('post') .alias('write') .description('Write a status...') .action((status) => __awaiter(void 0, void 0, void 0, function* () { yield Auth.Write(status); })); cli .command('export') .alias('exp') .description('Export your anime or manga list.') .option('-a, --anime', 'To get the anime search results.', false) .option('-m, --manga', 'To get the manga search results.', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) { if ((!anime && !manga) || (anime && manga)) { console.error(`\nMust select an option, either --anime or --manga`); } else { if (anime) { yield AniList.exportAnime(); } else if (manga) { yield AniList.exportManga(); } } })); cli .command('import') .alias('imp') .description('Import your anime or manga from anilist or other sources.') .option('-a, --anime', 'To get the anime search results.', false) .option('-m, --manga', 'To get the manga search results.', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) { if ((!anime && !manga) || (anime && manga)) { console.error(`\nMust select an option, either --anime or --manga`); } else { if (yield Auth.isLoggedIn()) { if (anime) { yield Auth.callAnimeImporter(); } else if (manga) { yield Auth.callMangaImporter(); } } else { console.error(`\nPlease login to use this feature.`); } } })); cli .command('social') .alias('sol') .description('Automate your process') .option('-f, --follow', 'Follow the user whos following you.', false) .option('-u, --unfollow', 'Unfollow the user whos not following you.', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ follow, unfollow }) { if (!follow && !unfollow) { console.error(`\nMust select an option, either --follow or --unfollow`); } else { if (yield Auth.isLoggedIn()) { if (follow) { yield Social.follow(); } else if (unfollow) { yield Social.unfollow(); } } else { console.error(`\nPlease login to use this feature.`); } } })); cli .command('move') .alias('mv') .description('Move anime or manga from one list to another') .option('-a, --anime', 'To move anime lists.', false) .option('-m, --manga', 'To move manga lists.', false) .action((_a) => __awaiter(void 0, [_a], void 0, function* ({ anime, manga }) { if (!(yield Auth.isLoggedIn())) { console.error(`\nPlease login to use this feature.`); process.exit(1); } if ((!anime && !manga) || (anime && manga)) { console.error(`\nMust select an option, either --anime or --manga`); } if (anime) { yield MoveTo.AnimeList(); } else if (manga) { yield MoveTo.MangaList(); } })); cli.parse(process.argv);