Merge branch 'dev' into dev-ksplayer
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
package kinosearch.core.browser;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleBrowser implements Browser {
|
||||
private Map<String, String> headers = new HashMap<>();
|
||||
private String encoding = "UTF-8";
|
||||
|
||||
@Override
|
||||
public Browser setHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String url) {
|
||||
String result = "";
|
||||
try {
|
||||
HttpURLConnection connection = create_connection(url);
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
if (connection.getResponseCode() != 200) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = readOutput(connection.getInputStream());
|
||||
connection.disconnect();
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(String url, String data) {
|
||||
String result = "";
|
||||
try {
|
||||
HttpURLConnection connection = create_connection(url);
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Length", String.valueOf(data.length()));
|
||||
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
||||
dos.writeBytes(data);
|
||||
dos.flush();
|
||||
dos.close();
|
||||
|
||||
if (connection.getResponseCode() != 200) {
|
||||
return "";
|
||||
}
|
||||
|
||||
result = readOutput(connection.getInputStream());
|
||||
connection.disconnect();
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
private HttpURLConnection create_connection(String strUrl) throws IOException {
|
||||
URL url = new URL(strUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setUseCaches(false); //TODO а надо ли?
|
||||
|
||||
connection.setRequestProperty("Connection", "close");
|
||||
connection.setRequestProperty("Accept-Encoding", "deflate");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36");
|
||||
|
||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||
connection.setRequestProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
private String readOutput(InputStream in) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str;
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in, encoding));
|
||||
while ((str = br.readLine()) != null) {
|
||||
sb.append(str).append('\n');
|
||||
}
|
||||
br.close();
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -118,10 +118,13 @@ public class Onlinelife implements KinoWarez {
|
||||
Map<String, List<KinoItem>> seasons = new LinkedHashMap<>();
|
||||
for (JsonElement element : jsonArray) {
|
||||
jsonObj = element.getAsJsonObject();
|
||||
String titleSeason = jsonObj.get("comment").getAsString();
|
||||
|
||||
ArrayList<KinoItem> serials = new ArrayList<>();
|
||||
JsonArray jsonSerials = jsonObj.get("playlist").getAsJsonArray();
|
||||
if (jsonSerials.size() > 0) {
|
||||
if (jsonSerials.get(0).getAsJsonObject().has("file")) {
|
||||
String titleSeason = jsonObj.get("comment").getAsString();
|
||||
ArrayList<KinoItem> serials = new ArrayList<>();
|
||||
|
||||
for (JsonElement elm1 : jsonSerials) {
|
||||
jsonObj = elm1.getAsJsonObject();
|
||||
serials.add(new KinoItem(
|
||||
@@ -132,6 +135,28 @@ public class Onlinelife implements KinoWarez {
|
||||
|
||||
serials.sort(Comparator.comparing(KinoItem::getTitle));
|
||||
seasons.put(titleSeason, serials);
|
||||
} else {
|
||||
// мультиозвучка
|
||||
for (JsonElement elm1 : jsonSerials) {
|
||||
jsonObj = elm1.getAsJsonObject();
|
||||
JsonArray jsonSerials2 = jsonObj.get("playlist").getAsJsonArray();
|
||||
|
||||
String titleSeason = jsonObj.get("comment").getAsString();
|
||||
ArrayList<KinoItem> serials = new ArrayList<>();
|
||||
|
||||
for (JsonElement elm2 : jsonSerials2) {
|
||||
jsonObj = elm2.getAsJsonObject();
|
||||
serials.add(new KinoItem(
|
||||
jsonObj.get("comment").getAsString(),
|
||||
jsonObj.get("file").getAsString().replace("http://", "/proxy/onlinelife/")
|
||||
));
|
||||
}
|
||||
|
||||
serials.sort(Comparator.comparing(KinoItem::getTitle));
|
||||
seasons.put(titleSeason, serials);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kinoPlay.setSeasons(seasons);
|
||||
|
||||
@@ -48,5 +48,6 @@ public class TestOnlinelife extends KinoWarezTestCase {
|
||||
@Override
|
||||
public void testFoundSeasonSerial() {
|
||||
seasonsSerial("/915-doktor-kto.html", kinoWarez);
|
||||
seasonsSerial("/11127-moya-geroyskaya-akademiya-2016.html", kinoWarez);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user