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(getDate());
36 meta
.setTags(getTags());
37 meta
.setSource(getType().getSourceName());
38 meta
.setUrl(getSource().toString());
39 meta
.setPublisher(getType().getSourceName());
40 meta
.setUuid(getSource().toString());
43 meta
.setSubject("manga");
44 meta
.setType(getType().toString());
45 meta
.setImageDocument(true);
46 meta
.setCover(getCover());
51 private String
getTitle() {
52 Element doc
= getSourceNode();
53 Element h4
= doc
.getElementsByTag("h4").first();
55 return StringUtils
.unhtml(h4
.text()).trim();
61 private String
getAuthor() {
62 Element doc
= getSourceNode();
63 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
65 String
[] tab
= tabEls
.outerHtml().split("<br>");
66 return getVal(tab
, 1);
72 private List
<String
> getTags() {
73 Element doc
= getSourceNode();
74 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
76 String
[] tab
= tabEls
.outerHtml().split("<br>");
77 List
<String
> tags
= new ArrayList
<String
>();
78 for (String tag
: getVal(tab
, 3).split(" ")) {
84 return new ArrayList
<String
>();
88 private String
getDate() {
89 Element doc
= getSourceNode();
90 Element table
= doc
.getElementsByClass("table").first();
92 // We take the first date we find
96 els
= table
.getElementsByTag("tr");
97 if (els
.size() >= 2) {
98 els
= els
.get(1).getElementsByTag("td");
99 if (els
.size() >= 3) {
100 value
= StringUtils
.unhtml(els
.get(2).text()).trim();
105 if (!value
.isEmpty()) {
107 long time
= StringUtils
.toTime(value
);
108 value
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
110 } catch (ParseException e
) {
118 protected String
getDesc() {
119 Element doc
= getSourceNode();
120 Element tabEls
= doc
.getElementsByClass("presentation-projet").first();
121 if (tabEls
!= null) {
122 String
[] tab
= tabEls
.outerHtml().split("<br>");
123 return getVal(tab
, 4);
129 private Image
getCover() {
130 Element doc
= getSourceNode();
131 Element container
= doc
.getElementsByClass("container").first();
133 if (container
!= null) {
135 Elements imgs
= container
.getElementsByTag("img");
137 if (imgs
.size() >= 1) {
139 if (img
.hasClass("banniere-team-projet")) {
141 if (imgs
.size() >= 2) {
148 String coverUrl
= img
.absUrl("src");
152 coverIn
= Instance
.getCache().open(new URL(coverUrl
), this,
155 return new Image(coverIn
);
159 } catch (IOException e
) {
160 Instance
.getTraceHandler().error(e
);
168 private String
getVal(String
[] tab
, int i
) {
171 if (i
< tab
.length
) {
172 val
= StringUtils
.unhtml(tab
[i
]);
173 int pos
= val
.indexOf(":");
175 val
= val
.substring(pos
+ 1).trim();
183 protected List
<Entry
<String
, URL
>> getChapters(Progress pg
)
185 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
187 Element doc
= getSourceNode();
188 Element table
= doc
.getElementsByClass("table").first();
190 for (Element tr
: table
.getElementsByTag("tr")) {
191 Element a
= tr
.getElementsByTag("a").first();
193 String name
= StringUtils
.unhtml(a
.text()).trim();
194 URL url
= new URL(a
.absUrl("href"));
195 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(name
, url
));
204 protected String
getChapterContent(URL chapUrl
, int number
, Progress pg
)
210 StringBuilder builder
= new StringBuilder();
212 InputStream in
= Instance
.getCache().open(chapUrl
, this, false);
214 Element pageDoc
= DataUtil
.load(in
, "UTF-8", chapUrl
.toString());
215 Element content
= pageDoc
.getElementById("content");
216 Elements linkEls
= content
.getElementsByTag("img");
217 for (Element linkEl
: linkEls
) {
218 if (linkEl
.absUrl("src").isEmpty()) {
223 builder
.append(linkEl
.absUrl("src"));
224 builder
.append("]<br/>");
231 return builder
.toString();
235 protected boolean supports(URL url
) {
236 // URL structure (the projectId is the manga key):
237 // http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet=999
239 return "mangas-lecture-en-ligne.fr".equals(url
.getHost());