genre_aliases.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Genre alias normalization and profile key mapping.
  5. """
  6. from __future__ import annotations
  7. GENRE_INPUT_ALIASES: dict[str, str] = {
  8. "修仙/玄幻": "修仙",
  9. "玄幻修仙": "修仙",
  10. "玄幻": "修仙",
  11. "修真": "修仙",
  12. "都市修真": "都市异能",
  13. "都市高武": "高武",
  14. "都市奇闻": "都市脑洞",
  15. "古言脑洞": "古言",
  16. "游戏电竞": "电竞",
  17. "电竞文": "电竞",
  18. "直播": "直播文",
  19. "直播带货": "直播文",
  20. "主播": "直播文",
  21. "克系": "克苏鲁",
  22. "克系悬疑": "克苏鲁",
  23. }
  24. GENRE_PROFILE_KEY_ALIASES: dict[str, str] = {
  25. "修仙": "xianxia",
  26. "修仙/玄幻": "xianxia",
  27. "玄幻": "xianxia",
  28. "爽文/系统流": "shuangwen",
  29. "高武": "xianxia",
  30. "西幻": "xianxia",
  31. "都市异能": "urban-power",
  32. "都市脑洞": "urban-power",
  33. "都市日常": "urban-power",
  34. "狗血言情": "romance",
  35. "古言": "romance",
  36. "青春甜宠": "romance",
  37. "替身文": "substitute",
  38. "规则怪谈": "rules-mystery",
  39. "悬疑脑洞": "mystery",
  40. "悬疑灵异": "mystery",
  41. "知乎短篇": "zhihu-short",
  42. "电竞": "esports",
  43. "直播文": "livestream",
  44. "克苏鲁": "cosmic-horror",
  45. }
  46. def normalize_genre_token(token: str) -> str:
  47. value = str(token or "").strip()
  48. if not value:
  49. return ""
  50. return GENRE_INPUT_ALIASES.get(value, value)
  51. def to_profile_key(genre: str) -> str:
  52. value = str(genre or "").strip()
  53. if not value:
  54. return ""
  55. normalized = normalize_genre_token(value)
  56. return GENRE_PROFILE_KEY_ALIASES.get(normalized, normalized.lower())