Skip to content

Instantly share code, notes, and snippets.

@seanbreckenridge
Last active September 15, 2021 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbreckenridge/dc9f4130b618cc41adb70746c9fcce73 to your computer and use it in GitHub Desktop.
Save seanbreckenridge/dc9f4130b618cc41adb70746c9fcce73 to your computer and use it in GitHub Desktop.
#!/bin/bash
# pass 'manga' as the first arg to the script to scrape manga instead
# requires https://github.com/ericchiang/pup to be installed
sort_by_id() {
sort -n -t= -k 2
}
scrape_type="${1:-anime}"
case "${scrape_type}" in
anime)
curl -s 'https://myanimelist.net/anime.php' | pup 'a[href*="/anime/genre/"] attr{href}' | awk 'BEGIN { FS = "/" } { sub("-", "_", $0); print "public const GENRE_ANIME_" toupper($5), "=", $4 ";" }' | sort_by_id
;;
manga)
curl -s 'https://myanimelist.net/manga.php' | pup 'a[href*="/manga/genre/"] attr{href}' | awk 'BEGIN { FS = "/" } { sub("-", "_", $0); print "public const GENRE_MANGA_" toupper($5), "=", $4 ";" }' | sort_by_id
;;
esac
@seanbreckenridge
Copy link
Author

seanbreckenridge commented Sep 15, 2021

Current output:

public const GENRE_ANIME_ACTION = 1;
public const GENRE_ANIME_ADVENTURE = 2;
public const GENRE_ANIME_CARS = 3;
public const GENRE_ANIME_COMEDY = 4;
public const GENRE_ANIME_AVANT_GARDE = 5;
public const GENRE_ANIME_DEMONS = 6;
public const GENRE_ANIME_MYSTERY = 7;
public const GENRE_ANIME_DRAMA = 8;
public const GENRE_ANIME_ECCHI = 9;
public const GENRE_ANIME_FANTASY = 10;
public const GENRE_ANIME_GAME = 11;
public const GENRE_ANIME_HENTAI = 12;
public const GENRE_ANIME_HISTORICAL = 13;
public const GENRE_ANIME_HORROR = 14;
public const GENRE_ANIME_KIDS = 15;
public const GENRE_ANIME_MARTIAL_ARTS = 17;
public const GENRE_ANIME_MECHA = 18;
public const GENRE_ANIME_MUSIC = 19;
public const GENRE_ANIME_PARODY = 20;
public const GENRE_ANIME_SAMURAI = 21;
public const GENRE_ANIME_ROMANCE = 22;
public const GENRE_ANIME_SCHOOL = 23;
public const GENRE_ANIME_SCI_FI = 24;
public const GENRE_ANIME_SHOUJO = 25;
public const GENRE_ANIME_GIRLS_LOVE = 26;
public const GENRE_ANIME_SHOUNEN = 27;
public const GENRE_ANIME_BOYS_LOVE = 28;
public const GENRE_ANIME_SPACE = 29;
public const GENRE_ANIME_SPORTS = 30;
public const GENRE_ANIME_SUPER_POWER = 31;
public const GENRE_ANIME_VAMPIRE = 32;
public const GENRE_ANIME_HAREM = 35;
public const GENRE_ANIME_SLICE_OF_LIFE = 36;
public const GENRE_ANIME_SUPERNATURAL = 37;
public const GENRE_ANIME_MILITARY = 38;
public const GENRE_ANIME_POLICE = 39;
public const GENRE_ANIME_PSYCHOLOGICAL = 40;
public const GENRE_ANIME_SUSPENSE = 41;
public const GENRE_ANIME_SEINEN = 42;
public const GENRE_ANIME_JOSEI = 43;
public const GENRE_ANIME_AWARD_WINNING = 46;
public const GENRE_ANIME_GOURMET = 47;
public const GENRE_ANIME_WORK_LIFE = 48;
public const GENRE_ANIME_EROTICA = 49;
public const GENRE_MANGA_ACTION = 1;
public const GENRE_MANGA_ADVENTURE = 2;
public const GENRE_MANGA_CARS = 3;
public const GENRE_MANGA_COMEDY = 4;
public const GENRE_MANGA_AVANT_GARDE = 5;
public const GENRE_MANGA_DEMONS = 6;
public const GENRE_MANGA_MYSTERY = 7;
public const GENRE_MANGA_DRAMA = 8;
public const GENRE_MANGA_ECCHI = 9;
public const GENRE_MANGA_FANTASY = 10;
public const GENRE_MANGA_GAME = 11;
public const GENRE_MANGA_HENTAI = 12;
public const GENRE_MANGA_HISTORICAL = 13;
public const GENRE_MANGA_HORROR = 14;
public const GENRE_MANGA_KIDS = 15;
public const GENRE_MANGA_MARTIAL_ARTS = 17;
public const GENRE_MANGA_MECHA = 18;
public const GENRE_MANGA_MUSIC = 19;
public const GENRE_MANGA_PARODY = 20;
public const GENRE_MANGA_SAMURAI = 21;
public const GENRE_MANGA_ROMANCE = 22;
public const GENRE_MANGA_SCHOOL = 23;
public const GENRE_MANGA_SCI_FI = 24;
public const GENRE_MANGA_SHOUJO = 25;
public const GENRE_MANGA_GIRLS_LOVE = 26;
public const GENRE_MANGA_SHOUNEN = 27;
public const GENRE_MANGA_BOYS_LOVE = 28;
public const GENRE_MANGA_SPACE = 29;
public const GENRE_MANGA_SPORTS = 30;
public const GENRE_MANGA_SUPER_POWER = 31;
public const GENRE_MANGA_VAMPIRE = 32;
public const GENRE_MANGA_HAREM = 35;
public const GENRE_MANGA_SLICE_OF_LIFE = 36;
public const GENRE_MANGA_SUPERNATURAL = 37;
public const GENRE_MANGA_MILITARY = 38;
public const GENRE_MANGA_POLICE = 39;
public const GENRE_MANGA_PSYCHOLOGICAL = 40;
public const GENRE_MANGA_SEINEN = 41;
public const GENRE_MANGA_JOSEI = 42;
public const GENRE_MANGA_DOUJINSHI = 43;
public const GENRE_MANGA_GENDER_BENDER = 44;
public const GENRE_MANGA_SUSPENSE = 45;
public const GENRE_MANGA_AWARD_WINNING = 46;
public const GENRE_MANGA_GOURMET = 47;
public const GENRE_MANGA_WORK_LIFE = 48;
public const GENRE_MANGA_EROTICA = 49;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment