#!/bin/env/bash

skin_api_url="https://teedata.net/api/skin/read?limit=400000"
mapres_api_url="https://teedata.net/api/mapres/read?limit=400000"
emoticon_api_url="https://teedata.net/api/gameskin/read?limit=400000"
emoticon_api_url="https://teedata.net/api/emoticon/read?limit=400000"
cursor_api_url="https://teedata.net/api/cursor/read?limit=400000"
particles_api_url="https://teedata.net/api/particle/read?limit=400000"
entity_api_url="https://teedata.net/api/entity/read?limit=400000"
font_api_url="https://teedata.net/api/font/read?limit=400000"
template_api_url="https://teedata.net/api/template/read?limit=400000"

database="https://teedata.net/databasev2"

skins=$(curl "$skin_api_url" | jq -r .result.items[].file_path)
mapres=$(curl "$mapres_api_url" | jq -r .result.items[].file_path)
emoticons=$(curl "$emoticon_api_url" | jq -r .result.items[].file_path)
cursors=$(curl "$cursor_api_url" | jq -r .result.items[].file_path)
particles=$(curl "$particles_api_url" | jq -r .result.items[].file_path)
entitys=$(curl "$entity_api_url" | jq -r .result.items[].file_path)
fonts=$(curl "$font_api_url" | jq -r .result.items[].file_path)
templates=$(curl "$template_api_url" | jq -r .result.items[].file_path)

mkdir -p skins/ mapres/ emoticon/ cursor/ particles/ entity/ font/ template/

for x in $skins; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o skins/$filename || true
done

for x in $mapres; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o mapres/$filename || true
done

for x in $emoticons; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o emoticon/$filename || true
done

for x in $cursors; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o cursor/$filename || true
done

for x in $particles; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o particles/$filename || true
done

for x in $entitys; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o entity/$filename || true
done

for x in $fonts; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o font/$filename || true
done

for x in $templates; do
	filename=$(echo "$x" | cut -d'/' -f4)
	curl "$database$x" -o template/$filename || true
done
