Skip to content

Commit

Permalink
use Booru trait
Browse files Browse the repository at this point in the history
  • Loading branch information
pat36 committed Jun 27, 2020
1 parent 39e6314 commit 2d37f72
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 63 deletions.
16 changes: 1 addition & 15 deletions src/main/scala/libbooru/boorus/Danbooru.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package ovh.fandemonium.libbooru

import java.net.{MalformedURLException, URL}
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.nio.file.{Paths, Files}
import scala.xml.XML
import scala.collection.mutable.ArrayBuffer
import scala.io.Source
import sys.process._
import scala.language.postfixOps

object Danbooru {
object Danbooru extends Booru {
def getFiles(tags: Array[String], limit: Int): Any = {
val files = Danbooru.getFilesLinks(tags, limit)

Expand Down Expand Up @@ -45,14 +41,4 @@ object Danbooru {

posts_arr.toArray
}

def downloadFile(url: String, name: String): String = {
val directory = Paths.get(".").toAbsolutePath + "/img/"
if(!new File(directory).exists) {
new File(directory).mkdir
}
val filename = directory + name
new URL(url) #> new File(filename) !!;
filename
}
}
38 changes: 14 additions & 24 deletions src/main/scala/libbooru/boorus/Gelbooru.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package ovh.fandemonium.libbooru

import java.net.URL
import java.io.File
import java.net.{MalformedURLException, URL}
import java.io.FileWriter
import java.io.IOException
import java.nio.file.{Paths, Files}
import scala.xml.XML
import scala.collection.mutable.ArrayBuffer
import scala.io.Source
import sys.process._
import scala.language.postfixOps

object Gelbooru {
object Gelbooru extends Booru {
def getFiles(tags: Array[String], limit: Int): Any = {
val files = Gelbooru.getFilesLinks(tags, limit)

Expand All @@ -29,26 +25,20 @@ object Gelbooru {
val posts = xml\"post"

for(post <- posts) {
val url = post\@"file_url"
val tags = post\@"tags"
val md5 = post\@"md5"
val url_segments = new URL(url).getFile.split("/")
val name = url_segments(url_segments.length - 1)
val post_map = Map("url" -> url, "tags" -> tags, "md5" -> md5, "name" -> name)

posts_arr += post_map
try {
val url = post\@"file_url"
val tags = post\@"tags"
val md5 = post\@"md5"
val url_segments = new URL(url).getFile.split("/")
val name = url_segments(url_segments.length - 1)
val post_map = Map("url" -> url, "tags" -> tags, "md5" -> md5, "name" -> name)

posts_arr += post_map
} catch {
case e: MalformedURLException => println("couldn't download file")
}
}

posts_arr.toArray
}

def downloadFile(url: String, name: String): String = {
val directory = Paths.get(".").toAbsolutePath + "/img/"
if(!new File(directory).exists) {
new File(directory).mkdir
}
val filename = directory + name
new URL(url) #> new File(filename) !!;
filename
}
}
38 changes: 14 additions & 24 deletions src/main/scala/libbooru/boorus/Safebooru.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package ovh.fandemonium.libbooru

import java.net.URL
import java.io.File
import java.net.{MalformedURLException, URL}
import java.io.FileWriter
import java.io.IOException
import java.nio.file.{Paths, Files}
import scala.xml.XML
import scala.collection.mutable.ArrayBuffer
import scala.io.Source
import sys.process._
import scala.language.postfixOps

object Safebooru {
object Safebooru extends Booru {
def getFiles(tags: Array[String], limit: Int): Any = {
val files = Safebooru.getFilesLinks(tags, limit)

Expand All @@ -29,26 +25,20 @@ object Safebooru {
val posts = xml\"post"

for(post <- posts) {
val url = post\@"file_url"
val tags = post\@"tags"
val md5 = post\@"md5"
val url_segments = new URL(url).getFile.split("/")
val name = url_segments(url_segments.length - 1)
val post_map = Map("url" -> url, "tags" -> tags, "md5" -> md5, "name" -> name)

posts_arr += post_map
try {
val url = post\@"file_url"
val tags = post\@"tags"
val md5 = post\@"md5"
val url_segments = new URL(url).getFile.split("/")
val name = url_segments(url_segments.length - 1)
val post_map = Map("url" -> url, "tags" -> tags, "md5" -> md5, "name" -> name)

posts_arr += post_map
} catch {
case e: MalformedURLException => println("couldn't download file")
}
}

posts_arr.toArray
}

def downloadFile(url: String, name: String): String = {
val directory = Paths.get(".").toAbsolutePath + "/img/"
if(!new File(directory).exists) {
new File(directory).mkdir
}
val filename = directory + name
new URL(url) #> new File(filename) !!;
filename
}
}

0 comments on commit 2d37f72

Please sign in to comment.