Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion project-downloader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ function Download-Assets {
}
}

function Download-Fonts {
param(
[string]$JsonFile,
[string]$BaseUrl,
[string]$AssetsDir
)

$json = Get-Content $JsonFile -Raw | ConvertFrom-Json -AsHashtable

$fonts = $json.customFonts
if ($null -eq $fonts -or $fonts.Count -eq 0) {
Write-Blue " (no custom fonts)"
return
}

foreach ($font in $fonts) {
$md5ext = $font.md5ext
if ([string]::IsNullOrWhiteSpace($md5ext)) { continue }

$url = "$BaseUrl/$md5ext"
$filename = Join-Path $AssetsDir $md5ext

Write-Host " Downloading: $md5ext ... " -NoNewline
try {
Invoke-WebRequest -Uri $url -OutFile $filename -UseBasicParsing -ErrorAction Stop
Write-Green "✓"
} catch {
Write-Red "✗"
}
}
}

# --- Main Logic ---

Write-Blue "=== Project Downloader ===`n"
Expand Down Expand Up @@ -275,6 +307,9 @@ if ($null -eq $websiteInfo) {
Write-Blue "`nDownloading sounds..."
Download-Assets -JsonFile $JSON_FILE -BaseUrl $ASSETS_BASE_URL -AssetsDir $ASSETS_DIR -AssetType "sounds"

Write-Blue "`nDownloading fonts..."
Download-Fonts -JsonFile $JSON_FILE -BaseUrl $ASSETS_BASE_URL -AssetsDir $ASSETS_DIR

Write-Green "`n✓ Asset download complete!`n"

Write-Host "Do you want to create an .sb3 file? (y/n): " -ForegroundColor Cyan -NoNewline
Expand Down Expand Up @@ -425,6 +460,9 @@ if ($PAGE_HTML -match '<script data=') {
Write-Blue "`nDownloading sounds..."
Download-Assets -JsonFile $JSON_FILE -BaseUrl $ASSETS_BASE_URL -AssetsDir $ASSETS_DIR -AssetType "sounds"

Write-Blue "`nDownloading fonts..."
Download-Fonts -JsonFile $JSON_FILE -BaseUrl $ASSETS_BASE_URL -AssetsDir $ASSETS_DIR

Write-Green "`n✓ Asset download complete!`n"

# Create SB3
Expand Down Expand Up @@ -539,4 +577,4 @@ if ($PAGE_HTML -match '<script data=') {
exit 1
}

Write-Green "`nDone!"
Write-Green "`nDone!"
42 changes: 41 additions & 1 deletion project-downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@ for target in data.get('targets', []):
done <<< "$md5exts"
}

download_fonts() {
local json_file="$1"
local base_url="$2"
local assets_dir="$3"

local md5exts
md5exts=$(python3 -c "
import json, sys
with open('$json_file') as f:
data = json.load(f)
for font in data.get('customFonts', []):
ext = font.get('md5ext', '')
if ext:
print(ext)
")

local found=0
while IFS= read -r md5ext; do
[[ -z "$md5ext" ]] && continue
found=1
local url="${base_url}/${md5ext}"
local filename="${assets_dir}/${md5ext}"

echo -ne " Downloading: ${md5ext} ... "
if curl -s -f -o "$filename" "$url"; then
write_green "✓"
else
write_red "✗"
fi
done <<< "$md5exts"

[[ $found -eq 0 ]] && write_blue " (no custom fonts)"
}

# --- Main Logic ---

write_blue "=== Project Downloader ===\n"
Expand Down Expand Up @@ -279,6 +313,9 @@ if [[ -z "$SITE_ID" ]]; then
write_blue "\nDownloading sounds..."
download_assets "$JSON_FILE" "$ASSETS_BASE_URL" "$ASSETS_DIR" "sounds"

write_blue "\nDownloading fonts..."
download_fonts "$JSON_FILE" "$ASSETS_BASE_URL" "$ASSETS_DIR"

write_green "\n✓ Asset download complete!\n"

echo -ne "${CYAN}Do you want to create an .sb3 file? (y/n): ${NC}"
Expand Down Expand Up @@ -481,6 +518,9 @@ elif echo "$PAGE_HTML" | grep -q 'assets/project\.json'; then
write_blue "\nDownloading sounds..."
download_assets "$JSON_FILE" "$ASSETS_BASE_URL" "$ASSETS_DIR" "sounds"

write_blue "\nDownloading fonts..."
download_fonts "$JSON_FILE" "$ASSETS_BASE_URL" "$ASSETS_DIR"

write_green "\n✓ Asset download complete!\n"

echo -ne "${CYAN}Do you want to create an .sb3 file? (y/n): ${NC}"
Expand Down Expand Up @@ -521,4 +561,4 @@ else
exit 1
fi

write_green "\nDone!"
write_green "\nDone!"
Loading