Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
fix japscan, mangafox and mangahere. fix old concept on details fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
raulhaag committed Jan 27, 2019
1 parent 84ba85b commit 84c1568
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 366 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/ar/rulosoft/mimanganu/DetailsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ public void run() {
try {
List<Manga> mangas = Database.getMangas(getContext(), null, true);
for (Manga m : mangas) {
if (m.getPath().equals(manga.getPath())) {
if (m.getPath().equals(manga.getPath()) && (m.getServerId() == manga.getServerId())) {
mangaAlreadyAdded = true;
if (floatingActionButton_add != null)
floatingActionButton_add.hide();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
floatingActionButton_add.hide();
}
});
}
}
} catch (Exception e) {
Expand All @@ -92,13 +97,13 @@ public void run() {
});
t0.start();

data = (ControlInfo) getView().findViewById(R.id.datos);
swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.str);
data = getView().findViewById(R.id.datos);
swipeRefreshLayout = getView().findViewById(R.id.str);
ActionBar mActBar = getActivity().getActionBar();
if (mActBar != null) {
mActBar.setDisplayHomeAsUpEnabled(true);
}
floatingActionButton_add = (FloatingActionButton) getView().findViewById(R.id.floatingActionButton_add);
floatingActionButton_add = getView().findViewById(R.id.floatingActionButton_add);
floatingActionButton_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
88 changes: 88 additions & 0 deletions app/src/main/java/ar/rulosoft/mimanganu/servers/FanFoxNet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package ar.rulosoft.mimanganu.servers;

import android.content.Context;

import ar.rulosoft.mimanganu.R;

public class FanFoxNet extends MTownBase {

public static final String HOST = "https://fanfox.net";
private static final int[] fltGenre = {
R.string.flt_tag_action,
R.string.flt_tag_adventure,
R.string.flt_tag_comedy,
R.string.flt_tag_drama,
R.string.flt_tag_fantasy,
R.string.flt_tag_martial_arts,
R.string.flt_tag_shounen,
R.string.flt_tag_horror,
R.string.flt_tag_supernatural,
R.string.flt_tag_harem,
R.string.flt_tag_psychological,
R.string.flt_tag_romance,
R.string.flt_tag_school_life,
R.string.flt_tag_shoujo,
R.string.flt_tag_mystery,
R.string.flt_tag_sci_fi,
R.string.flt_tag_seinen,
R.string.flt_tag_tragedy,
R.string.flt_tag_ecchi,
R.string.flt_tag_sports,
R.string.flt_tag_slice_of_life,
R.string.flt_tag_mature,
R.string.flt_tag_shoujo_ai,
R.string.flt_tag_webtoon,
R.string.flt_tag_doujinshi,
R.string.flt_tag_one_shot,
R.string.flt_tag_smut,
R.string.flt_tag_yaoi,
R.string.flt_tag_josei,
R.string.flt_tag_historical,
R.string.flt_tag_shounen_ai,
R.string.flt_tag_gender_bender,
R.string.flt_tag_adult,
R.string.flt_tag_yuri,
R.string.flt_tag_mecha
};

private static boolean cookieInit = false;

/**
* Construct a new ServerBase object.
*
* @param context the context for this object
*/
FanFoxNet(Context context) {
super(context);
setFlag(R.drawable.flag_en);
setIcon(R.drawable.mangafox_icon);
setServerName("FanFox");
setServerID(FANFOXNET);
}

@Override
public String getHost() {
return "https://fanfox.net";
}

@Override
public String getDomain() {
return "fanfox.net";
}

@Override
public int[] getFilter() {
return fltGenre;
}

@Override
public boolean getCookieInit() {
return cookieInit;
}

@Override
public void setCookieInit(boolean state) {
cookieInit = state;
}

}
10 changes: 7 additions & 3 deletions app/src/main/java/ar/rulosoft/mimanganu/servers/JapScan.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ar.rulosoft.mimanganu.servers;

import android.content.Context;
import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -95,9 +96,8 @@ public void loadMangaInformation(Manga manga, boolean forceReload) throws Except

