/ main.py
main.py
1 import asyncio 2 import os 3 from pathlib import Path 4 import PornAPI.Soundgasm as sg 5 import shutil 6 7 blocked_chars = set(r'\/:*?"<>|') 8 9 def sanitize_filename(filename: str) -> str: 10 """ 11 Remove characters not allowed in filenames across major platforms. 12 Trims trailing spaces and dots, and avoids reserved Windows names. 13 """ 14 name = ''.join(c for c in filename if c not in blocked_chars) 15 name = name.strip(" .") 16 reserved = {"CON", "PRN", "AUX", "NUL"} | {f"COM{i}" for i in range(1, 10)} | {f"LPT{i}" for i in range(1, 10)} 17 if name.upper() in reserved: 18 name = f"_{name}" 19 return name 20 21 async def proc(user: sg.User): 22 path = Path("downloads") / user.username 23 path.mkdir(parents=True, exist_ok=True) 24 tracks = await user.fetch_tracks() 25 tracks.sort(key=lambda x: x.duration or 0, reverse=True) 26 for track in tracks: 27 track.title = sanitize_filename(track.title) 28 track.description = sanitize_filename(track.description) if track.description else "No Description" 29 print(f"[*] Downloading {track.title} by {user.username}...") 30 filename = f"{track.title[:100]}_{track.description[:100]}.m4a" 31 filepath = path / filename 32 await track.download(filepath) 33 print(f"[**] Downloaded {track.title}") 34 35 async def main(): 36 """ 37 Entry point for downloading tracks from multiple Soundgasm users. 38 Keeps existing downloads unless --fresh flag is provided. 39 """ 40 if "--fresh" in os.sys.argv: 41 if os.path.exists("downloads"): 42 shutil.rmtree("downloads") 43 os.mkdir("downloads") 44 else: 45 Path("downloads").mkdir(exist_ok=True) 46 users = [ 47 sg.User("pompompuppy"), 48 sg.User("JessieVA"), 49 sg.User("IvyWilde"), 50 sg.User("muffinsmuffins") 51 ] 52 await asyncio.gather(*(proc(u) for u in users)) 53 54 if __name__ == "__main__": 55 asyncio.run(main())