|
@@ -1,4 +1,4 @@
|
|
|
-package eu.kanade.mangafeed.sources;
|
|
|
+package eu.kanade.mangafeed.sources.base;
|
|
|
|
|
|
|
|
|
import com.squareup.okhttp.Headers;
|
|
@@ -14,59 +14,7 @@ import eu.kanade.mangafeed.data.models.Page;
|
|
|
import rx.Observable;
|
|
|
import rx.schedulers.Schedulers;
|
|
|
|
|
|
-public abstract class Source {
|
|
|
-
|
|
|
- // Methods to implement or optionally override
|
|
|
-
|
|
|
- // Name of the source to display
|
|
|
- public abstract String getName();
|
|
|
-
|
|
|
- // Id of the source (must be declared and obtained from SourceManager to avoid conflicts)
|
|
|
- public abstract int getSourceId();
|
|
|
-
|
|
|
- protected abstract String getUrlFromPageNumber(int page);
|
|
|
- protected abstract String getSearchUrl(String query, int page);
|
|
|
- protected abstract List<Manga> parsePopularMangasFromHtml(String unparsedHtml);
|
|
|
- protected abstract List<Manga> parseSearchFromHtml(String unparsedHtml);
|
|
|
- protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml);
|
|
|
- protected abstract List<Chapter> parseHtmlToChapters(String unparsedHtml);
|
|
|
- protected abstract List<String> parseHtmlToPageUrls(String unparsedHtml);
|
|
|
- protected abstract String parseHtmlToImageUrl(String unparsedHtml);
|
|
|
-
|
|
|
- // True if the source requires a login
|
|
|
- public boolean isLoginRequired() {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Get the URL to the details of a manga, useful if the source provides some kind of API or fast calls
|
|
|
- protected String getMangaUrl(String defaultMangaUrl) {
|
|
|
- return defaultMangaUrl;
|
|
|
- }
|
|
|
-
|
|
|
- // Get the URL of the first page that contains a source image and the page list
|
|
|
- protected String getChapterPageUrl(String defaultPageUrl) {
|
|
|
- return defaultPageUrl;
|
|
|
- }
|
|
|
-
|
|
|
- // Get the URL of the remaining pages that contains source images
|
|
|
- protected String getRemainingPagesUrl(String defaultPageUrl) {
|
|
|
- return defaultPageUrl;
|
|
|
- }
|
|
|
-
|
|
|
- // Default headers, it can be overriden by children or just add new keys
|
|
|
- protected Headers.Builder headersBuilder() {
|
|
|
- Headers.Builder builder = new Headers.Builder();
|
|
|
- builder.add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)");
|
|
|
- return builder;
|
|
|
- }
|
|
|
-
|
|
|
- // Number of images to download at the same time
|
|
|
- protected int getNumberOfConcurrentPageDownloads() {
|
|
|
- return 3;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // ***** Source class implementation *****
|
|
|
+public abstract class Source extends BaseSource {
|
|
|
|
|
|
protected NetworkHelper mNetworkService;
|
|
|
protected CacheManager mCacheManager;
|
|
@@ -96,7 +44,7 @@ public abstract class Source {
|
|
|
// Get manga details from the source
|
|
|
public Observable<Manga> pullMangaFromNetwork(final String mangaUrl) {
|
|
|
return mNetworkService
|
|
|
- .getStringResponse(getMangaUrl(mangaUrl), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
+ .getStringResponse(overrideMangaUrl(mangaUrl), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
.flatMap(unparsedHtml -> Observable.just(parseHtmlToManga(mangaUrl, unparsedHtml)));
|
|
|
}
|
|
|
|
|
@@ -112,7 +60,7 @@ public abstract class Source {
|
|
|
return mCacheManager.getPageUrlsFromDiskCache(chapterUrl)
|
|
|
.onErrorResumeNext(throwable -> {
|
|
|
return mNetworkService
|
|
|
- .getStringResponse(getChapterPageUrl(chapterUrl), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
+ .getStringResponse(overrideChapterPageUrl(chapterUrl), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
.flatMap(unparsedHtml -> {
|
|
|
List<String> pageUrls = parseHtmlToPageUrls(unparsedHtml);
|
|
|
return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml));
|
|
@@ -126,7 +74,7 @@ public abstract class Source {
|
|
|
public Observable<Page> getRemainingImageUrlsFromPageList(final List<Page> pages) {
|
|
|
return Observable.from(pages)
|
|
|
.filter(page -> page.getImageUrl() == null)
|
|
|
- .window(getNumberOfConcurrentPageDownloads())
|
|
|
+ .window(overrideNumberOfConcurrentPageDownloads())
|
|
|
.concatMap(batchedPages ->
|
|
|
batchedPages.concatMap(this::getImageUrlFromPage)
|
|
|
);
|
|
@@ -134,7 +82,7 @@ public abstract class Source {
|
|
|
|
|
|
private Observable<Page> getImageUrlFromPage(final Page page) {
|
|
|
return mNetworkService
|
|
|
- .getStringResponse(getRemainingPagesUrl(page.getUrl()), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
+ .getStringResponse(overrideRemainingPagesUrl(page.getUrl()), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders)
|
|
|
.flatMap(unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml)))
|
|
|
.flatMap(imageUrl -> {
|
|
|
page.setImageUrl(imageUrl);
|