@Override
public String getImageFrom(Chapter chapter, int page) throws Exception {
String source = getNavigatorAndFlushParameters().get(HOST + chapter.getPath() + page + ".html");

return getFirstMatch("data-src=\"([^\"]+)", source, context.getString(R.string.error_downloading_image));
String[] parts = chapter.getExtra().split("\\|");
return parts[0] + parts[page];
}

@Override
Expand All @@ -106,6 +106,10 @@ public void chapterInit(Chapter chapter) throws Exception {
String source = getNavigatorAndFlushParameters().get(HOST + chapter.getPath());
String pages = getFirstMatch("Page (\\d+)</option>\\s*</select>", source,
context.getString(R.string.server_failed_loading_image));
String path = getFirstMatch("data-src=\"([^\"]+)", source, context.getString(R.string.error_downloading_image));
path = path.substring(0, path.lastIndexOf("/") + 1);
ArrayList<String> imgs = getAllMatch("<option[^<]+?data-img=\"([^\"]+)\"", source);
chapter.setExtra(path + "|" + TextUtils.join("|", imgs));
chapter.setPages(Integer.parseInt(pages));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,8 @@
import okhttp3.Cookie;
import okhttp3.HttpUrl;

public class FanfoxNet extends ServerBase {

public static final String HOST = "https://fanfox.net";
private static final int[] fltGenre = {
R.string.flt_tag_action,
R.string.flt_tag_adventure,
R.string.flt_tag_comedy,
R.string.flt_tag_drama,
R.string.flt_tag_fantasy,
R.string.flt_tag_martial_arts,
R.string.flt_tag_shounen,
R.string.flt_tag_horror,
R.string.flt_tag_supernatural,
R.string.flt_tag_harem,
R.string.flt_tag_psychological,
R.string.flt_tag_romance,
R.string.flt_tag_school_life,
R.string.flt_tag_shoujo,
R.string.flt_tag_mystery,
R.string.flt_tag_sci_fi,
R.string.flt_tag_seinen,
R.string.flt_tag_tragedy,
R.string.flt_tag_ecchi,
R.string.flt_tag_sports,
R.string.flt_tag_slice_of_life,
R.string.flt_tag_mature,
R.string.flt_tag_shoujo_ai,
R.string.flt_tag_webtoon,
R.string.flt_tag_doujinshi,
R.string.flt_tag_one_shot,
R.string.flt_tag_smut,
R.string.flt_tag_yaoi,
R.string.flt_tag_josei,
R.string.flt_tag_historical,
R.string.flt_tag_shounen_ai,
R.string.flt_tag_gender_bender,
R.string.flt_tag_adult,
R.string.flt_tag_yuri,
R.string.flt_tag_mecha
};
public abstract class MTownBase extends ServerBase {

private static final int[] fltOrder = {
R.string.flt_order_alpha,
R.string.flt_order_views,
Expand All @@ -68,32 +30,37 @@ public class FanfoxNet extends ServerBase {
R.string.flt_status_ongoing,
R.string.flt_status_completed
};
private static boolean cookieInit = false;

/**
* Construct a new ServerBase object.
*
* @param context the context for this object
*/
FanfoxNet(Context context) {
public MTownBase(Context context) {
super(context);
setFlag(R.drawable.flag_en);
setIcon(R.drawable.mangafox_icon);
setServerName("FanFox");
setServerID(FANFOXNET);
}

private static void generateNeededCookie() {
HttpUrl url = HttpUrl.parse(HOST);
public abstract String getHost();

public abstract String getDomain();

public abstract int[] getFilter();

public abstract boolean getCookieInit();

public abstract void setCookieInit(boolean state);

private void generateNeededCookie() {
HttpUrl url = HttpUrl.parse(getHost());
Navigator.getCookieJar().saveFromResponse(url, Arrays.asList(
Cookie.parse(url, "isAdult=1; Domain=fanfox.net"))
Cookie.parse(url, "isAdult=1; Domain=" + getDomain()))
);
cookieInit = true;
setCookieInit(true);
}

@Override
public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throws Exception {
StringBuilder web = new StringBuilder(HOST);
StringBuilder web = new StringBuilder(getHost());
web.append("/search?title=&genres=");
for (int i : filters[0]) {
web.append((i + 1));
Expand Down Expand Up @@ -122,7 +89,7 @@ ArrayList<Manga> getMangasFromSource(String source) {
@Override
public ArrayList<Manga> search(String term) throws Exception {
return getMangasFromSource(getNavigatorWithNeededHeader()
.get("https://fanfox.net/search?title=&genres=&st=0&sort=&stype=1&name_method=cw&name=" +
.get(getHost() + "/search?title=&genres=&st=0&sort=&stype=1&name_method=cw&name=" +
URLEncoder.encode(term, "UTF-8") +
"&author_method=cw&author=&artist_method=cw&artist=&type=&rating_method=eq&rating=&released_method=eq&released="));
}
Expand All @@ -134,7 +101,7 @@ public void loadChapters(Manga manga, boolean forceReload) throws Exception {

@Override
public void loadMangaInformation(Manga manga, boolean forceReload) throws Exception {
String data = getNavigatorWithNeededHeader().get(HOST + manga.getPath());
String data = getNavigatorWithNeededHeader().get(getHost() + manga.getPath());
manga.setImages(getFirstMatchDefault("over-img\" src=\"([^\"]+)", data, ""));
manga.setAuthor(getFirstMatchDefault("say\">Author:(.+)</p>", data, context.getString(R.string.nodisponible)));
manga.setGenre(getFirstMatchDefault("tag-list\">(.+?)</p>", data, context.getString(R.string.nodisponible)));
Expand All @@ -153,11 +120,13 @@ public String getImageFrom(Chapter chapter, int page) throws Exception {
String[] vars = chapter.getExtra().split("\\|");
if (vars[0].equals("1")) {
Navigator nav = getNavigatorWithNeededHeader();
nav.addHeader("Referer", HOST + chapter.getPath());
String data = nav.get(vars[2] + "chapterfun.ashx?cid=" + vars[1] + "&page=" + page + "&key=" + (page != 1 ? vars[3] : ""));
nav.addHeader("Referer", getHost() + chapter.getPath());
String data = nav.get(vars[2] + "/chapterfun.ashx?cid=" + vars[1] + "&page=" + page + "&key=" + (page != 1 ? vars[3] : ""));
data = Util.getInstance().unpack(data);
String dir = getFirstMatch("\"([^\"]+)\";", data, "Error getting image(0)");
String image = getFirstMatch("\\[\"([^\"]+)\"", data, "Error getting image(1)");
if (!dir.startsWith("http"))
dir = "https:" + dir;
return dir + image;
} else {
return "https:" + vars[page];
Expand All @@ -166,7 +135,7 @@ public String getImageFrom(Chapter chapter, int page) throws Exception {

@Override
public void chapterInit(Chapter chapter) throws Exception {
String web = HOST + chapter.getPath();
String web = getHost() + chapter.getPath();
String data = getNavigatorWithNeededHeader().get(web);
int pages = Integer.parseInt(getLastMatchDefault("data-page=\"(\\d+)\">(\\d+)", data, "-1"));
if (pages != -1) {
Expand Down Expand Up @@ -198,7 +167,7 @@ public ServerFilter[] getServerFilters() {
return new ServerFilter[]{
new ServerFilter(
context.getString(R.string.flt_include_tags),
buildTranslatedStringArray(fltGenre), ServerFilter.FilterType.MULTI),
buildTranslatedStringArray(getFilter()), ServerFilter.FilterType.MULTI),
new ServerFilter(
context.getString(R.string.flt_status),
buildTranslatedStringArray(fltStatus), ServerFilter.FilterType.SINGLE),
Expand All @@ -209,10 +178,11 @@ public ServerFilter[] getServerFilters() {
}

private Navigator getNavigatorWithNeededHeader() {
if (!cookieInit) {
if (!getCookieInit()) {
generateNeededCookie();
}
Navigator nav = getNavigatorAndFlushParameters();
return nav;
}

}
Loading

0 comments on commit 84c1568

Please sign in to comment.