1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.net
.HttpURLConnection
;
5 import java
.net
.MalformedURLException
;
7 import java
.util
.AbstractMap
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Collections
;
10 import java
.util
.List
;
11 import java
.util
.Map
.Entry
;
13 import org
.jsoup
.nodes
.Element
;
15 import be
.nikiroo
.fanfix
.Instance
;
16 import be
.nikiroo
.fanfix
.data
.MetaData
;
17 import be
.nikiroo
.utils
.Image
;
18 import be
.nikiroo
.utils
.Progress
;
19 import be
.nikiroo
.utils
.StringUtils
;
22 * Support class for <a href="https://mangahub.io/">MangaHub</a>, a website
27 class MangaHub
extends BasicSupport
{
29 protected boolean isHtml() {
34 protected MetaData
getMeta() throws IOException
{
35 MetaData meta
= new MetaData();
37 meta
.setTitle(getTitle());
39 meta
.setAuthor(getAuthor());
40 meta
.setTags(getTags());
41 meta
.setSource(getType().getSourceName());
42 meta
.setUrl(getSource().toString());
43 meta
.setPublisher(getType().getSourceName());
44 meta
.setUuid(getSource().toString());
47 meta
.setSubject("manga");
48 meta
.setType(getType().toString());
49 meta
.setImageDocument(true);
50 meta
.setCover(getCover());
55 private String
getTitle() {
56 Element doc
= getSourceNode();
58 Element el
= doc
.getElementsByTag("h1").first();
60 return StringUtils
.unhtml(el
.text()).trim();
66 private String
getAuthor() {
69 Element el
= getSourceNode().select("h1+div span:not([class])").first();
71 author
= StringUtils
.unhtml(el
.text()).trim();
75 private List
<String
> getTags() {
76 return getListA("genre-label");
79 private List
<String
> getListA(String uniqueClass
) {
80 List
<String
> list
= new ArrayList
<String
>();
82 Element doc
= getSourceNode();
83 Element el
= doc
.getElementsByClass(uniqueClass
).first();
85 for (Element valueA
: el
.getElementsByTag("a")) {
86 list
.add(StringUtils
.unhtml(valueA
.text()).trim());
94 protected String
getDesc() {
95 Element doc
= getSourceNode();
96 Element title
= doc
.getElementsByClass("fullcontent").first();
98 return StringUtils
.unhtml(title
.text()).trim();
104 private Image
getCover() {
105 Element doc
= getSourceNode();
106 Element cover
= doc
.getElementsByClass("manga-thumb").first();
109 return bsImages
.getImage(this, new URL(cover
.absUrl("src")));
110 } catch (MalformedURLException e
) {
111 Instance
.getTraceHandler().error(e
);
119 protected List
<Entry
<String
, URL
>> getChapters(Progress pg
) {
120 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
122 Element doc
= getSourceNode();
123 for (Element el
: doc
.getElementsByClass("list-group-item")) {
124 Element urlEl
= el
.getElementsByTag("a").first();
128 String url
= urlEl
.absUrl("href");
131 el
= el
.getElementsByClass("text-secondary").first();
133 title
= StringUtils
.unhtml(el
.text()).trim();
137 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(title
, new URL(url
)));
138 } catch (Exception e
) {
139 Instance
.getTraceHandler().error(e
);
143 // by default, the chapters are in reversed order
144 Collections
.reverse(urls
);
150 protected String
getChapterContent(URL chapUrl
, int number
, Progress pg
) throws IOException
{
155 // 1. Get the title and chapter url part
156 String path
= chapUrl
.getPath();
157 if (path
.endsWith("/")) {
158 path
= path
.substring(0, path
.length() - "/".length());
160 String tab
[] = path
.split("/");
161 String chap
= tab
[tab
.length
- 1];
162 String title
= tab
[tab
.length
- 2];
164 if (chap
.startsWith("chapter-")) {
165 chap
= chap
.substring("chapter-".length());
168 // 2. generate an image base
169 String base
= "https://img.mghubcdn.com/file/imghub/" + title
+ "/" + chap
+ "/";
171 // 3. add each chapter
172 StringBuilder builder
= new StringBuilder();
175 String url
= base
+ i
+ ".jpg";
176 while (getHttpStatus(new URL(url
)) != 404) {
179 builder
.append("]<br/>");
182 url
= base
+ i
+ ".jpg";
185 return builder
.toString();
188 // HTTP response code, or -1 if other error
189 private int getHttpStatus(URL url
) {
191 HttpURLConnection connection
= (HttpURLConnection
) url
.openConnection();
193 connection
.setRequestMethod("HEAD");
194 return connection
.getResponseCode();
196 connection
.disconnect();
198 } catch (Exception e
) {
204 protected boolean supports(URL url
) {
205 return "mangahub.io".equals(url
.getHost()) || "www.mangahub.io".equals(url
.getHost());