import urllib.request
import os
import ssl
import zipfile
import io

ssl._create_default_https_context = ssl._create_unverified_context

inter_url = "https://github.com/rsms/inter/releases/download/v4.0/Inter-4.0.zip"
print(f"Downloading Inter from {inter_url}")
try:
 req = urllib.request.Request(inter_url, headers={'User-Agent': 'Mozilla/5.0'})
 with urllib.request.urlopen(req) as response:
  with zipfile.ZipFile(io.BytesIO(response.read())) as z:
   for info in z.infolist():
    targets = ["Inter-Regular.ttf", "Inter-Bold.ttf", "Inter-Italic.ttf", "Inter-BoldItalic.ttf"]
    filename = os.path.basename(info.filename)
    if filename in targets:
     info.filename = filename
     z.extract(info, "assets/fonts/")
     print(f"Extracted {info.filename}")
except Exception as e:
 print(f"Failed to get Inter: {e}")

maple_url = "https://github.com/subframe7536/maple-font/releases/download/v6.4/MapleMono-ttf.zip"
print(f"Downloading Maple Mono from {maple_url}")
try:
 req = urllib.request.Request(maple_url, headers={'User-Agent': 'Mozilla/5.0'})
 with urllib.request.urlopen(req) as response:
  with zipfile.ZipFile(io.BytesIO(response.read())) as z:
   for info in z.infolist():
    targets = ["MapleMono-Regular.ttf", "MapleMono-Bold.ttf", "MapleMono-Italic.ttf", "MapleMono-BoldItalic.ttf"]
    filename = os.path.basename(info.filename)
    if filename in targets:
     info.filename = filename
     z.extract(info, "assets/fonts/")
     print(f"Extracted {info.filename}")
except Exception as e:
 print(f"Failed to get Maple Mono: {e}")
