Advertisement
Guest User

retroarch platlist creator

a guest
May 3rd, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | Gaming | 0 0
  1. import json
  2. import os
  3.  
  4. # === Valid extensions by default -Change and add yo your liking===
  5. rom_extensions = [
  6.     ".nes", ".sfc", ".smc", ".gba", ".bin", ".cue", ".iso", ".img",
  7.     ".zip", ".7z", ".gen", ".md", ".z64", ".pbp"
  8. ]
  9.  
  10. # === Clean the label ===
  11. def clean_label(filename):
  12.     return os.path.splitext(os.path.basename(filename))[0].lstrip("._")
  13.  
  14. # === Base folder (run the script from here) ===
  15. root_dir = os.getcwd()
  16.  
  17. # === Loop through each platform (subfolder of Games/) - Change path as needed ===
  18. for platform in os.listdir(root_dir):
  19.     platform_path = os.path.join(root_dir, platform)
  20.     if not os.path.isdir(platform_path) or platform.startswith("."):
  21.         continue
  22.  
  23.     # Set base path for RetroArch on Android - Change path as needed
  24.     retroarch_base = f"/storage/FCC5-19ED/Games/{platform}/"
  25.  
  26.     items = []
  27.  
  28.     # Walk through the platform folder recursively
  29.     for dirpath, _, filenames in os.walk(platform_path):
  30.         for filename in filenames:
  31.             if filename.startswith("._"):
  32.                 continue
  33.  
  34.             ext = os.path.splitext(filename)[1].lower()
  35.  
  36.             # Special case: Only .cue files for PlayStation
  37.             if platform.lower() in ["playstation", "ps1", "sony - playstation"]:
  38.                 if ext != ".cue":
  39.                     continue
  40.             elif ext not in rom_extensions:
  41.                 continue
  42.  
  43.             full_path = os.path.join(dirpath, filename)
  44.             relative_to_platform = os.path.relpath(full_path, platform_path)
  45.             retroarch_path = retroarch_base + relative_to_platform.replace("\\", "/")
  46.  
  47.             items.append({
  48.                 "path": retroarch_path,
  49.                 "label": clean_label(filename),
  50.                 "core_path": "DETECT",
  51.                 "core_name": "DETECT",
  52.                 "crc32": "DETECT|crc",
  53.                 "db_name": f"{platform}.lpl"
  54.             })
  55.  
  56.     # Build playlist JSON
  57.     playlist = {
  58.         "version": "1.5",
  59.         "default_core_path": "",
  60.         "default_core_name": "",
  61.         "label_display_mode": 0,
  62.         "right_thumbnail_mode": 0,
  63.         "left_thumbnail_mode": 0,
  64.         "sort_mode": 0,
  65.         "items": items
  66.     }
  67.  
  68.     # Save .lpl file
  69.     output_path = os.path.join(root_dir, f"{platform}.lpl")
  70.     with open(output_path, "w") as f:
  71.         json.dump(playlist, f, indent=2)
  72.  
  73.     print(f"✅ Created playlist: {platform}.lpl with {len(items)} games.")
Tags: retroarch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement