-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ranobe-org/feat/more-sources
Add more sources
- Loading branch information
Showing
49 changed files
with
3,412 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ | |
local.properties | ||
/app/release/ | ||
.idea | ||
beta/ | ||
beta/ | ||
|
||
/downloader/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
app/src/main/java/org/ranobe/ranobe/sources/en/BoxNovel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
148
app/src/main/java/org/ranobe/ranobe/sources/en/LightNovelHeaven.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.