Skip to content

Commit

Permalink
Merge pull request #29 from ranobe-org/feat/more-sources
Browse files Browse the repository at this point in the history
Add more sources
  • Loading branch information
ap-atul authored Aug 19, 2023
2 parents 2b9f66d + 66e6e69 commit 3b5766e
Show file tree
Hide file tree
Showing 49 changed files with 3,412 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
local.properties
/app/release/
.idea
beta/
beta/

/downloader/
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/src/main/java/org/ranobe/ranobe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static Context getContext() {
@Override
public void onCreate() {
super.onCreate();

Log.d(Ranobe.DEBUG, "app launched");
DynamicColors.applyToActivitiesIfAvailable(this);
App.context = getApplicationContext();
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/ranobe/ranobe/sources/SourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import org.ranobe.ranobe.sources.en.AllNovel;
import org.ranobe.ranobe.sources.en.AzyNovel;
import org.ranobe.ranobe.sources.en.BoxNovel;
import org.ranobe.ranobe.sources.en.LightNovelBtt;
import org.ranobe.ranobe.sources.en.LightNovelHeaven;
import org.ranobe.ranobe.sources.en.LightNovelPub;
import org.ranobe.ranobe.sources.en.Neovel;
import org.ranobe.ranobe.sources.en.NewNovel;
import org.ranobe.ranobe.sources.en.Ranobe;
import org.ranobe.ranobe.sources.en.ReadLightNovel;
import org.ranobe.ranobe.sources.en.ReadWebNovels;
import org.ranobe.ranobe.sources.en.VipNovel;
import org.ranobe.ranobe.sources.en.WuxiaWorld;
import org.ranobe.ranobe.sources.ru.RanobeHub;

import java.util.HashMap;
Expand Down Expand Up @@ -35,6 +41,12 @@ public static HashMap<Integer, Class<?>> getSources() {
sources.put(6, Ranobe.class);
sources.put(7, AllNovel.class);
sources.put(8, AzyNovel.class);
sources.put(9, LightNovelHeaven.class);
sources.put(10, NewNovel.class);
sources.put(11, ReadWebNovels.class);
sources.put(12, BoxNovel.class);
sources.put(13, WuxiaWorld.class);
sources.put(14, Neovel.class);

return sources;
}
Expand Down
152 changes: 152 additions & 0 deletions app/src/main/java/org/ranobe/ranobe/sources/en/BoxNovel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package org.ranobe.ranobe.sources.en;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.ranobe.ranobe.models.Chapter;
import org.ranobe.ranobe.models.DataSource;
import org.ranobe.ranobe.models.Filter;
import org.ranobe.ranobe.models.Lang;
import org.ranobe.ranobe.models.Novel;
import org.ranobe.ranobe.network.HttpClient;
import org.ranobe.ranobe.sources.Source;
import org.ranobe.ranobe.util.NumberUtils;
import org.ranobe.ranobe.util.SourceUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class BoxNovel implements Source {
private static final String baseUrl = "https://boxnovel.com";
private static final int sourceId = 12;

private String cleanImg(String cover) {
return cover.replaceAll("/-\\d+x\\d+.\\w{3}/gm", ".jpg");
}

@Override
public DataSource metadata() {
DataSource source = new DataSource();
source.sourceId = sourceId;
source.url = baseUrl;
source.name = "Box Novel";
source.lang = Lang.eng;
source.dev = "ap-atul";
source.logo = "https://boxnovel.com/wp-content/uploads/2018/04/box-icon-250x250.png";
return source;
}

@Override
public List<Novel> novels(int page) throws IOException {
List<Novel> items = new ArrayList<>();
String web = baseUrl.concat("/page/").concat(String.valueOf(page));
Element doc = Jsoup.parse(HttpClient.GET(web, new HashMap<>()));

for (Element element : doc.select(".page-item-detail")) {
String url = element.select(".h5 > a").attr("href").trim();

if (url.length() > 0) {
Novel item = new Novel(url);
item.sourceId = sourceId;
item.name = element.select(".h5 > a").text().trim();
item.cover = cleanImg(element.select("img").attr("data-src").trim());
items.add(item);
}
}

return items;
}

@Override
public Novel details(Novel novel) throws IOException {
Element doc = Jsoup.parse(HttpClient.GET(novel.url, new HashMap<>()));

novel.sourceId = sourceId;
novel.name = doc.select(".post-title > h1").text().trim();
novel.cover = cleanImg(doc.select(".summary_image > a > img").attr("data-src").trim());
novel.summary = doc.select("div.summary__content").text().replaceAll("\n", "\n\n").trim();
novel.rating = NumberUtils.toFloat(doc.select(".total_votes").text().trim());
novel.authors = Arrays.asList(doc.select(".author-content > a").text().split(","));

List<String> genres = new ArrayList<>();
for (Element element : doc.select(".genres-content > a")) {
genres.add(element.text().trim());
}
novel.genres = genres;

for (Element element : doc.select(".post-content_item")) {
String header = element.select(".summary-heading > h5").text().trim();
String content = element.select(".summary-content").text().trim();

if (header.equalsIgnoreCase("Status")) {
novel.status = content;
} else if (header.equalsIgnoreCase("Alternative")) {
novel.alternateNames = Arrays.asList(content.split(","));
} else if (header.equalsIgnoreCase("Release")) {
novel.year = NumberUtils.toInt(content);
}
}

return novel;
}

@Override
public List<Chapter> chapters(Novel novel) throws IOException {
List<Chapter> items = new ArrayList<>();
String web = novel.url.concat("ajax/chapters");
Element doc = Jsoup.parse(HttpClient.POST(web, new HashMap<>(), new HashMap<>()));

for (Element element : doc.select(".wp-manga-chapter")) {
Chapter item = new Chapter(novel.url);

item.url = element.select("a").attr("href").trim();
item.name = element.select("a").text().trim();
item.id = NumberUtils.toFloat(item.name);
item.updated = element.select("span.chapter-release-date").text().trim();
items.add(item);
}

return items;
}

@Override
public Chapter chapter(Chapter chapter) throws IOException {
Element doc = Jsoup.parse(HttpClient.GET(chapter.url, new HashMap<>()));
Element main = doc.select(".reading-content").first();

if (main == null) {
return null;
}

chapter.content = "";
chapter.content = String.join("\n\n", main.select("p").eachText());
return chapter;
}

@Override
public List<Novel> search(Filter filters, int page) throws IOException {
List<Novel> items = new ArrayList<>();

if (filters.hashKeyword()) {
String web = SourceUtils.buildUrl(baseUrl, "/page/", String.valueOf(page), "/?s=", filters.getKeyword(), "&post_type=wp-manga");
Element doc = Jsoup.parse(HttpClient.GET(web, new HashMap<>()));
for (Element element : doc.select(".c-tabs-item__content")) {
String url = element.select(".tab-thumb > a").attr("href").trim();

if (url.length() > 0) {
Novel item = new Novel(url);
item.sourceId = sourceId;
item.url = url;
item.name = element.select(".post-title > h3 > a").text().trim();
item.cover = cleanImg(element.select("img.img-responsive").attr("data-src").trim());

items.add(item);
}
}
}

return items;
}
}
148 changes: 148 additions & 0 deletions app/src/main/java/org/ranobe/ranobe/sources/en/LightNovelHeaven.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package org.ranobe.ranobe.sources.en;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.ranobe.ranobe.models.Chapter;
import org.ranobe.ranobe.models.DataSource;
import org.ranobe.ranobe.models.Filter;
import org.ranobe.ranobe.models.Lang;
import org.ranobe.ranobe.models.Novel;
import org.ranobe.ranobe.network.HttpClient;
import org.ranobe.ranobe.sources.Source;
import org.ranobe.ranobe.util.NumberUtils;
import org.ranobe.ranobe.util.SourceUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class LightNovelHeaven implements Source {
private final String baseUrl = "https://lightnovelheaven.com/";
private final int sourceId = 9;

@Override
public DataSource metadata() {
DataSource source = new DataSource();
source.sourceId = sourceId;
source.url = baseUrl;
source.name = "Light Novel Heaven";
source.lang = Lang.eng;
source.dev = "ap-atul";
source.logo = "https://lightnovelheaven.com/wp-content/uploads/2020/07/cropped-mid-2-192x192.png";
return source;
}

@Override
public List<Novel> novels(int page) throws IOException {
List<Novel> items = new ArrayList<>();
String web = baseUrl.concat("/page/").concat(String.valueOf(page));
Element doc = Jsoup.parse(HttpClient.GET(web, new HashMap<>()));

for (Element element : doc.select(".page-item-detail")) {
String url = element.select(".h5 > a").attr("href").trim();

if (url.length() > 0) {
Novel item = new Novel(url);
item.sourceId = sourceId;
item.name = element.select(".h5 > a").text().trim();
item.cover = element.select("img").attr("data-src").trim();
items.add(item);
}
}

return items;
}

@Override
public Novel details(Novel novel) throws IOException {
Element doc = Jsoup.parse(HttpClient.GET(novel.url, new HashMap<>()));

novel.sourceId = sourceId;
novel.name = doc.select(".post-title > h1").text().trim();
novel.cover = doc.select(".summary_image > a > img").attr("data-src").trim();
novel.summary = String.join("\n\n", doc.select("div.summary__content").select("p").eachText());
novel.rating = NumberUtils.toFloat(doc.select(".total_votes").text().trim());
novel.authors = Arrays.asList(doc.select(".author-content > a").text().split(","));

List<String> genres = new ArrayList<>();
for (Element element : doc.select(".genres-content > a")) {
genres.add(element.text().trim());
}
novel.genres = genres;

for (Element element : doc.select(".post-content_item")) {
String header = element.select(".summary-heading > h5").text().trim();
String content = element.select(".summary-content").text().trim();

if (header.equalsIgnoreCase("Status")) {
novel.status = content;
} else if (header.equalsIgnoreCase("Alternative")) {
novel.alternateNames = Arrays.asList(content.split(","));
} else if (header.equalsIgnoreCase("Release")) {
novel.year = NumberUtils.toInt(content);
}
}

return novel;
}

@Override
public List<Chapter> chapters(Novel novel) throws IOException {
List<Chapter> items = new ArrayList<>();
String web = novel.url.concat("ajax/chapters");
Element doc = Jsoup.parse(HttpClient.POST(web, new HashMap<>(), new HashMap<>()));

for (Element element : doc.select(".wp-manga-chapter")) {
Chapter item = new Chapter(novel.url);

item.url = element.select("a").attr("href").trim();
item.name = element.select("a").text().trim();
item.id = NumberUtils.toFloat(item.name);
item.updated = element.select("span.chapter-release-date").text().trim();
items.add(item);
}

return items;
}

@Override
public Chapter chapter(Chapter chapter) throws IOException {
Element doc = Jsoup.parse(HttpClient.GET(chapter.url, new HashMap<>()));
Element main = doc.select(".reading-content").first();

if (main == null) {
return null;
}

chapter.content = "";
chapter.content = String.join("\n\n", main.select("p").eachText());
return chapter;
}

@Override
public List<Novel> search(Filter filters, int page) throws IOException {
List<Novel> items = new ArrayList<>();

if (filters.hashKeyword()) {
String web = SourceUtils.buildUrl(baseUrl, "/page/", String.valueOf(page), "/?s=", filters.getKeyword(), "&post_type=wp-manga");
Element doc = Jsoup.parse(HttpClient.GET(web, new HashMap<>()));
for (Element element : doc.select(".c-tabs-item__content")) {
String url = element.select(".tab-thumb > a").attr("href").trim();

if (url.length() > 0) {
Novel item = new Novel(url);
item.sourceId = sourceId;
item.url = url;
item.name = element.select(".post-title > h3 > a").text().trim();
item.cover = element.select("img.img-responsive").attr("data-src").trim();

items.add(item);
}
}
}

return items;
}
}
Loading

0 comments on commit 3b5766e

Please sign in to comment.