1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
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
.helper
.DataUtil
;
14 import org
.jsoup
.nodes
.Element
;
15 import org
.jsoup
.select
.Elements
;
17 import be
.nikiroo
.fanfix
.Instance
;
18 import be
.nikiroo
.fanfix
.data
.MetaData
;
19 import be
.nikiroo
.utils
.Image
;
20 import be
.nikiroo
.utils
.Progress
;
21 import be
.nikiroo
.utils
.StringUtils
;
23 class MangaLel
extends BasicSupport
{
25 protected boolean isHtml() {
30 public String
getSourceName() {
31 return "MangaLel.com";
35 protected MetaData
getMeta() throws IOException
{
36 MetaData meta
= new MetaData();
38 String
[] authorDateTag
= getAuthorDateTag();
40 meta
.setTitle(getTitle());
41 meta
.setAuthor(authorDateTag
[0]);
42 meta
.setDate(authorDateTag
[1]);
43 meta
.setTags(explode(authorDateTag
[2]));
44 meta
.setSource(getSourceName());
45 meta
.setUrl(getSource().toString());
46 meta
.setPublisher(getSourceName());
47 meta
.setUuid(getSource().toString());
50 meta
.setSubject("manga");
51 meta
.setType(getType().toString());
52 meta
.setImageDocument(true);
53 meta
.setCover(getCover());
58 private String
getTitle() {
59 Element doc
= getSourceNode();
60 Element h2
= doc
.getElementsByClass("widget-title").first();
62 return StringUtils
.unhtml(h2
.text()).trim();
71 private String
[] getAuthorDateTag() {
72 String
[] tab
= new String
[3];
74 Element doc
= getSourceNode();
75 Element tabEls
= doc
.getElementsByClass("dl-horizontal").first();
77 for (Element tabEl
: tabEls
.children()) {
78 String txt
= tabEl
.text().trim();
80 if (tab
[prevOk
- 1] == null) {
83 tab
[prevOk
- 1] += ", ";
86 tab
[prevOk
- 1] += txt
;
89 if (txt
.equals("Auteur(s)") || txt
.equals("Artist(s)")) {
91 } else if (txt
.equals("Date de sortie")) {
93 } else if (txt
.equals("Type") || txt
.equals("Catégories")) {
101 for (int i
= 0; i
< 3; i
++) {
103 for (String item
: explode(tab
[i
])) {
104 if (!list
.isEmpty()) {
116 protected String
getDesc() {
119 Element doc
= getSourceNode();
120 Element title
= doc
.getElementsByClass("well").first();
122 desc
= StringUtils
.unhtml(title
.text()).trim();
123 if (desc
.startsWith("Résumé")) {
124 desc
= desc
.substring("Résumé".length()).trim();
131 private Image
getCover() {
132 Element doc
= getSourceNode();
133 Element cover
= doc
.getElementsByClass("img-responsive").first();
136 String coverUrl
= cover
.absUrl("src");
140 coverIn
= Instance
.getCache().open(new URL(coverUrl
), this,
143 return new Image(coverIn
);
147 } catch (IOException e
) {
148 Instance
.getTraceHandler().error(e
);
156 protected List
<Entry
<String
, URL
>> getChapters(Progress pg
) {
157 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
160 Element doc
= getSourceNode();
161 Elements chapEls
= doc
.getElementsByClass("chapters").first()
162 .getElementsByTag("li");
163 for (Element chapEl
: chapEls
) {
164 Element titleEl
= chapEl
.getElementsByTag("h5").first();
165 String title
= StringUtils
.unhtml(titleEl
.text()).trim();
167 // because Atril does not support strange file names
168 title
= Integer
.toString(chapEls
.size() - i
);
170 Element linkEl
= chapEl
.getElementsByTag("h5").first()
171 .getElementsByTag("a").first();
172 String link
= linkEl
.absUrl("href");
175 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(title
,
177 } catch (MalformedURLException e
) {
178 Instance
.getTraceHandler().error(e
);
184 Collections
.reverse(urls
);
189 protected String
getChapterContent(URL chapUrl
, int number
, Progress pg
)
195 StringBuilder builder
= new StringBuilder();
197 InputStream in
= Instance
.getCache().open(chapUrl
, this, false);
199 Element pageDoc
= DataUtil
.load(in
, "UTF-8", chapUrl
.toString());
200 Elements linkEls
= pageDoc
.getElementsByClass("img-responsive");
201 for (Element linkEl
: linkEls
) {
202 if (linkEl
.hasAttr("data-src")) {
204 builder
.append(linkEl
.absUrl("data-src").trim());
205 builder
.append("]<br/>");
213 return builder
.toString();
217 * Explode an HTML comma-separated list of values into a non-duplicate text
221 * the comma-separated values in HTML format
223 * @return the full list with no duplicate in text format
225 private List
<String
> explode(String values
) {
226 List
<String
> list
= new ArrayList
<String
>();
227 if (values
!= null && !values
.isEmpty()) {
228 for (String auth
: values
.split(",")) {
229 String a
= StringUtils
.unhtml(auth
).trim();
230 if (!a
.isEmpty() && !list
.contains(a
.trim())) {
240 protected boolean supports(URL url
) {
241 return "manga-lel.com".equals(url
.getHost())
242 || "www.manga-lel.com".equals(url
.getHost());