1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.text
.ParseException
;
7 import java
.text
.SimpleDateFormat
;
8 import java
.util
.AbstractMap
;
9 import java
.util
.ArrayList
;
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 protected MetaData
getMeta() throws IOException
{
31 MetaData meta
= new MetaData();
33 meta
.setTitle(getTitle());
34 meta
.setAuthor(getAuthor());
35 meta
.setDate(bsHelper
.formatDate(getDate()));
36 meta
.setTags(getTags());
37 meta
.setUrl(getSource().toString());
38 meta
.setUuid(getSource().toString());
41 meta
.setSubject("manga");
42 meta
.setImageDocument(true);
43 meta
.setCover(getCover());
48 private String
getTitle() {
49 Element doc
= getSourceNode();
50 Element h4
= doc
.getElementsByTag("h4").first();
52 return StringUtils
.unhtml(h4
.text()).trim();
58 private String
getAuthor() {
59 Element doc
= getSourceNode();
60 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
62 String
[] tab
= tabEls
.outerHtml().split("<br>");
63 return getVal(tab
, 1);
69 private List
<String
> getTags() {
70 Element doc
= getSourceNode();
71 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
73 String
[] tab
= tabEls
.outerHtml().split("<br>");
74 List
<String
> tags
= new ArrayList
<String
>();
75 for (String tag
: getVal(tab
, 3).split(" ")) {
81 return new ArrayList
<String
>();
85 private String
getDate() {
86 Element doc
= getSourceNode();
87 Element table
= doc
.getElementsByClass("table").first();
89 // We take the first date we find
93 els
= table
.getElementsByTag("tr");
94 if (els
.size() >= 2) {
95 els
= els
.get(1).getElementsByTag("td");
96 if (els
.size() >= 3) {
97 value
= StringUtils
.unhtml(els
.get(2).text()).trim();
106 protected String
getDesc() {
107 Element doc
= getSourceNode();
108 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
109 if (tabEls
!= null) {
110 String
[] tab
= tabEls
.outerHtml().split("<br>");
111 return getVal(tab
, 4);
117 private Image
getCover() {
118 Element doc
= getSourceNode();
119 Element container
= doc
.getElementsByClass("container").first();
121 if (container
!= null) {
123 Elements imgs
= container
.getElementsByTag("img");
125 if (imgs
.size() >= 1) {
127 if (img
.hasClass("banniere-team-projet")) {
129 if (imgs
.size() >= 2) {
136 String coverUrl
= img
.absUrl("src");
139 InputStream coverIn
= Instance
.getInstance().getCache()
140 .open(new URL(coverUrl
), this, true);
142 Image ii
= new Image(coverIn
);
143 if (ii
.getSize() == 0) {
145 throw new IOException("Empty image not accepted");
152 } catch (IOException e
) {
153 Instance
.getInstance().getTraceHandler().error(e
);
161 private String
getVal(String
[] tab
, int i
) {
164 if (i
< tab
.length
) {
165 val
= StringUtils
.unhtml(tab
[i
]);
166 int pos
= val
.indexOf(":");
168 val
= val
.substring(pos
+ 1).trim();
176 protected List
<Entry
<String
, URL
>> getChapters(Progress pg
)
178 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
180 Element doc
= getSourceNode();
181 Element table
= doc
.getElementsByClass("table").first();
183 for (Element tr
: table
.getElementsByTag("tr")) {
184 Element a
= tr
.getElementsByTag("a").first();
186 String name
= StringUtils
.unhtml(a
.text()).trim();
187 URL url
= new URL(a
.absUrl("href"));
188 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(name
, url
));
197 protected String
getChapterContent(URL chapUrl
, int number
, Progress pg
)
203 StringBuilder builder
= new StringBuilder();
205 InputStream in
= Instance
.getInstance().getCache().open(chapUrl
, this, false);
207 Element pageDoc
= DataUtil
.load(in
, "UTF-8", chapUrl
.toString());
208 Element content
= pageDoc
.getElementById("content");
209 Elements linkEls
= content
.getElementsByTag("img");
210 for (Element linkEl
: linkEls
) {
211 if (linkEl
.absUrl("src").isEmpty()) {
216 builder
.append(linkEl
.absUrl("src"));
217 builder
.append("]<br/>");
224 return builder
.toString();
228 protected boolean supports(URL url
) {
229 // URL structure (the projectId is the manga key):
230 // http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet=999
232 return "mangas-lecture-en-ligne.fr".equals(url
.getHost());