from collections import OrderedDict
import re as regex

from bs4 import BeautifulSoup
from bs4 import SoupStrainer
from json2html import *
import aiohttp
import hug

__version__ = "0.5.3"
__author__ = '<NAME>'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017 <NAME>'
__title__ = 'Novel Updates Unofficial API'

session = None
headers = None
table_filter = None


@hug.local()
async def async_iter(iterable):
    for item in iterable:
        yield item


@hug.local()
async def init():
    """Manual initialization function due to Hug's broken: @hug.startup()"""
    global session
    global headers
    global table_filter
    global base_url
    session = aiohttp.ClientSession()
    headers = {'user_agent': '{}/{} (https://github.com/Evolution0/Kasasagi)'.format(__title__, __version__)}
    table_filter = SoupStrainer('table')
    base_url = 'http://www.novelupdates.com/'


@hug.local()
async def parse_search(soup, limit=None):
    intro_clean = lambda string: regex.sub(r'(\.\.\.\smore>>|\s<<less)', '', string.text.strip())

    titles = [title.text async for title in async_iter(soup.find_all('span', {'class': 'entry-title'}))]
    links = [link.get('href', None) async for link in async_iter(soup.find_all('a', {'class': 'w-blog-entry-link'}))]
    covers = [cover.get('src', None) async for cover in async_iter(soup.find_all('img', {'class': 'wp-post-image'}))]
    genres_block = [genre.text async for genre in async_iter(soup.find_all('span', {'class': 's-genre'}))]
    genres = [genre.split() async for genre in async_iter(genres_block)]
    intros = [intro_clean(intro) async for intro in async_iter(soup.find_all('div', {'class': 'w-blog-entry-short'}))]

    novels = []

    async for title, link, cover, genre, intro in async_iter(zip(titles, links, covers, genres, intros)):
        novels.append({
            'title': title,
            'link': link,
            'cover': cover if cover != 'http://www.novelupdates.com/img/noimagefound.jpg' else None,
            'genre': genre or None,
            'intro': intro or None
        })

    return novels


@hug.local()
def parse_latest(soup, limit=None) -> dict:
    pass


@hug.local()
def parse_ranking(soup, limit=None) -> dict:
    pass


@hug.local()
@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def get_reading_list(url: str) -> dict:
    """https://nu-kasasagi.herokuapp.com/v1/get_reading_list/?url=READING_LIST_URL"""
    await init()
    novels = OrderedDict({})
    async with session.get(url, headers=headers) as response:
        list_soup = BeautifulSoup(await response.text(), 'lxml', parse_only=table_filter)

    statuses = list_soup.find_all('td', {'align': 'left'})
    links = list_soup.find_all('a')

    for url, status in zip(links, statuses):
        status = status.text.split(' / ')
        novels.update({url['title']: {
            'url': url['href'],
            'last': status[0][2:],
            'current': status[1][:-2]
        }})
    session.close()
    return novels


@hug.local()
@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def get_all_chapters(url: str) -> dict:
    """https://nu-kasasagi.herokuapp.com/v1/get_all_chapters/?url=NOVEL_PAGE_URL"""
    await init()

    chapters_list = []

    async def get_chapter_list(chapter_url: str):
        async with session.get(chapter_url, headers=headers) as chapter_response:
            chapter_list_soup = BeautifulSoup(await chapter_response.text(), 'lxml', parse_only=table_filter)

        latest = chapter_list_soup.find('table', {'id': 'myTable'})
        latest_chapters = latest.find_all('a', {'class': 'chp-release'})
        releases = chapter_list_soup.find_all('a', href=regex.compile('http://www\.novelupdates\.com/group/'))

        for chapter, release in zip(latest_chapters[1::2], releases):
            chapters_list.append({
                'chapter_name': chapter.text,
                'chapter_link': chapter['href'],
                'release_group': release.text
            })

    if 'series' not in url:
        return {'error': 'Not a valid novel url'}
    else:
        pattern = regex.compile(r'/series/.*/')
        series = pattern.search(url).group()
        base_url = 'http://www.novelupdates.com'

        url = f'{base_url}{series}'

    async with session.get(url, headers=headers) as response:
        novel_soup = BeautifulSoup(await response.text(), 'lxml')

    gap = novel_soup.find('span', {'class': 'gap'})
    pagination = novel_soup.find_all('div', {'class': 'digg_pagination'})

    single = False

    if gap:
        gap = gap.findNext('a')
        final_page = regex.sub('\D', '', gap['href'])
        page_urls = [f'{url}?pg={i}' for i in range(1, int(final_page) + 1)]
    elif pagination:
        page_nums = novel_soup.find_all('a', text=regex.compile(r'^[0-6]'))
        page_nums = [num.text for num in page_nums]
        page_urls = [f'{url}?pg={i}' for i in range(1, int(max(page_nums)) + 1)]
    else:
        single = True

    if single is True:
        await get_chapter_list(url)
    else:
        for page_url in page_urls:
            await get_chapter_list(page_url)

    novel_title = novel_soup.find('div', {'class': 'seriestitlenu'}).text

    chapters = {
        'name': novel_title,
        'chapter_count': len(chapters_list),
        'chapters': chapters_list
    }

    session.close()
    return chapters


@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def search(term: str, limit=None) -> dict:
    """https://nu-kasasagi.herokuapp.com/v1/search/?term=SEARCH_TERMS"""
    # TODO: Slows down far too much per page of results

    await init()

    url = f'{base_url}/?s={term}&post_type=seriesplans'

    search_filter = SoupStrainer('div', {'class': 'l-content'})

    async with session.get(url, headers=headers) as response:
        search_soup = BeautifulSoup(await response.text(), 'lxml', parse_only=search_filter)

    found = search_soup.find('div', {'class': 'w-blog-entry-h'})

    search_result = []

    if found is None:
        search_result = {'info': 'no posts were found'}
    else:
        search_result.extend(await parse_search(search_soup))

        nav = search_soup.find('div', {'class': 'digg_pagination'})
        next_page = nav.find('a', {'class': 'next'})
        dots = nav.find('span', {'class': 'dots'})

        async def page_gen(num):
                return f'{base_url}/page/{num}/?s={term}&post_type=seriesplans'

        if next_page:
            if dots:
                last_page = dots.findNext('a').text
                pages = [await page_gen(page) async for page in async_iter(range(1, int(last_page)))]
            else:
                last_page = 3
                pages = [await page_gen(page) async for page in async_iter(range(1, int(last_page)))]

        if pages:
            async for page in async_iter(pages):
                async with session.get(page, headers=headers) as response:
                    if response.status == 200:
                        search_soup = BeautifulSoup(await response.text(), 'lxml', parse_only=search_filter)
                        search_result.extend(await parse_search(search_soup))

    search_results = {
        'result_count': len(search_result),
        'results': search_result
    }

    session.close()
    return search_results


