Попытка показа видео через proxy
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package kinosearch.core.warez;
|
package kinosearch.core.warez;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import kinosearch.core.browser.Browser;
|
import kinosearch.core.browser.Browser;
|
||||||
import kinosearch.core.Kino;
|
import kinosearch.core.Kino;
|
||||||
@@ -68,12 +70,30 @@ public class Onlinelife implements KinoWarez {
|
|||||||
JsonObject jsonObj = new Gson().fromJson(json, JsonObject.class);
|
JsonObject jsonObj = new Gson().fromJson(json, JsonObject.class);
|
||||||
|
|
||||||
if (jsonObj.has("file")) {
|
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")) {
|
} else if (jsonObj.has("pl")) {
|
||||||
browser.setEncoding("utf-8");
|
browser.setEncoding("utf-8");
|
||||||
return browser.get(jsonObj.get("pl").getAsString());
|
return replaceToProxy(browser.get(jsonObj.get("pl").getAsString()));
|
||||||
} else {
|
} else {
|
||||||
return "{}";
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
if (typeof(video_data.file) !== 'undefined') {
|
if (typeof(video_data.file) !== 'undefined') {
|
||||||
$('#player').attr('src', video_data.file);
|
$('#player').attr('src', '${basedir}'+video_data.file);
|
||||||
} else if (typeof(video_data.playlist) !== 'undefined') {
|
} else if (typeof(video_data.playlist) !== 'undefined') {
|
||||||
$('#pl-season').removeClass('hide');
|
$('#pl-season').removeClass('hide');
|
||||||
menu = $('#pl-season-menu');
|
menu = $('#pl-season-menu');
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
smenu.find('a').bind('click', function(){
|
smenu.find('a').bind('click', function(){
|
||||||
$('#dropdownSerial').html(this.text + ' <span class="caret"></span>');
|
$('#dropdownSerial').html(this.text + ' <span class="caret"></span>');
|
||||||
$('#player').attr('src', this.attributes['data-file'].value);
|
$('#player').attr('src', '${basedir}'+this.attributes['data-file'].value);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#pl-serial').removeClass('hide');
|
$('#pl-serial').removeClass('hide');
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
<servlet-class>kinosearch.webapp.servlets.PlayerServlet</servlet-class>
|
<servlet-class>kinosearch.webapp.servlets.PlayerServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>proxy</servlet-name>
|
||||||
|
<servlet-class>kinosearch.webapp.servlets.ProxyServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>index</servlet-name>
|
<servlet-name>index</servlet-name>
|
||||||
<url-pattern>/</url-pattern>
|
<url-pattern>/</url-pattern>
|
||||||
@@ -38,6 +43,11 @@
|
|||||||
<url-pattern>/onlinelife/*</url-pattern>
|
<url-pattern>/onlinelife/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>proxy</servlet-name>
|
||||||
|
<url-pattern>/proxy/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>default</servlet-name>
|
<servlet-name>default</servlet-name>
|
||||||
<url-pattern>/js/*</url-pattern>
|
<url-pattern>/js/*</url-pattern>
|
||||||
|
|||||||
Reference in New Issue
Block a user