From 524f699684399a02fbd2229043e89b11adc0f088 Mon Sep 17 00:00:00 2001 From: Ruslan Molchanov Date: Fri, 8 Dec 2017 01:55:39 +0300 Subject: [PATCH] Close #20 --- build.gradle | 4 +- .../component/impl/ScraperVkClient.java | 33 +++++--- src/main/resources/decrypt.js | 79 +++++++------------ 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/build.gradle b/build.gradle index 66db05e..c6ee0aa 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'me.ruslanys' -version = '2.1.1' +version = '2.1.2' sourceCompatibility = JavaVersion.VERSION_1_8 repositories { @@ -30,8 +30,8 @@ dependencies { compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") // Utils - compile('commons-cli:commons-cli:1.3.1') compile('commons-codec:commons-codec:1.10') + compile('org.apache.commons:commons-text:1.1') compile('org.apache.commons:commons-lang3:3.6') compile('com.google.guava:guava:23.0') compile('org.jsoup:jsoup:1.10.3') diff --git a/src/main/java/me/ruslanys/vkmusic/component/impl/ScraperVkClient.java b/src/main/java/me/ruslanys/vkmusic/component/impl/ScraperVkClient.java index 7286111..7e2721e 100644 --- a/src/main/java/me/ruslanys/vkmusic/component/impl/ScraperVkClient.java +++ b/src/main/java/me/ruslanys/vkmusic/component/impl/ScraperVkClient.java @@ -7,8 +7,8 @@ import me.ruslanys.vkmusic.entity.Audio; import me.ruslanys.vkmusic.exception.VkException; import me.ruslanys.vkmusic.util.JsonUtils; -import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.text.StringEscapeUtils; import org.jsoup.Connection; import org.jsoup.Jsoup; import org.springframework.stereotype.Component; @@ -17,6 +17,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; @@ -42,8 +43,22 @@ public class ScraperVkClient implements VkClient { private static final int SLEEP_INTERVAL = 5_000; private final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript"); + private final String script; + private final Map cookies = new HashMap<>(); + + public ScraperVkClient() throws IOException { + StringBuilder sb = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("decrypt.js")))) { + String line; + while ((line = reader.readLine()) != null) { + sb.append(line).append(System.lineSeparator()); + } + } + script = sb.toString(); + } + @Override public void addCookies(Map cookies) { this.cookies.putAll(cookies); @@ -121,12 +136,13 @@ public List