@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def advanced_search(language=None, novel_type=None, genre: hug.types.delimited_list(',')=None,
                          genre_ao: hug.types.one_of(['and', 'or'])=None, releases: hug.types.number=None,
                          releases_mm: hug.types.one_of(['min', 'max'])=None, frequency: hug.types.number=None,
                          frequency_mm: hug.types.one_of(['min', 'max'])=None, rating: hug.types.number=None,
                          rating_mm: hug.types.one_of(['min', 'max'])=None, ratings: hug.types.number=None,
                          ratings_mm: hug.types.one_of(['min', 'max'])=None, readers: hug.types.number=None,
                          readers_mm: hug.types.one_of(['min', 'max'])=None, tags_include: hug.types.delimited_list(',')=None,
                          tags_ao: hug.types.one_of(['and', 'or'])=None, tags_exclude: hug.types.delimited_list(',')=None,
                          last_release=None, last_release_mm: hug.types.one_of(['min', 'max'])=None,
                          complete: hug.types.one_of(['yes', 'no'])=None, sort=None, order=None,
                          limit: hug.types.number=None) -> dict:
    """https://nu-kasasagi.herokuapp.com/v1/advanced_search/?arg1=value&?arg2=value, etc (See Inputs)"""
    await init()

    base_url = 'http://www.novelupdates.com/series-finder/?sf=1'

    novel_types = {
        'chinese': '2441',      'korean': '2442',       'thai': '9955',
        'filipino': '9182',     'light': '2443',        'vietnamese': '9178',
        'indonesian': '9180',    'malaysian': '9184',    'web': '2444'
    }
    languages = {
        'chinese': '495',       'japanese': '496',      'thai': '9954',
        'filipino': '9181',     'korean': '497',        'vietnamese': '9177',
        'indonesian': '9179',    'malaysian': '9183'
    }
    genres = {
        'action': '8',          'horror': '343',        'sci-fi': '11',       'supernatural': '16',
        'adult': '280',         'josei': '324',         'seinen': '18',       'tragedy': '132',
        'adventure': '13',      'lolicon': '5982',      'shotacon': '2335',   'wuxia': '479',
        'comedy': '17',         'martial_arts': '14',   'shoujo': '157',      'xianxia': '480',
        'drama': '9',           'mature': '4',          'shoujo_ai': '851',   'xuanhuan': '3954',
        'ecchi': '292',         'mecha': '10',          'shounen': '12',      'yaoi': '560',
        'fantasy': '5',         'mystery': '245',       'shounen_ai': '1692', 'yuri': '922',
        'gender_bender': '168', 'psychological': '486', 'slice_of_life': '7',
        'harem': '3',           'romance': '15',        'smut': '281',
        'historical': '330',    'school_life': '6',     'sports': '1357'
    }
    tags = {
        "abandoned_child": "1299",
        "ability_steal": "4859",
        "absent_parents": "1248",
        "abusive_characters": "11325",
        "academy": "4885",
        "accelerated_growth": "475",
        "actors": "567",
        "actresses": "7415",
        "acupuncture": "6417",
        "adapted_from_manga": "4976",
        "adapted_from_manhua": "6280",
        "adapted_to_anime": "269",
        "adapted_to_drama": "2999",
        "adapted_to_drama_cd": "928",
        "adapted_to_game": "891",
        "adapted_to_manga": "270",
        "adapted_to_manhua": "182",
        "adapted_to_manhwa": "2721",
        "adapted_to_movie": "1133",
        "adapted_to_visual_novel": "1334",
        "adopted_children": "858",
        "adopted_protagonist": "603",
        "adultery": "4974",
        "adventurers": "3108",
        "affair": "3802",
        "afterlife": "578",
        "afterstory": "7977",
        "age_gap": "758",
        "age_progression": "357",
        "age_regression": "216",
        "aged_protagonist": "11772",
        "aggressive_females": "104",
        "aggressive_lover": "309",
        "aggressive_male_lead": "8508",
        "agriculture": "8469",
        "alchemy": "234",
        "aliens": "621",
        "all-girls_school": "598",
        "alternate_ending": "8684",
        "alternate_world": "7909",
        "alternative_future": "855",
        "amazon_women": "11225",
        "america": "1259",
        "amnesia": "625",
        "amoral_protagonist": "8798",
        "amusement_park": "774",
        "anal": "4594",
        "analysis": "9094",
        "ancient_china": "476",
        "ancient_fictional_china": "5908",
        "ancient_legends": "6208",
        "ancient_times": "2662",
        "androgynous_female_lead": "190",
        "androgynous_male_lead": "810",
        "androgynous_protagonist": "575",
        "androids": "892",
        "angels": "1327",
        "anilingus": "4595",
        "animal_characteristics": "255",
        "animal_rearing": "7323",
        "animal_transformation": "241",
        "animals": "4553",
        "anonymous_protagonist": "8689",
        "anthology": "2696",
        "anti_devil_organisation": "6300",
        "anti-magic": "724",
        "anti-social_protagonist": "1732",
        "antihero_protagonist": "4297",
        "antique_shop": "203",
        "apartment_life": "513",
        "apathetic_male_lead": "6537",
        "apocalypse": "217",
        "appearance_changes": "721",
        "appearance_different_from_actual_age": "430",
        "appraisal": "10087",
        "archery": "697",
        "aristocracy": "6442",
        "arms_dealers": "9591",
        "army": "306",
        "army_building": "9522",
        "army_commander": "6093",
        "arranged_marriage": "2676",
        "arrogant_female_lead": "8784",
        "arrogant_male_lead": "97",
        "arthurian_legends": "7971",
        "artifact_crafting": "9851",
        "artifacts": "4699",
        "artificial_intelligence": "141",
        "artists": "271",
        "assassinations": "4270",
        "assassins": "81",
        "assistant": "9665",
        "astrologers": "8965",
        "author-editor_relationship": "10627",
        "autism": "9776",
        "autobiography": "6693",
        "automatons": "11491",
        "average_looking_male_lead": "7400",
        "average-looking_female_lead": "7476",
        "aviation": "1213",
        "award-winning_work": "1134",
        "awkward_female_lead": "1683",
        "awkward_male_lead": "1385",
        "axe_wielder": "10789",
        "bad_luck": "1277",
        "bandits": "1654",
        "bands": "4975",
        "barbarian": "5329",
        "bartending": "935",
        "baseball": "5590",
        "based_on_a_movie": "1346",
        "based_on_a_song": "1632",
        "based_on_a_tv_show": "6572",
        "based_on_a_video_game": "1442",
        "based_on_a_visual_novel": "1447",
        "based_on_an_anime": "1230",
        "basketball": "617",
        "battle_academy": "825",
        "battle_competition": "6308",
        "battle_mage": "58",
        "battleship": "2761",
        "bdsm": "10668",
        "beast_companions": "5363",
        "beastkin": "5406",
        "beastkin_girls": "10017",
        "beasts": "116",
        "beautician": "3212",
        "beautiful_couple": "2552",
        "beautiful_female_lead": "111",
        "beautiful_male_lead": "4345",
        "berserker": "6226",
        "betrayal": "256",
        "bickering_couple": "2573",
        "biography": "6692",
        "bisexual_protagonist": "6359",
        "bishoujo": "1629",
        "bishounen": "1997",
        "black_belly": "2943",
        "black_magic": "7090",
        "black_market": "5323",
        "blackmail": "916",
        "blacksmith": "2734",
        "blind_dates": "9280",
        "blind_male_lead": "12200",
        "blind_protagonist": "2347",
        "blood_magic": "10474",
        "blood_manipulation": "9492",
        "bloodlines": "5824",
        "blunt_male_lead": "8555",
        "body_swap": "2642",
        "body_tempering": "9907",
        "body-double": "568",
        "bodyguards": "224",
        "books": "1288",
        "bookstore": "1289",
        "bookworms": "542",
        "boss-subordinate_relationship": "325",
        "brain_development": "9095",
        "brainwashing": "1710",
        "breast_fetish": "5607",
        "breathing_technique": "9087",
        "bride_kidnapping": "9880",
        "broken_engagement": "9410",
        "brothel": "11263",
        "brother_complex": "604",
        "brotherhood": "8185",
        "buddhism": "3825",
        "bullying": "123",
        "business_management": "782",
        "businessmen": "11786",
        "butlers": "1597",
        "bystander": "4173",
        "calm_female_lead": "6141",
        "calm_male_lead": "682",
        "cannibalism": "4248",
        "capable_female_lead": "5861",
        "capable_male_lead": "7412",
        "card_games": "2774",
        "card_system": "8013",
        "carefree_female_lead": "5705",
        "carefree_male_lead": "3064",
        "carefree_protagonist": "11345",
        "caring_male_lead": "102",
        "castaway": "1458",
        "cats": "2073",
        "cautious_male_lead": "9706",
        "celebrities": "2304",
        "celestial": "4866",
        "centaurs": "9723",
        "character_growth": "257",
        "charismatic_male_lead": "5576",
        "charm_ability": "4366",
        "charming_male_lead": "9137",
        "chat_rooms": "1942",
        "cheats": "5708",
        "cheerful_female_lead": "4027",
        "chefs": "1832",
        "child_abuse": "1368",
        "child_protagonist": "3470",
        "childcare": "1391",
        "childhood_friends": "85",
        "childhood_love": "917",
        "childhood_promise": "691",
        "childish_male_lead": "3595",
        "children": "639",
        "children_soldiers": "5842",
        "church": "437",
        "chuunibyou": "169",
        "cities_in_the_skies": "8190",
        "city_life": "903",
        "clan_building": "4423",
        "clans": "230",
        "class_representative": "1532",
        "classic": "7777",
        "classical_music": "3351",
        "clever_female_lead": "7736",
        "clever_male_lead": "5635",
        "clingy_lover": "2356",
        "clones": "2274",
        "clubs": "611",
        "clumsy_female_lead": "10656",
        "co-workers": "7951",
        "coding": "6479",
        "cohabitation": "710",
        "cold_female_lead": "520",
        "cold_male_lead": "98",
        "collection_of_short_stories": "8656",
        "college/university": "7776",
        "coma": "1675",
        "comedic_undertone": "124",
        "coming_of_age": "282",
        "compassionate_protagonist": "7354",
        "competition": "8480",
        "complex_family_relationships": "4822",
        "concubines": "1171",
        "conditional_power": "7117",
        "confident_male_lead": "6558",
        "confinement": "1404",
        "conflicting_loyalties": "3241",
        "conspiracies": "11119",
        "contract_spirits": "7254",
        "contracts": "859",
        "controversial": "1282",
        "cooking": "2506",
        "corpses": "1565",
        "corruption": "352",
        "cosmic_wars": "9926",
        "cosplay": "7844",
        "couple_growth": "592",
        "court_official": "5792",
        "cousins": "836",
        "cowardly_protagonist": "3752",
        "crafting": "5944",
        "crime": "2969",
        "crime_organization": "9765",
        "criminal_profilers": "3347",
        "criminals": "443",
        "crippled_protagonist": "5392",
        "cross-dressing": "769",
        "crossover": "1795",
        "cruel_lovers": "3242",
        "cruel_male_lead": "8693",
        "cruel_protagonist": "7293",
        "cruelty_depictions": "9825",
        "crybaby_characters": "11544",
        "cult": "8491",
        "cultivation": "117",
        "cunnilingus": "4596",
        "cunning_female_lead": "3672",
        "cunning_male_lead": "184",
        "curious_female_lead": "829",
        "cursed_item": "11710",
        "cursed_weapon": "1350",
        "curses": "579",
        "cute_daughter": "2546",
        "cute_female_lead": "4026",
        "cute_male_lead": "4070",
        "cute_story": "5525",
        "cyberpunk": "1890",
        "cyborgs": "142",
        "dancers": "8248",
        "dao_companion": "10343",
        "dao_comprehension": "6242",
        "daoism": "3824",
        "dark": "4599",
        "dark_elves": "5403",
        "dark_fantasy": "4600",
        "dark_guilds": "9364",
        "dark_humor": "8633",
        "dark_knight": "8990",
        "dead_family_members": "605",
        "dead_protagonist": "2215",
        "death": "2142",
        "death_flags": "5909",
        "death_game": "3403",
        "death_gods": "10619",
        "death_of_loved_ones": "1615",
        "debts": "5333",
        "debugger": "7355",
        "deceptive_female_lead": "5605",
        "deceptively_weak-looking_protagonist": "150",
        "decisive_male_lead": "6626",
        "defiant_male_lead": "3194",
        "delinquents": "749",
        "delusions": "1362",
        "demi-god": "10345",
        "demi-humans": "5526",
        "demon_child": "2363",
        "demon_lord": "2386",
        "demonic_cultivation": "7489",
        "demons": "86",
        "denied_feelings": "2318",
        "dense_female_lead": "159",
        "dense_male_lead": "151",
        "depression": "1946",
        "despair": "353",
        "destiny": "3135",
        "detectives": "1200",
        "determined_female_lead": "4319",
        "determined_male_lead": "8238",
        "devil_path_practitioner": "4674",
        "devoted_female_lead": "6397",
        "devoted_male_lead": "6396",
        "dhampir": "11492",
        "diaries": "750",
        "different_social_status": "2243",
        "disability": "1899",
        "disaster": "3909",
        "discrimination": "258",
        "dishonest_protagonist": "2343",
        "disney": "1791",
        "dissection": "5322",
        "distrustful_protagonist": "7949",
        "divination": "2019",
        "divine_protection": "4706",
        "divorce": "2305",
        "doctors": "2876",
        "doll_maker": "470",
        "dolls": "199",
        "domestic_affairs": "2663",
        "domineering_male_lead": "10285",
        "doppelgangers": "570",
        "dormitories": "2074",
        "doting_male_lead": "5862",
        "doting_older_brother": "2800",
        "doujins": "274",
        "dragon_bloodline": "5334",
        "dragon_girls": "164",
        "dragon_protagonist": "6780",
        "dragon_riders": "509",
        "dragon_slayers": "897",
        "dragons": "72",
        "dreams": "1406",
        "drugs": "311",
        "druids": "8126",
        "dungeon_building": "11497",
        "dungeon_in_real-world": "7188",
        "dungeon_master": "174",
        "dungeons": "175",
        "dwarfs": "3569",
        "dystopia": "1283",
        "e-sports": "6704",
        "early_romance": "7711",
        "earth_invasion": "1661",
        "easy_going_life": "5431",
        "eating_ability": "7048",
        "eccentric_male_lead": "2670",
        "economics": "784",
        "editors": "1878",
        "eidetic_memory": "3796",
        "elemental_magic": "9855",
        "elves": "165",
        "emotionally_strong_female_lead": "2306",
        "emotionally_strong_male_lead": "8237",
        "emotionally_weak_female_lead": "1647",
        "emotionally_weak_male_lead": "9677",
        "empires": "3570",
        "enemies_become_allies": "840",
        "enemies_become_lovers": "113",
        "engagement": "263",
        "engineer": "2735",
        "enlightenment": "4480",
        "episodic": "1798",
        "espers": "5715",
        "estranged_family": "1676",
        "eunuch": "10593",
        "european_ambience": "7778",
        "evil_gods": "10172",
        "evil_male_lead": "4035",
        "evil_organizations": "5411",
        "evil_religions": "7087",
        "evolution": "2049",
        "ex-mercenary": "2700",
        "ex-police": "4139",
        "executioner": "5193",
        "exhibitionism": "6365",
        "exorcism": "711",
        "experiments": "1951",
        "eye_powers": "200",
        "eyepatch": "1237",
        "fairies": "525",
        "fairy_tale": "9237",
        "fake_love_confession": "918",
        "fallen_angels": "134",
        "fallen_nobility": "734",
        "familial_love": "12009",
        "familiars": "2152",
        "family": "641",
        "family_business": "2013",
        "family_conflict": "8664",
        "family_devotion": "4177",
        "famous_male_lead": "2888",
        "famous_parents": "1833",
        "fanaticism": "5399",
        "fanfiction": "5691",
        "fantasy_creatures": "771",
        "fantasy_world": "99",
        "farming": "3068",
        "fast_cultivation": "5068",
        "fast_learner": "7599",
        "fast-paced_story": "11352",
        "fat_male_lead": "1182",
        "fated_lovers": "2574",
        "fearless_male_lead": "3521",
        "fellatio": "3953",
        "female_cross-dress_as_male": "8228",
        "female_demographic_with_male_lead": "1936",
        "female_dominance": "1771",
        "female_fighters": "191",
        "female_knights": "11386",
        "female_lead_falls_in_love_first": "919",
        "female_master": "5262",
        "female_protagonist": "2879",
        "female_to_male": "4178",
        "feminine_male_lead": "8888",
        "feng_shui": "10919",
        "firearms": "9340",
        "first_love": "1569",
        "first-time_intercourse": "4880",
        "fishing": "2245",
        "flag_interception": "9200",
        "flashbacks": "6061",
        "folklore": "923",
        "food": "2382",
        "forbidden_love": "1633",
        "forced_into_a_relationship": "1353",
        "forced_living_arrangements": "606",
        "forced_marriage": "3052",
        "forced_work": "1900",
        "foreigners": "1519",
        "forensics": "5469",
        "forgetful_protagonist": "2367",
        "former_hero": "7405",
        "fortuitous_event": "4361",
        "foul_mouthed_protagonist": "4549",
        "fox_spirits": "6222",
        "friends_become_enemies": "1576",
        "friends_grow_distant": "1539",
        "friendship": "1476",
        "fudanshi": "9414",
        "fujoshi": "797",
        "funny_female_lead": "8268",
        "funny_male_lead": "4346",
        "futanari": "3468",
        "futuristic_setting": "2616",
        "gacha": "9660",
        "galge": "7643",
        "gambling": "9425",
        "game_elements": "93",
        "game_roles": "664",
        "gamers": "225",
        "games": "213",
        "gangs": "313",
        "gate_to_another_world": "5382",
        "genderless_protagonist": "9295",
        "genetic_modification": "1177",
        "genies": "2014",
        "genius_female_lead": "5767",
        "genius_male_lead": "3055",
        "genius_scientist": "2722",
        "genji_monogatari": "743",
        "ghost_companion": "9073",
        "ghost_protagonist": "744",
        "ghost_summoning": "9176",
        "ghosts": "515",
        "ghoul": "2617",
        "giants": "2143",
        "given_powers": "2725",
        "gladiators": "2044",
        "glasses-wearing_female_lead": "8084",
        "glasses-wearing_male_lead": "275",
        "gluttony": "5309",
        "goblins": "11494",
        "god_bloodline": "10908",
        "god_protagonist": "6683",
        "god-human_relationship": "1354",
        "goddesses": "1355",
        "godly_powers": "73",
        "gods": "177",
        "golems": "4437",
        "gore": "455",
        "gossip": "11504",
        "grave_keepers": "1736",
        "greedy_male_lead": "3979",
        "grimoires": "7717",
        "grinding": "807",
        "grotesque": "9642",
        "group_sex": "6334",
        "guardian_relationship": "2005",
        "guilds": "438",
        "gunfighters": "792",
        "gyaru": "11490",
        "gynophobia": "1896",
        "hackers": "1753",
        "halberd_wielder": "9059",
        "half-human_protagonist": "9445",
        "half-sister": "4886",
        "hammer_user": "11062",
        "han_dynasty": "8640",
        "handjob": "9873",
        "handsome_male_lead": "192",
        "handsome_seme": "11482",
        "hard_life": "6758",
        "hard_working_female_lead": "6550",
        "hard-working_male_lead": "4219",
        "hardworking_protagonist": "11344",
        "harem-seeking_male_lead": "500",
        "harsh_training": "8149",
        "hated_protagonist": "2307",
        "haunted_location": "1543",
        "healers": "12141",
        "heartwarming": "5267",
        "heaven": "242",
        "heavenly_tribulation": "4770",
        "hell": "4720",
        "helpful_female_lead": "5876",
        "herbalist": "808",
        "heretics": "10473",
        "heroes": "100",
        "heroic_male_lead": "5143",
        "heterochromia": "2111",
        "hibernation": "166",
        "hidden_abilities": "7227",
        "hidden_boss": "5056",
        "hiding_true_abilities": "6384",
        "hiding_true_identity": "10134",
        "high-school_students": "315",
        "hikikomori": "765",
        "historical_figures": "8485",
        "homunculus": "2741",
        "honest_protagonist": "1772",
        "honors_students": "920",
        "hospital": "1387",
        "hot-blooded_female_lead": "1759",
        "hot-blooded_male_lead": "912",
        "human_evolution": "7325",
        "human_experiments": "354",
        "human_weapon": "1687",
        "human-nonhuman_relationship": "259",
        "humanoids": "874",
        "hunters": "494",
        "hunting": "8729",
        "hybrid": "9532",
        "hypnotism": "1711",
        "identity_crisis": "10075",
        "idols": "562",
        "illegitimate_child/ren": "3246",
        "illusion": "3911",
        "image_change": "1363",
        "imaginary_friend": "3555",
        "immature_adults": "1459",
        "immortals": "233",
        "imperial_harem": "9033",
        "important_non-romantic_relationships": "1184",
        "impulsive_male_lead": "8170",
        "incest": "626",
        "incomplete_due_to_author/artist_death": "2197",
        "incubus": "3398",
        "indecisive_protagonist": "2319",
        "independent_female_lead": "6440",
        "industrialization": "12135",
        "inferiority_complex": "506",
        "inheritance": "1400",
        "innocent_female_lead": "153",
        "innocent_male_lead": "6406",
        "innocent_uke": "5613",
        "innovative_male_lead": "10578",
        "inscriptions": "5132",
        "insects": "550",
        "interconnected_storylines": "4539",
        "interdimensional_travel": "11229",
        "internet": "1613",
        "interracial_couples": "1556",
        "interspatial_storage": "4624",
        "intrigue": "2660",
        "introverted_male_lead": "10579",
        "investigations": "9064",
        "invisibility": "3978",
        "islands": "1461",
        "jack_of_all_trades": "3687",
        "janitor": "5338",
        "jealousy": "1864",
        "jiangshi": "6665",
        "jobless_class": "7086",
        "jsdf": "5300",
        "katana": "11591",
        "kidnappings": "1250",
        "killer": "2940",
        "kind_female_lead": "7036",
        "kind_male_lead": "278",
        "kingdom_building": "3869",
        "kingdoms": "1904",
        "knights": "137",
        "kuudere": "571",
        "labyrinth": "4987",
        "lack_of_common_sense": "5086",
        "language_barrier": "5426",
        "large_number_of_skills": "5151",
        "late_romance": "5920",
        "lawyers": "4551",
        "lazy_protagonist": "338",
        "leadership": "6706",
        "legendary_artifacts": "5348",
        "legends": "3430",
        "level_system": "7443",
        "lgbt_parents": "2119",
        "librarians": "545",
        "library": "1402",
        "lich": "8453",
        "lies": "4353",
        "life-changing_events": "717",
        "lifestyle_change": "6439",
        "limited_lifespan": "2222",
        "live-in_lover": "712",
        "living_abroad": "3154",
        "living_alone": "1437",
        "loli": "3715",
        "lone_wolf": "9539",
        "loneliness": "865",
        "loner_protagonist": "651",
        "long_separations": "2891",
        "long-distance_relationship": "1859",
        "lost_civilizations": "1696",
        "lottery": "7151",
        "love_at_first_sight": "1561",
        "love_comedy": "7455",
        "love_interest_change": "2285",
        "love_rivals": "627",
        "love_triangles": "607",
        "lovers_reunited": "1616",
        "low_key_protagonist": "9161",
        "loyal_servants": "11156",
        "lucky_protagonist": "6526",
        "mafia": "442",
        "magic": "60",
        "magic_beasts": "6095",
        "magic_crests": "3700",
        "magic_formations": "3038",
        "magic_items": "5421",
        "magic_shop": "2059",
        "magic_technology": "6013",
        "magic_weapons": "4056",
        "magical_engineering": "62",
        "magical_girls": "516",
        "magical_space": "3460",
        "maids": "336",
        "makeshift_family": "1841",
        "male_demographic_with_female_lead": "266",
        "male_lead_falls_in_love_first": "162",
        "male_protagonist": "3257",
        "male_to_female": "171",
        "male_yandere": "557",
        "management": "2604",
        "mangaka": "2781",
        "manipulation": "1220",
        "manipulative_female_lead": "2344",
        "manipulative_male_lead": "6726",
        "manly_gay_couple": "2084",
        "marriage": "642",
        "marriage_of_convenience": "706",
        "martial_spirits": "10145",
        "masculine_female_lead": "8889",
        "masculine_uke": "1656",
        "masked_character": "2089",
        "masochists": "290",
        "master-disciple_relationship": "667",
        "master-servant_relationship": "260",
        "masturbation": "2501",
        "mathematics": "7244",
        "matriarchy": "6437",
        "mature_protagonist": "279",
        "mechanical_civilization": "7148",
        "mechanical_engineering": "63",
        "medical": "910",
        "medical_knowledge": "9021",
        "medicine": "2719",
        "medieval": "4498",
        "mental_age_regression": "10693",
        "mercenaries": "9573",
        "merchant": "1991",
        "mermaid": "8681",
        "metallurgy": "6742",
        "meticulous_protagonist": "9310",
        "middle_eastern": "1804",
        "military": "589",
        "military_generals": "8269",
        "mind_break": "6073",
        "mind_control": "456",
        "mind_games": "1905",
        "mind_reading": "10258",
        "mining": "8580",
        "misandry": "11503",
        "misfits": "775",
        "misfortune": "238",
        "mismatched_couple": "1516",
        "misunderstandings": "172",
        "misunderstood_protagonist": "580",
        "mixed_blood": "613",
        "mmorpg": "105",
        "model": "8994",
        "modern_day": "2606",
        "modern_knowledge": "2666",
        "modern_weapons": "4481",
        "molesting": "1221",
        "monarchy": "8989",
        "money_grubber": "3754",
        "monster_fusing_ability": "4544",
        "monster_girls": "510",
        "monster_society": "8988",
        "monster_tamer": "253",
        "monsters": "261",
        "motorcycles": "2223",
        "movie_business": "572",
        "movies": "345",
        "multiple_bloodlines": "10711",
        "multiple_deaths": "4722",
        "multiple_endings": "5810",
        "multiple_identities": "7163",
        "multiple_personalities": "8266",
        "multiple_povs": "4538",
        "multiple_protagonists": "441",
        "multiple_realms": "3706",
        "multiple_reincarnated_individuals": "5149",
        "multiple_storylines": "7978",
        "multiple_summoned_individuals": "10000",
        "multiple_timelines": "7802",
        "murders": "885",
        "music": "1231",
        "musicians": "538",
        "mutated_creatures": "5036",
        "mutations": "68",
        "mute_character": "1141",
        "mysterious_elements": "924",
        "mysterious_family_background": "8440",
        "mysterious_illness": "2224",
        "mysterious_past": "4783",
        "mysterious_powers": "1677",
        "mysterious_protagonist": "523",
        "mystery_solving": "3537",
        "mythical_beasts": "8995",
        "mythology": "1474",
        "naive_female_lead": "243",
        "naive_male_lead": "143",
        "narcissistic_male_lead": "11984",
        "nationalism": "6204",
        "natural_disaster": "3908",
        "naval_warfare": "873",
        "near-death_experience": "130",
        "necromancer": "186",
        "neet": "1728",
        "nerdy_male_lead": "144",
        "netorare": "4126",
        "netori": "3862",
        "nightmares": "6164",
        "ninjas": "1725",
        "nobles": "265",
        "non-human_protagonist": "3388",
        "non-linear_storytelling": "2514",
        "nudity": "1524",
        "nuns": "759",
        "nurses": "7551",
        "oath": "9923",
        "obsessive_love": "1477",
        "occult": "1908",
        "office_romance": "9331",
        "older_female_younger_male": "284",
        "older_male_younger_female": "1649",
        "older_seme_younger_uke": "1416",
        "older_uke_younger_seme": "1265",
        "one-shot": "3545",
        "online_game": "1142",
        "online_romance": "5122",
        "onmyouji": "2060",
        "onsens": "7782",
        "opposites_attract": "3248",
        "orchestral_conductors": "9947",
        "orcs": "6211",
        "organ_transplant": "2172",
        "organized_crime": "2645",
        "orphans": "125",
        "otaku": "277",
        "otome_game": "466",
        "outcasts": "726",
        "outdoor_intercourse": "1222",
        "outer_space": "875",
        "outlaw": "5401",
        "overcoming_the_past": "286",
        "overpowered_female_lead": "9763",
        "overpowered_protagonist": "4598",
        "overprotective_siblings": "145",
        "pacifist_protagonist": "8832",
        "painters": "2075",
        "paizuri": "6049",
        "paladin": "6225",
        "parallel_dimension": "812",
        "parallel_worlds": "318",
        "paranoia": "10696",
        "paranormal": "8616",
        "parasites": "1300",
        "parent_complex": "4741",
        "parody": "2350",
        "part-time_job": "628",
        "passive_protagonist": "6165",
        "past_memories": "11312",
        "past_plays_a_big_role": "220",
        "past_trauma": "6457",
        "patissier": "7651",
        "perceptive_male_lead": "3695",
        "persian_influences": "1243",
        "persistent_male_lead": "2889",
        "personality_changes": "488",
        "perverted_female_lead": "287",
        "perverted_male_lead": "458",
        "perverted_seme": "1266",
        "pessimistic_male_lead": "4049",
        "pets": "2710",
        "pharmacist": "5623",
        "philosophical": "1799",
        "phobias": "1817",
        "phoenix_bloodline": "10698",
        "phoenixes": "8790",
        "photography": "1371",
        "physical_deformity": "2252",
        "pill_based_cultivation": "3019",
        "pill_concocting": "9071",
        "pill_master": "5264",
        "piloted_robots": "585",
        "pilots": "1215",
        "pirates": "3025",
        "pitiful_male_lead": "10580",
        "pixies": "5598",
        "playboys": "1311",
        "playful_female_lead": "2833",
        "playful_male_lead": "5527",
        "plot_against_protagonist": "5349",
        "plot_twists": "8954",
        "poetry": "7813",
        "poisons": "2674",
        "police": "83",
        "polite_male_lead": "2176",
        "political_marriage": "708",
        "politics": "298",
        "politics_involving_royalty": "163",
        "pollution": "1824",
        "polyandry": "11890",
        "polygamy": "2684",
        "poor_background": "5209",
        "poor_female_lead": "2358",
        "poor_male_lead": "228",
        "poor_talent": "10549",
        "poor_to_rich": "8801",
        "popular_female_lead": "154",
        "popular_male_lead": "483",
        "possession": "94",
        "possessive_female_lead": "9416",
        "possessive_lovers": "1495",
        "possessive_male_lead": "5858",
        "possessive_seme": "11480",
        "post-apocalyptic": "1301",
        "post-epidemic/pandemic": "1302",
        "post-war": "3156",
        "poverty": "4662",
        "power_boost": "2726",
        "power_couple": "2551",
        "power_struggle": "673",
        "power_suits": "7905",
        "powerful_assisting_items": "4632",
        "pragmatic_protagonist": "564",
        "precognition": "2020",
        "pregnancy": "3330",
        "pretend_lovers": "1763",
        "previous_life_talent": "1124",
        "priestess/es": "3534",
        "priests": "2341",
        "prison": "1426",
        "prisoner_of_war": "1382",
        "proactive_protagonist": "701",
        "producers": "11390",
        "programmer": "6302",
        "progression": "4231",
        "promiscuous_male_lead": "8426",
        "prophecy": "2090",
        "prosthesis": "146",
        "prostitutes": "1892",
        "protagonist_loyal_to_love_interest": "593",
        "protagonist_seeks_bad_end": "6055",
        "protagonist_strong_from_the_start": "167",
        "protagonist_with_two_bodies": "5603",
        "protective_male_lead": "5875",
        "psychics": "3541",
        "psychokinesis": "2133",
        "psychopaths": "846",
        "punishments": "1657",
        "puppet": "6707",
        "puppeteers": "9950",
        "qing_dynasty": "8643",
        "quests": "239",
        "quiet_female_lead": "2076",
        "quiet_male_lead": "1342",
        "quirky_characters": "931",
        "r-15": "2738",
        "r-18": "4074",
        "race_change": "2903",
        "racism": "3314",
        "radio_host": "8168",
        "ranked_by_strength": "131",
        "ranking_system": "9281",
        "rape": "431",
        "rape_victims": "1427",
        "rape_victims_become_lovers": "3952",
        "rational_female_lead": "8646",
        "reality_show": "10996",
        "rebellion": "5574",
        "redemption": "289",
        "regeneration": "1525",
        "regicide": "9546",
        "reincarnated_as_a_monster": "447",
        "reincarnated_as_an_object": "9480",
        "reincarnated_into_a_game_world": "7297",
        "reincarnated_into_another_world": "6304",
        "reincarnation": "120",
        "religion": "761",
        "religious_references": "2091",
        "reluctant_protagonist": "179",
        "reporters": "1684",
        "rescue": "3250",
        "restaurant": "1835",
        "resurrection": "1209",
        "revenge": "121",
        "reverse_harem": "558",
        "reverse_rape": "4500",
        "rich_characters": "600",
        "rich_family": "147",
        "rich_female_lead": "229",
        "rich_male_lead": "1805",
        "rich_to_poor": "11448",
        "righteous_protagonist": "7780",
        "rivalry": "614",
        "rivals_become_lovers": "2173",
        "robots": "766",
        "rogue_cultivator": "4396",
        "romantic_subplot": "334",
        "roommates": "106",
        "royal_servant": "6361",
        "royalty": "335",
        "rpg": "205",
        "ruthless_female_lead": "2345",
        "ruthless_male_lead": "127",
        "ruthless_seme": "11481",
        "sacrifice": "8424",
        "sadistic_male_lead": "9022",
        "sadists": "1223",
        "saints": "7288",
        "salaryman": "1189",
        "samurai": "826",
        "saving_the_world": "788",
        "scary_female_lead": "6410",
        "scary_male_lead": "745",
        "scheming": "6096",
        "schizophrenia": "2288",
        "school_clubs": "1135",
        "schools": "8265",
        "scientists": "843",
        "sculptors": "426",
        "scythe_wielder": "9058",
        "sealed_power": "732",
        "searching_for_love": "206",
        "searching_for_something": "1640",
        "secluded_life": "8599",
        "second_chance": "2571",
        "secret_crush": "1475",
        "secret_identity": "214",
        "secret_organizations": "827",
        "secret_relationship": "1190",
        "secretive_male_lead": "692",
        "secrets": "1623",
        "sect_development": "7536",
        "seduction": "2595",
        "seeing_things_other_humans_can't": "201",
        "seer": "9687",
        "seke": "1418",
        "self_aware": "5677",
        "self-sacrificing_female_lead": "5144",
        "selfish_protagonist": "1463",
        "selfless_protagonist": "1372",
        "seme_partner": "6315",
        "seme_turned_uke": "1852",
        "senpai-kouhai_relationship": "629",
        "sentai_heroes": "8494",
        "sentient_items": "10004",
        "sentient_weapon": "90",
        "serial_killers": "1328",
        "servants": "254",
        "seven_deadly_sins": "3863",
        "seven_heavenly_virtues": "9253",
        "sex_friends": "4432",
        "sex_slaves": "656",
        "sex_toys": "1502",
        "sexual_abuse": "3252",
        "sexual_cultivation_technique": "6245",
        "sexual_innuendo": "2026",
        "shameless_female_lead": "2691",
        "shameless_male_lead": "3580",
        "shapeshifters": "10602",
        "sharing_a_body": "7874",
        "sharp-tongued_male_lead": "328",
        "shield_wielder": "11388",
        "shikigami": "2280",
        "shinto": "2061",
        "shogi": "1938",
        "short_chapters": "5871",
        "short_female_lead": "762",
        "short_male_lead": "586",
        "short_story": "3358",
        "short-tempered_protagonist": "207",
        "shota": "5580",
        "shoujo-ai_subplot": "7147",
        "shounen-ai_subplot": "7146",
        "show_host": "8541",
        "showbiz": "565",
        "shrine_maidens": "767",
        "shy_female_lead": "208",
        "sibling_rivalry": "1971",
        "sibling's_care": "8186",
        "siblings": "1411",
        "siblings_not_related_by_blood": "65",
        "sickly_character": "2603",
        "sightseeing": "5675",
        "sign_language": "8631",
        "silat": "9614",
        "silent_protagonist": "1536",
        "silly_female_lead": "3705",
        "simple-minded_female_lead": "244",
        "simple-minded_male_lead": "10658",
        "singers": "209",
        "single_parent": "1985",
        "sister_complex": "668",
        "skeletons": "5880",
        "skill_assimilation": "3820",
        "skill_books": "7032",
        "skill_carry-over": "4894",
        "skill_creation": "6753",
        "skill_mimicry": "4887",
        "skills": "5407",
        "slave_harem": "3936",
        "slave_protagonist": "5420",
        "slaves": "180",
        "sleeping": "3014",
        "slime": "1126",
        "slow_growth_at_start": "3185",
        "slow_romance": "76",
        "slow-paced_story": "6046",
        "smart_children": "11326",
        "smart_couple": "831",
        "smart_female_lead": "362",
        "smart_male_lead": "66",
        "smartphone": "9661",
        "snipers": "727",
        "soccer": "8899",
        "social_gap": "1717",
        "social_outcasts": "652",
        "soldiers": "674",
        "solo_player": "4588",
        "sorcery": "738",
        "soul_fusion": "9690",
        "soul_power": "7828",
        "souls": "4627",
        "space_opera": "1779",
        "spanning_generations": "1261",
        "spatial_manipulation": "8777",
        "spear_wielder": "4842",
        "special_abilities": "323",
        "special_forces_member": "5902",
        "special_squads": "2300",
        "special_techniques": "5350",
        "special_weapons": "262",
        "speech_impediment": "582",
        "spellcraft": "8816",
        "spies": "2069",
        "spirit_advisor": "2586",
        "spirit_users": "11422",
        "spirits": "202",
        "spiritual_power": "2475",
        "spoiled_child": "8947",
        "staff_wielder": "10894",
        "stalkers": "1713",
        "star_cultivation": "8922",
        "step_siblings": "4773",
        "stockholm_syndrome": "1373",
        "stoic_female_lead": "181",
        "stoic_male_lead": "683",
        "straight_seme": "1191",
        "straight_uke": "1594",
        "straightforward_female_lead": "753",
        "straightforward_male_lead": "11052",
        "strategic_battles": "675",
        "strategic_minds": "188",
        "strategist": "4777",
        "strength_recover": "4869",
        "strict_parents": "1760",
        "strong_female_lead": "195",
        "strong_male_lead": "70",
        "strong_party_members": "3200",
        "strong_seme": "2085",
        "strong_to_stronger": "4971",
        "strong_uke": "2086",
        "strong-willed_female_lead": "694",
        "strong-willed_male_lead": "695",
        "stubborn_female_lead": "3930",
        "stubborn_protagonist": "1643",
        "student_council": "608",
        "student-teacher_relationship": "1224",
        "students": "587",
        "submissive_male_lead": "1861",
        "subtle_romance": "777",
        "succession": "473",
        "succubus": "645",
        "sudden_appearance": "713",
        "sudden_deaths": "1238",
        "sudden_disappearances": "2006",
        "sudden_strength_gain": "898",
        "sudden_wealth": "9574",
        "suicidal_tendencies": "9636",
        "suicides": "1743",
        "summoned_hero": "2990",
        "summoning_magic": "4127",
        "super_heroes": "3594",
        "super_senses": "2062",
        "supernatural_items": "9704",
        "superstars": "8247",
        "support_abilities": "6309",
        "survival": "347",
        "survival_game": "348",
        "suspense": "11595",
        "swimming": "1626",
        "sword_and_magic": "4302",
        "sword_sects": "3686",
        "swords": "210",
        "swordsman": "196",
        "swordsmanship": "8757",
        "swordswoman": "1179",
        "system_administrator": "7357",
        "taekwondo": "11659",
        "talented_female_lead": "653",
        "talented_male_lead": "294",
        "talisman_making": "8487",
        "tang_dynasty": "8082",
        "tattoo": "8738",
        "teachers": "1749",
        "team_battles": "2937",
        "teamwork": "1847",
        "technology_gap": "4933",
        "telekinesis": "5340",
        "teleportation": "5341",
        "tentacles": "8760",
        "terminal_illness": "2225",
        "terrorist_attack": "1783",
        "terrorists": "2196",
        "theater": "619",
        "thieves": "1360",
        "three_kingdoms_period": "676",
        "threesome": "1420",
        "thriller": "2970",
        "time_leap": "4518",
        "time_loop": "886",
        "time_manipulation": "2054",
        "time_paradox": "887",
        "time_skip": "360",
        "time_travel": "92",
        "timid_female_lead": "4855",
        "timid_protagonist": "5085",
        "tomb_raiding": "11724",
        "tomboyish_female_lead": "267",
        "torture": "355",
        "tragic_past": "148",
        "tragic_protagonist": "356",
        "training": "77",
        "trains": "3745",
        "transfer_students": "615",
        "transforming_weapons": "9585",
        "transmigration": "3046",
        "transplanted_memories": "4323",
        "transported_into_a_game_world": "7663",
        "transported_modern_structure": "6559",
        "transported_to_another_world": "95",
        "trap": "1279",
        "treasures": "5496",
        "tribal_society": "5825",
        "trickster": "4856",
        "tsundere": "795",
        "tsundere_male_lead": "5289",
        "tsundere_uke": "1571",
        "twins": "518",
        "twisted_personality": "10488",
        "ugly_male_lead": "7278",
        "ugly_to_beautiful": "4851",
        "uke_protagonist": "6313",
        "uncivilized_male_lead": "3565",
        "unconditional_love": "1595",
        "undead": "189",
        "underdog_protagonist": "3864",
        "underestimated_female_lead": "4661",
        "underestimated_male_lead": "2476",
        "underworld": "84",
        "unexpected_feelings": "1383",
        "unique_cultivation_technique": "3718",
        "unique_powers": "8670",
        "unique_skills": "4893",
        "unlucky_protagonist": "2314",
        "unreliable_narrator": "4697",
        "unrequited_love": "1268",
        "unscrupulous_characters": "223",
        "urban_legends": "2180",
        "valkyrie": "1846",
        "vampires": "149",
        "vengeance": "12050",
        "video_games": "108",
        "village": "1700",
        "villager": "3970",
        "villain_protagonist": "646",
        "villainess_noble_girls": "11404",
        "vintage": "4342",
        "violent_female_lead": "198",
        "virtual_reality": "109",
        "vocaloid": "1634",
        "voice_actors": "2887",
        "voyeurism": "3256",
        "vrmmorpg": "110",
        "waiters": "1216",
        "war_records": "5128",
        "warlords": "677",
        "warring_states_period": "3134",
        "warriors": "6377",
        "wars": "101",
        "weak_female_lead": "739",
        "weak_male_lead": "321",
        "weak_to_strong": "71",
        "weak-willed_male_lead": "6331",
        "werewolves": "1986",
        "whip_user": "6400",
        "wishes": "1338",
        "witches": "1829",
        "wizards": "634",
        "wolves": "8692",
        "workaholic": "7652",
        "world_domination": "895",
        "world_travel": "364",
        "writers": "548",
        "yakuza": "7230",
        "yandere": "291",
        "youkai": "926",
        "young_male_lead": "686",
        "young_to_old": "7302",
        "younger_brothers": "11677",
        "younger_sisters": "11678",
        "zombie_apocalypse": "459",
        "zombies": "350"
    }

    urlargs = {
        'org': '',      # Language
        'nt': '',       # Novel Type
        'gi': '',       # Genre
        'mgi': '',      # AND/OR Condition for Genre
        'rl': '',       # Number of Releases
        'mrl': '',      # MIN/MAX Number of Releases
        'rf': '',       # Release Frequency
        'mrf': '',      # MIN/MAX Release Frequency
        'rt': '',       # Rating
        'mrt': '',      # MIN/MAX Rating
        'rtc': '',      # Number of Ratings
        'mrtc': '',     # MIN/MAX Number of Ratings
        'rct': '',      # Number of Readers
        'mrct': '',     # MIN/MAX number of Readers
        'tgi': '',      # Tags to Include
        'mtgi': '',     # AND/OR Condition for Tags
        'tge': '',      # Tags to Exclude
        'dt': '',       # Last Release Date
        'mdt': '',      # MIN/MAX Last Release Date
        'cp': '',       # YES/NO Completely Translated
        'sort': '',     # Sorting Method
        'order': '',    # Sorting Order
    }

    search_filter = SoupStrainer('div', {'class': 'w-blog-list'})

    async with session.get(base_url, params=urlargs, headers=headers) as response:
        adv_search_soup = BeautifulSoup(await response.text(), 'lxml', parse_only=search_filter)

    session.close()

    if 'No posts were found.' in adv_search_soup.find('div', {'class': 'l-content'}).text:
        search_result = {'info': 'no posts were found'}
    else:
        search_result = parse_search(adv_search_soup)

    return search_result


@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def get_latest_series(limit=None) -> dict:
    """Get latest series added"""
    await init()

    url = 'http://www.novelupdates.com/latest-series/'

    latest_filter = SoupStrainer('div', {'class': 'g-html'})

    async with session.get(url, headers=headers) as response:
        latest_series_soup = BeautifulSoup(await response.text(), 'lxml', parse_only=latest_filter)



    session.close()
    return {'error': 'unimplemented'}


@hug.cli()
@hug.get(versions=1, output=hug.output_format.pretty_json)
async def get_series_ranking(limit=None) -> dict:
    """Get series ranking"""
    await init()

    url = 'http://www.novelupdates.com/series-ranking/'

    async with session.get(url, headers=headers) as response:
        series_ranking_soup = BeautifulSoup(await response.text(), 'lxml')
    session.close()
    return {'error': 'unimplemented'}


@hug.not_found(output=hug.output_format.html)
async def not_found_html(documentation: hug.directives.documentation):
    """Generate HTML based 404 page"""
    template = """
        <html>
        <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
        </head>
        <body>
    """
    generated_404 = json2html.convert(documentation, table_attributes="class=\"table table-bordered\"")
    return f'{template}{generated_404}</body></html>'
