Попытка показа видео через proxy
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package kinosearch.core.warez;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import kinosearch.core.browser.Browser;
|
||||
import kinosearch.core.Kino;
|
||||
@@ -68,12 +70,30 @@ public class Onlinelife implements KinoWarez {
|
||||
JsonObject jsonObj = new Gson().fromJson(json, JsonObject.class);
|
||||
|
||||
if (jsonObj.has("file")) {
|
||||
return "{\"file\":\"" + jsonObj.get("file").getAsString() + "\"}";
|
||||
String fileMp4 = jsonObj.get("file").getAsString().substring("http://".length());
|
||||
return "{\"file\":\"/proxy/onlinelife/" + fileMp4 + "\"}";
|
||||
} else if (jsonObj.has("pl")) {
|
||||
browser.setEncoding("utf-8");
|
||||
return browser.get(jsonObj.get("pl").getAsString());
|
||||
return replaceToProxy(browser.get(jsonObj.get("pl").getAsString()));
|
||||
} else {
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
private String replaceToProxy(String json) {
|
||||
JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
|
||||
JsonArray jsonArray = jsonObject.get("playlist").getAsJsonArray();
|
||||
|
||||
//jsonArray.get(0).getAsJsonObject().get("playlist").getAsJsonArray().get(0).getAsJsonObject().get("file").getAsString();
|
||||
|
||||
for (JsonElement elm1 : jsonArray) {
|
||||
JsonArray arr1 = elm1.getAsJsonObject().get("playlist").getAsJsonArray();
|
||||
for (JsonElement elm2 : arr1) {
|
||||
JsonObject obj1 = elm2.getAsJsonObject();
|
||||
obj1.addProperty("file", obj1.get("file").getAsString().replace("http://", "/proxy/onlinelife/"));
|
||||
}
|
||||
}
|
||||
|
||||
return new Gson().toJson(jsonObject);
|
||||
}
|
||||
}
|
||||
64
src/main/java/kinosearch/webapp/servlets/ProxyServlet.java
Normal file
64
src/main/java/kinosearch/webapp/servlets/ProxyServlet.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package kinosearch.webapp.servlets;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.Part;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by DmitriyMX <mail@dmitriymx.ru>
|
||||
* 2016
|
||||
*/
|
||||
public class ProxyServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String path = request.getPathInfo().substring("/onlinelife/".length());
|
||||
|
||||
URL url = new URL("http://" + path);
|
||||
HttpURLConnection con =(HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setDoOutput(true);
|
||||
con.setDoInput(true);
|
||||
con.setUseCaches(true);
|
||||
|
||||
for (Enumeration names = request.getHeaderNames(); names.hasMoreElements();) {
|
||||
String headerName = names.nextElement().toString();
|
||||
if (headerName.equalsIgnoreCase("referer")) continue;
|
||||
con.setRequestProperty(headerName, request.getHeader(headerName));
|
||||
}
|
||||
|
||||
con.connect();
|
||||
|
||||
int statusCode = con.getResponseCode();
|
||||
response.setStatus(statusCode);
|
||||
|
||||
for (Map.Entry<String, List<String>> stringListEntry : con.getHeaderFields().entrySet()) {
|
||||
Map.Entry mapEntry = (Map.Entry) stringListEntry;
|
||||
if (mapEntry.getKey() != null) {
|
||||
response.setHeader(mapEntry.getKey().toString(), ((List) mapEntry.getValue()).get(0).toString());
|
||||
}
|
||||
}
|
||||
|
||||
BufferedInputStream webToProxyBuf = new BufferedInputStream(con.getInputStream());
|
||||
BufferedOutputStream proxyToClientBuf = new BufferedOutputStream(response.getOutputStream());
|
||||
|
||||
int oneByte;
|
||||
while ((oneByte = webToProxyBuf.read()) != -1) {
|
||||
proxyToClientBuf.write(oneByte);
|
||||
}
|
||||
|
||||
proxyToClientBuf.flush();
|
||||
proxyToClientBuf.close();
|
||||
webToProxyBuf.close();
|
||||
con.disconnect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user