X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaLel.java;h=1ba51bc0f5d8a5c32a0341526a5aac142ae3fff6;hb=b8564025bd7c722084c665f7a0a54beda8ef8209;hp=0351622e8ef66b66d6563c6a0920e3f4f8a8edb2;hpb=9e2fad3600cd08eca73d45cb5c991d98095842aa;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java
index 0351622..1ba51bc 100644
--- a/src/be/nikiroo/fanfix/supported/MangaLel.java
+++ b/src/be/nikiroo/fanfix/supported/MangaLel.java
@@ -2,11 +2,11 @@ package be.nikiroo.fanfix.supported;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.AbstractMap;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
@@ -26,24 +26,17 @@ class MangaLel extends BasicSupport {
return true;
}
- @Override
- public String getSourceName() {
- return "MangaLel.com";
- }
-
@Override
protected MetaData getMeta() throws IOException {
MetaData meta = new MetaData();
- String[] authorDateTag = getAuthorDateTag();
-
meta.setTitle(getTitle());
- meta.setAuthor(authorDateTag[0]);
- meta.setDate(authorDateTag[1]);
- meta.setTags(explode(authorDateTag[2]));
- meta.setSource(getSourceName());
+ meta.setAuthor(getAuthor());
+ meta.setDate(getDate());
+ meta.setTags(getTags());
+ meta.setSource(getType().getSourceName());
meta.setUrl(getSource().toString());
- meta.setPublisher(getSourceName());
+ meta.setPublisher(getType().getSourceName());
meta.setUuid(getSource().toString());
meta.setLuid("");
meta.setLang("fr");
@@ -57,131 +50,153 @@ class MangaLel extends BasicSupport {
private String getTitle() {
Element doc = getSourceNode();
- Element h2 = doc.getElementsByClass("widget-title").first();
- if (h2 != null) {
- return StringUtils.unhtml(h2.text()).trim();
+ Element h4 = doc.getElementsByTag("h4").first();
+ if (h4 != null) {
+ return StringUtils.unhtml(h4.text()).trim();
}
return null;
}
- // 0 = author
- // 1 = date
- // 2 = tags
- private String[] getAuthorDateTag() {
- String[] tab = new String[3];
+ private String getAuthor() {
+ Element doc = getSourceNode();
+ Element tabEls = doc.getElementsByClass("presentation-projet").first();
+ if (tabEls != null) {
+ String[] tab = tabEls.outerHtml().split("
");
+ return getVal(tab, 1);
+ }
+ return "";
+ }
+
+ private List getTags() {
Element doc = getSourceNode();
- Element tabEls = doc.getElementsByClass("dl-horizontal").first();
- int prevOk = 0;
- for (Element tabEl : tabEls.children()) {
- String txt = tabEl.text().trim();
- if (prevOk > 0) {
- if (tab[prevOk - 1] == null) {
- tab[prevOk - 1] = "";
- } else {
- tab[prevOk - 1] += ", ";
- }
+ Element tabEls = doc.getElementsByClass("presentation-projet").first();
+ if (tabEls != null) {
+ String[] tab = tabEls.outerHtml().split("
");
+ List tags = new ArrayList();
+ for (String tag : getVal(tab, 3).split(" ")) {
+ tags.add(tag);
+ }
+ return tags;
+ }
- tab[prevOk - 1] += txt;
- prevOk = 0;
- } else {
- if (txt.equals("Auteur(s)") || txt.equals("Artist(s)")) {
- prevOk = 1;
- } else if (txt.equals("Date de sortie")) {
- prevOk = 2;
- } else if (txt.equals("Type") || txt.equals("Catégories")) {
- prevOk = 3;
- } else {
- prevOk = 0;
+ return new ArrayList();
+
+ }
+
+ private String getDate() {
+ Element doc = getSourceNode();
+ Element table = doc.getElementsByClass("table").first();
+
+ // We take the first date we find
+ String value = "";
+ if (table != null) {
+ Elements els;
+ els = table.getElementsByTag("tr");
+ if (els.size() >= 2) {
+ els = els.get(1).getElementsByTag("td");
+ if (els.size() >= 3) {
+ value = StringUtils.unhtml(els.get(2).text()).trim();
}
}
}
- for (int i = 0; i < 3; i++) {
- String list = "";
- for (String item : explode(tab[i])) {
- if (!list.isEmpty()) {
- list = list + ", ";
- }
- list += item;
+ if (!value.isEmpty()) {
+ try {
+ long time = StringUtils.toTime(value);
+ value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
+ .format(time);
+ } catch (ParseException e) {
}
- tab[i] = list;
}
- return tab;
+ return value;
}
@Override
protected String getDesc() {
- String desc = null;
-
Element doc = getSourceNode();
- Element title = doc.getElementsByClass("well").first();
- if (title != null) {
- desc = StringUtils.unhtml(title.text()).trim();
- if (desc.startsWith("Résumé")) {
- desc = desc.substring("Résumé".length()).trim();
- }
+ Element tabEls = doc.getElementsByClass("presentation-projet").first();
+ if (tabEls != null) {
+ String[] tab = tabEls.outerHtml().split("
");
+ return getVal(tab, 4);
}
- return desc;
+ return "";
}
private Image getCover() {
Element doc = getSourceNode();
- Element cover = doc.getElementsByClass("img-responsive").first();
+ Element container = doc.getElementsByClass("container").first();
+
+ if (container != null) {
+
+ Elements imgs = container.getElementsByTag("img");
+ Element img = null;
+ if (imgs.size() >= 1) {
+ img = imgs.get(0);
+ if (img.hasClass("banniere-team-projet")) {
+ img = null;
+ if (imgs.size() >= 2) {
+ img = imgs.get(1);
+ }
+ }
+ }
- if (cover != null) {
- String coverUrl = cover.absUrl("src");
+ if (img != null) {
+ String coverUrl = img.absUrl("src");
- InputStream coverIn;
- try {
- coverIn = Instance.getCache().open(new URL(coverUrl), this,
- true);
+ InputStream coverIn;
try {
- return new Image(coverIn);
- } finally {
- coverIn.close();
+ coverIn = Instance.getCache().open(new URL(coverUrl), this,
+ true);
+ try {
+ return new Image(coverIn);
+ } finally {
+ coverIn.close();
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
}
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
}
}
return null;
}
- @Override
- protected List> getChapters(Progress pg) {
- List> urls = new ArrayList>();
+ private String getVal(String[] tab, int i) {
+ String val = "";
- int i = 0;
- Element doc = getSourceNode();
- Elements chapEls = doc.getElementsByClass("chapters").first()
- .getElementsByTag("li");
- for (Element chapEl : chapEls) {
- Element titleEl = chapEl.getElementsByTag("h5").first();
- String title = StringUtils.unhtml(titleEl.text()).trim();
+ if (i < tab.length) {
+ val = StringUtils.unhtml(tab[i]);
+ int pos = val.indexOf(":");
+ if (pos >= 0) {
+ val = val.substring(pos + 1).trim();
+ }
+ }
- // because Atril does not support strange file names
- title = Integer.toString(chapEls.size() - i);
+ return val;
+ }
- Element linkEl = chapEl.getElementsByTag("h5").first()
- .getElementsByTag("a").first();
- String link = linkEl.absUrl("href");
+ @Override
+ protected List> getChapters(Progress pg)
+ throws IOException {
+ List> urls = new ArrayList>();
- try {
- urls.add(new AbstractMap.SimpleEntry(title,
- new URL(link)));
- } catch (MalformedURLException e) {
- Instance.getTraceHandler().error(e);
+ Element doc = getSourceNode();
+ Element table = doc.getElementsByClass("table").first();
+ if (table != null) {
+ for (Element tr : table.getElementsByTag("tr")) {
+ Element a = tr.getElementsByTag("a").first();
+ if (a != null) {
+ String name = StringUtils.unhtml(a.text()).trim();
+ URL url = new URL(a.absUrl("href"));
+ urls.add(new AbstractMap.SimpleEntry(name, url));
+ }
}
-
- i++;
}
- Collections.reverse(urls);
return urls;
}
@@ -197,13 +212,16 @@ class MangaLel extends BasicSupport {
InputStream in = Instance.getCache().open(chapUrl, this, false);
try {
Element pageDoc = DataUtil.load(in, "UTF-8", chapUrl.toString());
- Elements linkEls = pageDoc.getElementsByClass("img-responsive");
+ Element content = pageDoc.getElementById("content");
+ Elements linkEls = content.getElementsByTag("img");
for (Element linkEl : linkEls) {
- if (linkEl.hasAttr("data-src")) {
- builder.append("[");
- builder.append(linkEl.absUrl("data-src").trim());
- builder.append("]
");
+ if (linkEl.absUrl("src").isEmpty()) {
+ continue;
}
+
+ builder.append("[");
+ builder.append(linkEl.absUrl("src"));
+ builder.append("]
");
}
} finally {
@@ -213,32 +231,11 @@ class MangaLel extends BasicSupport {
return builder.toString();
}
- /**
- * Explode an HTML comma-separated list of values into a non-duplicate text
- * {@link List} .
- *
- * @param values
- * the comma-separated values in HTML format
- *
- * @return the full list with no duplicate in text format
- */
- private List explode(String values) {
- List list = new ArrayList();
- if (values != null && !values.isEmpty()) {
- for (String auth : values.split(",")) {
- String a = StringUtils.unhtml(auth).trim();
- if (!a.isEmpty() && !list.contains(a.trim())) {
- list.add(a);
- }
- }
- }
-
- return list;
- }
-
@Override
protected boolean supports(URL url) {
- return "manga-lel.com".equals(url.getHost())
- || "www.manga-lel.com".equals(url.getHost());
+ // URL structure (the projectId is the manga key):
+ // http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet=999
+
+ return "mangas-lecture-en-ligne.fr".equals(url.getHost());
}
}