From 59e2390bfdc1160acd2c20f4644dd486adfb1370 Mon Sep 17 00:00:00 2001 From: raulhaag Date: Tue, 26 Sep 2017 16:59:34 -0300 Subject: [PATCH] fix tmo fix #441 fix #442 --- .../java/ar/rulosoft/mimanganu/testNine.java | 26 +++++++++++++++---- .../mimanganu/servers/TuMangaOnline.java | 19 +++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/src/androidTest/java/ar/rulosoft/mimanganu/testNine.java b/app/src/androidTest/java/ar/rulosoft/mimanganu/testNine.java index fa2364d2..574f3f18 100644 --- a/app/src/androidTest/java/ar/rulosoft/mimanganu/testNine.java +++ b/app/src/androidTest/java/ar/rulosoft/mimanganu/testNine.java @@ -47,7 +47,21 @@ public void testImages() throws Exception { Navigator nav = Navigator.navigator; nav.addHeader("Accept-Language", "es-AR,es;q=0.8,en-US;q=0.5,en;q=0.3"); nav.addHeader("Accept-Encoding", "deflate"); - String boundary = Navigator.getNewBoundary(); + nav.addHeader("Accept","application/json, text/plain, */*"); + nav.addHeader("Accept-Encoding","gzip, deflate, br"); + nav.addHeader("Accept-Language","es-AR,es;q=0.8,en-US;q=0.5,en;q=0.3"); + nav.addHeader("Cache-mode","no-cache"); + //nav.addHeader("Connection","keep-alive"); + nav.addHeader("Cookie","__cfduid=d7025d17b59e189d890c2cc05b9feb5c31505483555; tmoSession=eyJpdiI6ImZXZUlPZjVWOGNKS2VCRkVcL1I3XC9iZz09IiwidmFsdWUiOiJ0MEhzdXF0XC93YkFvSkJlUnVvZ3hnN011WWtGUzdEdnJrY1ZOakhnTVRBTGJQZk91NmphTTFaNDhhbUozUnZnRmJndGtBdkNHZlFsTTFZT2RvSWlBSGc9PSIsIm1hYyI6ImMxODZmYmRkNTJiZTQ4YjUwZGQ0MTBkYTRlOWExNmU1NjM3YWFkMTA2MGJjNGJhMzMwOGY3NjY0YmFhMDIyMmIifQ%3D%3D"); + //nav.addHeader("Host","www.tumangaonline.com"); + nav.addHeader("Referer","https://www.tumangaonline.com/biblioteca"); + //nav.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0"); + //nav.addHeader("X-Requested-With","XMLHttpRequest"); + Log.e("respuesta", nav.get("https://www.tumangaonline.com/api/v1/mangas/2968/capitulos?page=2&tomo=-1")); + + + +/* String boundary = Navigator.getNewBoundary(); nav.addHeader("Content-Type", "multipart/form-data; boundary=" + boundary); nav.addHeader("X-Requested-With", "XMLHttpRequest"); MultipartBody.Builder mBodyBuilder = new MultipartBody.Builder(boundary).setType(MultipartBody.FORM); @@ -68,18 +82,20 @@ public void testImages() throws Exception { for(int i = 0; i < 6; i++){ mBodyBuilder.addFormDataPart("typeBookID["+i+"]","0"); } -/* + Request request = new Request.Builder() .url("http://mangapedia.fr/project_code/script/search.php") .method("POST", mBodyBuilder.build()) .build(); - Log.e("Body", bodyToString(request));//*/ + Log.e("Body", bodyToString(request));// //RequestBody body = RequestBody - // .create(MediaType.parse("multipart/form-data; boundary"),mBodyBuilder.build()); + .create(MediaType.parse("multipart/form-data; boundary"),mBodyBuilder.build()); String data = nav.post("http://mangapedia.fr/project_code/script/search.php", mBodyBuilder.build()); - Log.e("Aaaaaaaaaaaa", data); + Log.e("Aaaaaaaaaaaa", data);/*/ + + } } diff --git a/app/src/main/java/ar/rulosoft/mimanganu/servers/TuMangaOnline.java b/app/src/main/java/ar/rulosoft/mimanganu/servers/TuMangaOnline.java index 6eef0c0f..d93a4ef0 100644 --- a/app/src/main/java/ar/rulosoft/mimanganu/servers/TuMangaOnline.java +++ b/app/src/main/java/ar/rulosoft/mimanganu/servers/TuMangaOnline.java @@ -15,6 +15,7 @@ import ar.rulosoft.mimanganu.componentes.Database; import ar.rulosoft.mimanganu.componentes.Manga; import ar.rulosoft.mimanganu.componentes.ServerFilter; +import ar.rulosoft.navegadores.Navigator; /** * Created by Raul on 05/04/2016. @@ -91,7 +92,7 @@ public ArrayList getMangas() throws Exception { @Override public ArrayList search(String term) throws Exception { - JSONObject jsonObject = new JSONObject(getNavigatorAndFlushParameters().get("http://www.tumangaonline.com/api/v1/mangas?categorias=%5B%5D&generos=%5B%5D&itemsPerPage=20&nameSearch=" + URLEncoder.encode(term, "UTF-8") + "&page=1&puntuacion=0&searchBy=nombre&sortDir=asc&sortedBy=nombre")); + JSONObject jsonObject = new JSONObject(getNavWithNeededHeaders().get("http://www.tumangaonline.com/api/v1/mangas?categorias=%5B%5D&generos=%5B%5D&itemsPerPage=20&nameSearch=" + URLEncoder.encode(term, "UTF-8") + "&page=1&puntuacion=0&searchBy=nombre&sortDir=asc&sortedBy=nombre")); return getMangasJsonArray(jsonObject.getJSONArray("data")); } @@ -102,7 +103,7 @@ public void loadChapters(Manga manga, boolean forceReload) throws Exception { public void loadChapters(Manga manga, boolean forceReload, boolean last) throws Exception { ArrayList result = new ArrayList<>(); - String data = getNavigatorAndFlushParameters().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath() + "/capitulos?page=" + 1 + "&tomo=-1"); + String data = getNavWithNeededHeaders().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath() + "/capitulos?page=" + 1 + "&tomo=-1"); if (data != null && data.length() > 3) { JSONObject object = new JSONObject(data); int last_page = object.getInt("last_page"); @@ -110,7 +111,7 @@ public void loadChapters(Manga manga, boolean forceReload, boolean last) throws if (!last) for (int i = 2; i <= last_page; i++) { try { - data = getNavigatorAndFlushParameters().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath() + "/capitulos?page=" + i + "&tomo=-1"); + data = getNavWithNeededHeaders().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath() + "/capitulos?page=" + i + "&tomo=-1"); if (data != null && data.length() > 3) { object = new JSONObject(data); result.addAll(0, getChaptersJsonArray(object.getJSONArray("data"), manga.getPath())); @@ -141,7 +142,7 @@ private ArrayList getChaptersJsonArray(JSONArray jsonArray, String mid) @Override public void loadMangaInformation(Manga manga, boolean forceReload) throws Exception { - JSONObject object = new JSONObject(getNavigatorAndFlushParameters().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath())); + JSONObject object = new JSONObject(getNavWithNeededHeaders().get("http://www.tumangaonline.com/api/v1/mangas/" + manga.getPath())); manga.setImages("http://img1.tumangaonline.com/" + object.getString("imageUrl")); manga.setSynopsis(object.getJSONObject("info").getString("sinopsis")); if (object.getJSONArray("autores").length() != 0) { @@ -310,12 +311,18 @@ public ArrayList getMangasFiltered(int[][] filters, int pageNumber) throw estadoV[filters[3][0]] + "&generos=%5B" + gens + "%5D&itemsPerPage=20&page=" + pageNumber + "&puntuacion=0&searchBy=nombre" + sortByValues[filters[5][0]] + "&tipo=" + typeV[filters[0][0]]; - - JSONObject jsonObject = new JSONObject(getNavigatorAndFlushParameters().get(web)); + JSONObject jsonObject = new JSONObject(getNavWithNeededHeaders().get(web)); lastPage = jsonObject.getInt("last_page"); return getMangasJsonArray(jsonObject.getJSONArray("data")); } else { return new ArrayList<>(); } } + + private Navigator getNavWithNeededHeaders() { + Navigator nav = getNavigatorAndFlushParameters(); + nav.addHeader("Cache-mode","no-cache"); + nav.addHeader("Referer","https://www.tumangaonline.com/biblioteca"); + return nav; + } }