Pull manga details from Batoto
This commit is contained in:
parent
e7ecfd1e84
commit
270b3e796a
@ -171,114 +171,36 @@ public class Batoto extends Source {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
private void updateLibraryInDatabase(List<Manga> mangaList) {
|
|
||||||
mQueryManager.beginLibraryTransaction();
|
|
||||||
try {
|
|
||||||
List<Manga> mangaToRemove = new ArrayList<>();
|
|
||||||
for (Manga currentManga : mangaList) {
|
|
||||||
Manga existingManga = mQueryManager.retrieveManga(NAME, currentManga.getName())
|
|
||||||
.toBlocking()
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (existingManga != null) {
|
|
||||||
existingManga.setUpdated(currentManga.getUpdated());
|
|
||||||
existingManga.setUpdateCount(currentManga.getUpdateCount());
|
|
||||||
|
|
||||||
|
|
||||||
mQueryManager.createManga(existingManga)
|
|
||||||
.toBlocking()
|
|
||||||
.single();
|
|
||||||
} else {
|
|
||||||
mangaToRemove.add(currentManga);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mangaList.removeAll(mangaToRemove);
|
|
||||||
|
|
||||||
mQueryManager.setLibraryTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
mQueryManager.endLibraryTransaction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findNextUrlFromParsedDocument(String requestUrl, String unparsedHtml) {
|
|
||||||
if (!unparsedHtml.contains("No (more) comics found!")) {
|
|
||||||
requestUrl = requestUrl.replace("http://bato.to/search_ajax?order_cond=update&order=desc&p=", "");
|
|
||||||
|
|
||||||
return "http://bato.to/search_ajax?order_cond=update&order=desc&p=" + (Integer.valueOf(requestUrl) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DefaultFactory.UpdatePageMarker.DEFAULT_NEXT_PAGE_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Observable<Manga> pullMangaFromNetwork(final String mangaUrl) {
|
public Observable<Manga> pullMangaFromNetwork(final String mangaUrl) {
|
||||||
String mangaId = mangaUrl.substring(mangaUrl.lastIndexOf("r") + 1);
|
String mangaId = mangaUrl.substring(mangaUrl.lastIndexOf("r") + 1);
|
||||||
|
|
||||||
return mNetworkService
|
return mNetworkService
|
||||||
.getResponse("http://bato.to/comic_pop?id=" + mangaId, NetworkModule.NULL_CACHE_CONTROL, REQUEST_HEADERS)
|
.getStringResponse("http://bato.to/comic_pop?id=" + mangaId, mNetworkService.NULL_CACHE_CONTROL, REQUEST_HEADERS)
|
||||||
.flatMap(new Func1<Response, Observable<String>>() {
|
.flatMap(unparsedHtml -> Observable.just(parseHtmlToManga(mangaUrl, unparsedHtml)));
|
||||||
@Override
|
|
||||||
public Observable<String> call(Response response) {
|
|
||||||
return mNetworkService.mapResponseToString(response);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.flatMap(new Func1<String, Observable<Manga>>() {
|
|
||||||
@Override
|
|
||||||
public Observable<Manga> call(String unparsedHtml) {
|
|
||||||
return Observable.just(parseHtmlToManga(mangaUrl, unparsedHtml));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Manga parseHtmlToManga(String mangaUrl, String unparsedHtml) {
|
private Manga parseHtmlToManga(String mangaUrl, String unparsedHtml) {
|
||||||
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
||||||
|
|
||||||
Element artistElement = parsedDocument.select("a[href^=http://bato.to/search?artist_name]").first();
|
Elements artistElements = parsedDocument.select("a[href^=http://bato.to/search?artist_name]");
|
||||||
Element descriptionElement = parsedDocument.select("tr").get(5);
|
Element descriptionElement = parsedDocument.select("tr").get(5);
|
||||||
Elements genreElements = parsedDocument.select("img[src=http://bato.to/forums/public/style_images/master/bullet_black.png]");
|
Elements genreElements = parsedDocument.select("img[src=http://bato.to/forums/public/style_images/master/bullet_black.png]");
|
||||||
Element thumbnailUrlElement = parsedDocument.select("img[src^=http://img.batoto.net/forums/uploads/]").first();
|
Element thumbnailUrlElement = parsedDocument.select("img[src^=http://img.batoto.net/forums/uploads/]").first();
|
||||||
|
|
||||||
StringBuilder selection = new StringBuilder();
|
Manga newManga = new Manga();
|
||||||
List<String> selectionArgs = new ArrayList<String>();
|
newManga.url = mangaUrl;
|
||||||
|
|
||||||
selection.append(LibraryContract.Manga.COLUMN_SOURCE + " = ?");
|
if (artistElements != null) {
|
||||||
selectionArgs.add(NAME);
|
newManga.author = artistElements.get(0).text();
|
||||||
selection.append(" AND ").append(LibraryContract.Manga.COLUMN_URL + " = ?");
|
if (artistElements.size() > 1) {
|
||||||
selectionArgs.add(mangaUrl);
|
newManga.artist = artistElements.get(1).text();
|
||||||
|
} else {
|
||||||
Manga newManga = mQueryManager.retrieveMangaAsCursor(
|
newManga.artist = newManga.author;
|
||||||
null,
|
}
|
||||||
selection.toString(),
|
|
||||||
selectionArgs.toArray(new String[selectionArgs.size()]),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
"1"
|
|
||||||
)
|
|
||||||
.map(new Func1<Cursor, Manga>() {
|
|
||||||
@Override
|
|
||||||
public Manga call(Cursor cursor) {
|
|
||||||
return DatabaseUtils.toObject(cursor, Manga.class);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(new Func1<Manga, Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean call(Manga manga) {
|
|
||||||
return manga != null;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toBlocking()
|
|
||||||
.single();
|
|
||||||
|
|
||||||
if (artistElement != null) {
|
|
||||||
String fieldArtist = artistElement.text();
|
|
||||||
newManga.setArtist(fieldArtist);
|
|
||||||
newManga.setAuthor(fieldArtist);
|
|
||||||
}
|
}
|
||||||
if (descriptionElement != null) {
|
if (descriptionElement != null) {
|
||||||
String fieldDescription = descriptionElement.text().substring("Description:".length()).trim();
|
String fieldDescription = descriptionElement.text().substring("Description:".length()).trim();
|
||||||
newManga.setDescription(fieldDescription);
|
newManga.description = fieldDescription;
|
||||||
}
|
}
|
||||||
if (genreElements != null) {
|
if (genreElements != null) {
|
||||||
String fieldGenres = "";
|
String fieldGenres = "";
|
||||||
@ -291,26 +213,21 @@ public class Batoto extends Source {
|
|||||||
fieldGenres += currentGenre;
|
fieldGenres += currentGenre;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newManga.setGenre(fieldGenres);
|
newManga.genre = fieldGenres;
|
||||||
}
|
}
|
||||||
if (thumbnailUrlElement != null) {
|
if (thumbnailUrlElement != null) {
|
||||||
String fieldThumbnailUrl = thumbnailUrlElement.attr("src");
|
String fieldThumbnailUrl = thumbnailUrlElement.attr("src");
|
||||||
newManga.setThumbnailUrl(fieldThumbnailUrl);
|
newManga.thumbnail_url = fieldThumbnailUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean fieldCompleted = unparsedHtml.contains("<td>Complete</td>");
|
boolean fieldCompleted = unparsedHtml.contains("<td>Complete</td>");
|
||||||
newManga.setCompleted(fieldCompleted);
|
//TODO fix
|
||||||
|
newManga.status = fieldCompleted + "";
|
||||||
|
|
||||||
|
newManga.initialized = true;
|
||||||
newManga.setInitialized(true);
|
|
||||||
|
|
||||||
mQueryManager.createManga(newManga)
|
|
||||||
.toBlocking()
|
|
||||||
.single();
|
|
||||||
|
|
||||||
return newManga;
|
return newManga;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public Observable<List<Chapter>> pullChaptersFromNetwork(String mangaUrl) {
|
public Observable<List<Chapter>> pullChaptersFromNetwork(String mangaUrl) {
|
||||||
return mNetworkService
|
return mNetworkService
|
||||||
@ -322,12 +239,11 @@ public class Batoto extends Source {
|
|||||||
private List<Chapter> parseHtmlToChapters(String unparsedHtml) {
|
private List<Chapter> parseHtmlToChapters(String unparsedHtml) {
|
||||||
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
||||||
|
|
||||||
List<Chapter> chapterList = new ArrayList<Chapter>();
|
List<Chapter> chapterList = new ArrayList<>();
|
||||||
|
|
||||||
Elements chapterElements = parsedDocument.select("tr.row.lang_English.chapter_row");
|
Elements chapterElements = parsedDocument.select("tr.row.lang_English.chapter_row");
|
||||||
for (Element chapterElement : chapterElements) {
|
for (Element chapterElement : chapterElements) {
|
||||||
Chapter currentChapter = constructChapterFromHtmlBlock(chapterElement);
|
Chapter currentChapter = constructChapterFromHtmlBlock(chapterElement);
|
||||||
System.out.println(currentChapter.name);
|
|
||||||
chapterList.add(currentChapter);
|
chapterList.add(currentChapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user