diff --git a/.idea/artifacts/SpriteResourceDownloader_jar.xml b/.idea/artifacts/SpriteResourceDownloader_jar.xml
new file mode 100644
index 0000000..54b96e8
--- /dev/null
+++ b/.idea/artifacts/SpriteResourceDownloader_jar.xml
@@ -0,0 +1,12 @@
+
+
+ $PROJECT_DIR$/out/artifacts/SpriteResourceDownloader_jar
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..a1a1c62
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..4b661a5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..65c267d
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,371 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ intln
+ println
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1561223475351
+
+
+ 1561223475351
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SpriteResourceDownloader:jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SpriteResourceDownloader.iml b/SpriteResourceDownloader.iml
new file mode 100644
index 0000000..78b2cc5
--- /dev/null
+++ b/SpriteResourceDownloader.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/out/artifacts/SpriteResourceDownloader_jar/SpriteResourceDownloader.jar b/out/artifacts/SpriteResourceDownloader_jar/SpriteResourceDownloader.jar
new file mode 100644
index 0000000..748a441
Binary files /dev/null and b/out/artifacts/SpriteResourceDownloader_jar/SpriteResourceDownloader.jar differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..120bc52
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+
+ de.yochyo.sprite-resource-downloader
+ SpriteResourceDownloader
+ 1.0
+
+
+ 1.3.40
+
+
+
+
+ org.jsoup
+ jsoup
+ 1.12.1
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/de/yochyo/spriteresourcedownloader/Main.kt b/src/main/java/de/yochyo/spriteresourcedownloader/Main.kt
new file mode 100644
index 0000000..ce13ec5
--- /dev/null
+++ b/src/main/java/de/yochyo/spriteresourcedownloader/Main.kt
@@ -0,0 +1,131 @@
+package de.yochyo.spriteresourcedownloader
+
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Document
+import java.io.File
+import java.lang.Exception
+import java.net.URL
+
+lateinit var host: String
+fun main(args: Array) {
+ if (args.isNotEmpty()) {
+ val builder = StringBuilder()
+ for (a in args)
+ builder.append(a)
+ val url = builder.toString().filter { it != '"' && it != '\'' }
+ host = "https://${URL(url).host}"
+ val doc = Jsoup.connect(url).get()
+ val sheetsNumber = getSheetsNumber(doc)
+ val links = getLinksToSprite(doc)
+ if(sheetsNumber != links.size) println("error in program, not all sprites are downloaded")
+ var downloaded = 1
+ val threadAmount = 5
+ for(i in 0 until threadAmount){
+ Thread{
+ for(index in i until sheetsNumber step threadAmount){
+ try {
+ val doc = Jsoup.connect(host + links[index]).get()
+ val bytes = downloadImageByUrl(doc)
+ val name = getImageNameByUrl(doc)
+ if(bytes != null && name != null){
+ saveFile("${index+1} - $name", bytes)
+ println("Downloaded $downloaded/$sheetsNumber")
+ }else println("Error downloading $index")
+ }catch (e: Exception){
+ e.printStackTrace()
+ }
+ downloaded++
+ }
+ }.start()
+ }
+
+ }
+}
+
+fun getSheetsNumber(doc: Document): Int {
+ var sheetsNumber = -1
+ for (sheetRow in doc.getElementsByClass("altrow0")) {
+ for (e in sheetRow.allElements)
+ if (e.text() == "Sheets") {
+ sheetsNumber = sheetRow.allElements.last().text().toInt()
+ }
+ }
+ return sheetsNumber
+}
+
+fun getLinksToSprite(doc: Document): ArrayList {
+ val links = ArrayList(getSheetsNumber(doc))
+ val spriteContainers = doc.getElementsByClass("updatesheeticons")
+ for (item in spriteContainers) {
+ for (i in item.getElementsByAttribute("style"))
+ links += i.attr("href")
+ }
+ return links
+}
+
+fun getImageUrl(doc: Document): String? {
+ try {
+ for (e in doc.allElements) {
+ if (e.text() == "Download this Sheet"){
+ val s = host + e.allElements.last().attr("href") //todo ist das hier jetzt der richtige link?
+ return s
+ }
+ }
+ }catch (e: Exception){}
+ return null
+}
+
+fun downloadImageByUrl(doc: Document): ByteArray? {
+ try {
+ val url = getImageUrl(doc)
+ if (url != null) {
+ try {
+ val con = URL(url).openConnection()
+ val stream = con.getInputStream()
+ val bytes = stream.readBytes()
+ stream.close()
+ return bytes
+ }catch (e: Exception){}
+ }
+ }catch (e: Exception){}
+ return null
+}
+
+fun getImageNameByUrl(doc: Document): String? {
+ try {
+ var name = ""
+ for (meta in doc.getElementsByTag("meta")) {
+ if (meta.attr("name") == "description")
+ name = meta.attr("content")
+ }
+ if (name == "") return null
+
+ val index = name.indexOf(" - The #1 source for video game sprites on the internet!")
+ return if (index != -1) name.substring(0, index)
+ else name
+ }catch (e: Exception){
+ return null
+ }
+}
+
+fun saveFile(name: String, bytes: ByteArray){
+ val file = File(nameToFilename(name))
+ file.createNewFile()
+ file.writeBytes(bytes)
+}
+
+fun removeParameters(url: String): String{
+ var url = url
+ val questionMarkIndex = url.lastIndexOf("?")
+ if(questionMarkIndex != -1)
+ url = url.substring(0, questionMarkIndex)
+ return url
+}
+fun getAbsoluteUrl(parent: String, child: String): String = parent + child
+
+private fun nameToFilename(name: String): String {
+ val s = name.filter { it != '/' && it != '\\' && it != '|' && it != ':' && it != '*' && it != '?' && it != '"' && it != '[' && it != ']' }
+ var last = s.length
+ if (last > 123) last = 123
+ return s.substring(0, last) + ".png"
+}
diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..676c860
--- /dev/null
+++ b/src/main/resources/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: de.yochyo.spriteresourcedownloader.MainKt
+
diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..676c860
--- /dev/null
+++ b/target/classes/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: de.yochyo.spriteresourcedownloader.MainKt
+
diff --git a/target/classes/META-INF/SpriteResourceDownloader.kotlin_module b/target/classes/META-INF/SpriteResourceDownloader.kotlin_module
new file mode 100644
index 0000000..a090caf
Binary files /dev/null and b/target/classes/META-INF/SpriteResourceDownloader.kotlin_module differ
diff --git a/target/classes/de/yochyo/spriteresourcedownloader/MainKt$main$1.class b/target/classes/de/yochyo/spriteresourcedownloader/MainKt$main$1.class
new file mode 100644
index 0000000..2b986f0
Binary files /dev/null and b/target/classes/de/yochyo/spriteresourcedownloader/MainKt$main$1.class differ
diff --git a/target/classes/de/yochyo/spriteresourcedownloader/MainKt.class b/target/classes/de/yochyo/spriteresourcedownloader/MainKt.class
new file mode 100644
index 0000000..86502b6
Binary files /dev/null and b/target/classes/de/yochyo/spriteresourcedownloader/MainKt.class differ