2015-10-05 18:24:29 -04:00
|
|
|
package eu.kanade.mangafeed.sources;
|
|
|
|
|
|
|
|
import com.squareup.okhttp.Headers;
|
|
|
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
2015-10-06 13:44:30 -04:00
|
|
|
import java.text.ParseException;
|
|
|
|
import java.text.SimpleDateFormat;
|
2015-10-05 18:24:29 -04:00
|
|
|
import java.util.ArrayList;
|
2015-10-06 13:44:30 -04:00
|
|
|
import java.util.Date;
|
2015-10-05 18:24:29 -04:00
|
|
|
import java.util.List;
|
2015-10-06 13:44:30 -04:00
|
|
|
import java.util.Locale;
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
import eu.kanade.mangafeed.data.caches.CacheManager;
|
|
|
|
import eu.kanade.mangafeed.data.helpers.NetworkHelper;
|
2015-10-08 07:15:29 -04:00
|
|
|
import eu.kanade.mangafeed.data.helpers.SourceManager;
|
2015-10-06 13:44:30 -04:00
|
|
|
import eu.kanade.mangafeed.data.models.Chapter;
|
|
|
|
import eu.kanade.mangafeed.data.models.Manga;
|
2015-10-26 09:04:03 -04:00
|
|
|
import eu.kanade.mangafeed.sources.base.Source;
|
2015-10-05 18:24:29 -04:00
|
|
|
import rx.Observable;
|
|
|
|
|
2015-10-08 07:15:29 -04:00
|
|
|
public class Batoto extends Source {
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
public static final String NAME = "Batoto (EN)";
|
|
|
|
public static final String BASE_URL = "www.bato.to";
|
2015-10-09 16:08:36 -04:00
|
|
|
public static final String INITIAL_UPDATE_URL =
|
|
|
|
"http://bato.to/search_ajax?order_cond=views&order=desc&p=";
|
2015-10-12 17:17:37 -04:00
|
|
|
public static final String INITIAL_SEARCH_URL = "http://bato.to/search_ajax?";
|
2015-10-24 18:08:15 -04:00
|
|
|
public static final String INITIAL_PAGE_URL = "http://bato.to/areader?";
|
2015-10-12 17:17:37 -04:00
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
public Batoto(NetworkHelper networkService, CacheManager cacheManager) {
|
2015-10-09 16:08:36 -04:00
|
|
|
super(networkService, cacheManager);
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-10 08:28:57 -04:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected Headers.Builder headersBuilder() {
|
|
|
|
Headers.Builder builder = super.headersBuilder();
|
|
|
|
builder.add("Cookie", "lang_option=English");
|
2015-10-24 18:08:15 -04:00
|
|
|
builder.add("Referer", "http://bato.to/reader");
|
2015-10-09 16:08:36 -04:00
|
|
|
return builder;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public Observable<List<String>> getGenres() {
|
2015-10-09 16:08:36 -04:00
|
|
|
List<String> genres = new ArrayList<>(38);
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
genres.add("4-Koma");
|
|
|
|
genres.add("Action");
|
|
|
|
genres.add("Adventure");
|
|
|
|
genres.add("Award Winning");
|
|
|
|
genres.add("Comedy");
|
|
|
|
genres.add("Cooking");
|
|
|
|
genres.add("Doujinshi");
|
|
|
|
genres.add("Drama");
|
|
|
|
genres.add("Ecchi");
|
|
|
|
genres.add("Fantasy");
|
|
|
|
genres.add("Gender Bender");
|
|
|
|
genres.add("Harem");
|
|
|
|
genres.add("Historical");
|
|
|
|
genres.add("Horror");
|
|
|
|
genres.add("Josei");
|
|
|
|
genres.add("Martial Arts");
|
|
|
|
genres.add("Mecha");
|
|
|
|
genres.add("Medical");
|
|
|
|
genres.add("Music");
|
|
|
|
genres.add("Mystery");
|
|
|
|
genres.add("One Shot");
|
|
|
|
genres.add("Psychological");
|
|
|
|
genres.add("Romance");
|
|
|
|
genres.add("School Life");
|
|
|
|
genres.add("Sci-fi");
|
|
|
|
genres.add("Seinen");
|
|
|
|
genres.add("Shoujo");
|
|
|
|
genres.add("Shoujo Ai");
|
|
|
|
genres.add("Shounen");
|
|
|
|
genres.add("Shounen Ai");
|
|
|
|
genres.add("Slice of Life");
|
|
|
|
genres.add("Smut");
|
|
|
|
genres.add("Sports");
|
|
|
|
genres.add("Supernatural");
|
|
|
|
genres.add("Tragedy");
|
|
|
|
genres.add("Webtoon");
|
|
|
|
genres.add("Yaoi");
|
|
|
|
genres.add("Yuri");
|
|
|
|
|
|
|
|
return Observable.just(genres);
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
2015-10-17 10:28:35 -04:00
|
|
|
public int getSourceId() {
|
2015-10-09 16:08:36 -04:00
|
|
|
return SourceManager.BATOTO;
|
|
|
|
}
|
2015-10-08 07:15:29 -04:00
|
|
|
|
2015-10-25 20:41:10 -04:00
|
|
|
@Override
|
|
|
|
public boolean isLoginRequired() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected String getUrlFromPageNumber(int page) {
|
|
|
|
return INITIAL_UPDATE_URL + page;
|
2015-10-08 07:15:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-12 17:17:37 -04:00
|
|
|
@Override
|
|
|
|
protected String getSearchUrl(String query, int page) {
|
|
|
|
return INITIAL_SEARCH_URL + "name=" + query + "&p=" + page;
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
2015-10-26 09:04:03 -04:00
|
|
|
protected String overrideMangaUrl(String defaultMangaUrl) {
|
2015-10-09 16:08:36 -04:00
|
|
|
String mangaId = defaultMangaUrl.substring(defaultMangaUrl.lastIndexOf("r") + 1);
|
|
|
|
return "http://bato.to/comic_pop?id=" + mangaId;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-24 18:08:15 -04:00
|
|
|
@Override
|
2015-10-26 09:04:03 -04:00
|
|
|
protected String overrideChapterPageUrl(String defaultPageUrl) {
|
2015-10-24 18:08:15 -04:00
|
|
|
String id = defaultPageUrl.substring(defaultPageUrl.indexOf("#") + 1);
|
|
|
|
return INITIAL_PAGE_URL + "id=" + id + "&p=1";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-26 09:04:03 -04:00
|
|
|
protected String overrideRemainingPagesUrl(String defaultPageUrl) {
|
2015-10-24 18:08:15 -04:00
|
|
|
int start = defaultPageUrl.indexOf("#") + 1;
|
|
|
|
int end = defaultPageUrl.indexOf("_", start);
|
|
|
|
String id = defaultPageUrl.substring(start, end);
|
|
|
|
return INITIAL_PAGE_URL + "id=" + id + "&p=" + defaultPageUrl.substring(end+1);
|
|
|
|
}
|
|
|
|
|
2015-10-12 17:17:37 -04:00
|
|
|
private List<Manga> parseMangasFromHtml(String unparsedHtml) {
|
2015-10-12 17:53:27 -04:00
|
|
|
if (unparsedHtml.contains("No (more) comics found!")) {
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
|
|
|
|
2015-10-08 07:15:29 -04:00
|
|
|
List<Manga> updatedMangaList = new ArrayList<>();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
Elements updatedHtmlBlocks = parsedDocument.select("tr:not([id]):not([class])");
|
|
|
|
for (Element currentHtmlBlock : updatedHtmlBlocks) {
|
|
|
|
Manga currentlyUpdatedManga = constructMangaFromHtmlBlock(currentHtmlBlock);
|
|
|
|
|
|
|
|
updatedMangaList.add(currentlyUpdatedManga);
|
|
|
|
}
|
|
|
|
|
|
|
|
return updatedMangaList;
|
|
|
|
}
|
|
|
|
|
2015-10-12 17:17:37 -04:00
|
|
|
@Override
|
|
|
|
public List<Manga> parsePopularMangasFromHtml(String unparsedHtml) {
|
|
|
|
return parseMangasFromHtml(unparsedHtml);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Manga> parseSearchFromHtml(String unparsedHtml) {
|
|
|
|
return parseMangasFromHtml(unparsedHtml);
|
|
|
|
}
|
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
private Manga constructMangaFromHtmlBlock(Element htmlBlock) {
|
2015-10-08 07:15:29 -04:00
|
|
|
Manga mangaFromHtmlBlock = new Manga();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
Element urlElement = htmlBlock.select("a[href^=http://bato.to]").first();
|
|
|
|
Element nameElement = urlElement;
|
|
|
|
Element updateElement = htmlBlock.select("td").get(5);
|
|
|
|
|
2015-10-17 10:28:35 -04:00
|
|
|
mangaFromHtmlBlock.source = getSourceId();
|
2015-10-08 07:15:29 -04:00
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
if (urlElement != null) {
|
|
|
|
String fieldUrl = urlElement.attr("href");
|
2015-10-08 07:15:29 -04:00
|
|
|
mangaFromHtmlBlock.url = fieldUrl;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (nameElement != null) {
|
|
|
|
String fieldName = nameElement.text().trim();
|
2015-10-08 07:15:29 -04:00
|
|
|
mangaFromHtmlBlock.title = fieldName;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (updateElement != null) {
|
|
|
|
long fieldUpdate = parseUpdateFromElement(updateElement);
|
2015-10-08 07:15:29 -04:00
|
|
|
mangaFromHtmlBlock.last_update = fieldUpdate;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return mangaFromHtmlBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
private long parseUpdateFromElement(Element updateElement) {
|
|
|
|
String updatedDateAsString = updateElement.text();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Date specificDate = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(updatedDateAsString);
|
|
|
|
|
|
|
|
return specificDate.getTime();
|
|
|
|
} catch (ParseException e) {
|
|
|
|
// Do Nothing.
|
|
|
|
}
|
|
|
|
|
2015-10-08 07:15:29 -04:00
|
|
|
return 0;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml) {
|
2015-10-05 18:24:29 -04:00
|
|
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
|
|
|
|
2015-10-09 10:05:13 -04:00
|
|
|
Elements artistElements = parsedDocument.select("a[href^=http://bato.to/search?artist_name]");
|
2015-10-05 18:24:29 -04:00
|
|
|
Element descriptionElement = parsedDocument.select("tr").get(5);
|
|
|
|
Elements genreElements = parsedDocument.select("img[src=http://bato.to/forums/public/style_images/master/bullet_black.png]");
|
2015-10-13 10:47:27 -04:00
|
|
|
Element thumbnailUrlElement = parsedDocument.select("img[src^=http://img.bato.to/forums/uploads/]").first();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
2015-10-09 10:05:13 -04:00
|
|
|
Manga newManga = new Manga();
|
|
|
|
newManga.url = mangaUrl;
|
|
|
|
|
|
|
|
if (artistElements != null) {
|
|
|
|
newManga.author = artistElements.get(0).text();
|
|
|
|
if (artistElements.size() > 1) {
|
|
|
|
newManga.artist = artistElements.get(1).text();
|
|
|
|
} else {
|
|
|
|
newManga.artist = newManga.author;
|
|
|
|
}
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (descriptionElement != null) {
|
|
|
|
String fieldDescription = descriptionElement.text().substring("Description:".length()).trim();
|
2015-10-09 10:05:13 -04:00
|
|
|
newManga.description = fieldDescription;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (genreElements != null) {
|
|
|
|
String fieldGenres = "";
|
|
|
|
for (int index = 0; index < genreElements.size(); index++) {
|
|
|
|
String currentGenre = genreElements.get(index).attr("alt");
|
|
|
|
|
|
|
|
if (index < genreElements.size() - 1) {
|
|
|
|
fieldGenres += currentGenre + ", ";
|
|
|
|
} else {
|
|
|
|
fieldGenres += currentGenre;
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 10:05:13 -04:00
|
|
|
newManga.genre = fieldGenres;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (thumbnailUrlElement != null) {
|
|
|
|
String fieldThumbnailUrl = thumbnailUrlElement.attr("src");
|
2015-10-09 10:05:13 -04:00
|
|
|
newManga.thumbnail_url = fieldThumbnailUrl;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean fieldCompleted = unparsedHtml.contains("<td>Complete</td>");
|
2015-10-09 10:05:13 -04:00
|
|
|
//TODO fix
|
|
|
|
newManga.status = fieldCompleted + "";
|
2015-10-05 18:24:29 -04:00
|
|
|
|
2015-10-09 10:05:13 -04:00
|
|
|
newManga.initialized = true;
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
return newManga;
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected List<Chapter> parseHtmlToChapters(String unparsedHtml) {
|
2015-10-05 18:24:29 -04:00
|
|
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
|
|
|
|
2015-10-09 10:05:13 -04:00
|
|
|
List<Chapter> chapterList = new ArrayList<>();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
Elements chapterElements = parsedDocument.select("tr.row.lang_English.chapter_row");
|
|
|
|
for (Element chapterElement : chapterElements) {
|
|
|
|
Chapter currentChapter = constructChapterFromHtmlBlock(chapterElement);
|
|
|
|
chapterList.add(currentChapter);
|
|
|
|
}
|
|
|
|
|
2015-10-06 13:44:30 -04:00
|
|
|
//saveChaptersToDatabase(chapterList, mangaUrl);
|
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
return chapterList;
|
2015-10-06 13:44:30 -04:00
|
|
|
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private Chapter constructChapterFromHtmlBlock(Element chapterElement) {
|
2015-10-06 13:44:30 -04:00
|
|
|
Chapter newChapter = Chapter.newChapter();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
2015-10-24 16:47:34 -04:00
|
|
|
Element urlElement = chapterElement.select("a[href^=http://bato.to/reader").first();
|
2015-10-05 18:24:29 -04:00
|
|
|
Element nameElement = urlElement;
|
|
|
|
Element dateElement = chapterElement.select("td").get(4);
|
|
|
|
|
|
|
|
if (urlElement != null) {
|
|
|
|
String fieldUrl = urlElement.attr("href");
|
2015-10-06 13:44:30 -04:00
|
|
|
newChapter.url = fieldUrl;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (nameElement != null) {
|
|
|
|
String fieldName = nameElement.text().trim();
|
2015-10-06 13:44:30 -04:00
|
|
|
newChapter.name = fieldName;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
if (dateElement != null) {
|
|
|
|
long fieldDate = parseDateFromElement(dateElement);
|
2015-10-06 13:44:30 -04:00
|
|
|
newChapter.date_upload = fieldDate;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
2015-10-06 13:44:30 -04:00
|
|
|
newChapter.date_fetch = new Date().getTime();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
return newChapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
private long parseDateFromElement(Element dateElement) {
|
|
|
|
String dateAsString = dateElement.text();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Date specificDate = new SimpleDateFormat("dd MMMMM yyyy - hh:mm a", Locale.ENGLISH).parse(dateAsString);
|
|
|
|
|
|
|
|
return specificDate.getTime();
|
|
|
|
} catch (ParseException e) {
|
|
|
|
// Do Nothing.
|
|
|
|
}
|
|
|
|
|
2015-10-06 13:44:30 -04:00
|
|
|
return 0;
|
2015-10-05 18:24:29 -04:00
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected List<String> parseHtmlToPageUrls(String unparsedHtml) {
|
2015-10-05 18:24:29 -04:00
|
|
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
List<String> pageUrlList = new ArrayList<>();
|
2015-10-05 18:24:29 -04:00
|
|
|
|
|
|
|
Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option");
|
|
|
|
for (Element pageUrlElement : pageUrlElements) {
|
|
|
|
pageUrlList.add(pageUrlElement.attr("value"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return pageUrlList;
|
|
|
|
}
|
|
|
|
|
2015-10-09 16:08:36 -04:00
|
|
|
@Override
|
|
|
|
protected String parseHtmlToImageUrl(String unparsedHtml) {
|
2015-10-05 18:24:29 -04:00
|
|
|
int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\"");
|
|
|
|
int endIndex = unparsedHtml.indexOf("</a>", beginIndex);
|
|
|
|
String trimmedHtml = unparsedHtml.substring(beginIndex, endIndex);
|
|
|
|
|
|
|
|
Document parsedDocument = Jsoup.parse(trimmedHtml);
|
|
|
|
|
|
|
|
Element imageElement = parsedDocument.getElementById("comic_page");
|
|
|
|
|
|
|
|
return imageElement.attr("src");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|