X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaLel.java;h=9929699cc43839b93e1b98752d205d562a08a845;hb=d66deb8d8b30cff6b54db352eef34a3508939f84;hp=43d0b2cff22972d6e45dc245ae4b3669ae4bfd9a;hpb=af1f506fb4bb7265645e34cd03c6c7178d6a4da7;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java
index 43d0b2c..9929699 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,127 +50,152 @@ 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.getInstance().getCache().open(new URL(coverUrl), this, true);
+ try {
+ return new Image(coverIn);
+ } finally {
+ coverIn.close();
+ }
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);
}
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
}
}
return null;
}
+ private String getVal(String[] tab, int i) {
+ String val = "";
+
+ if (i < tab.length) {
+ val = StringUtils.unhtml(tab[i]);
+ int pos = val.indexOf(":");
+ if (pos >= 0) {
+ val = val.substring(pos + 1).trim();
+ }
+ }
+
+ return val;
+ }
+
@Override
- protected List> getChapters(Progress pg) {
+ protected List> getChapters(Progress pg)
+ throws IOException {
List> urls = new ArrayList>();
- int i = 1;
Element doc = getSourceNode();
- Element chapEls = doc.getElementsByClass("chapters").first();
- for (Element chapEl : chapEls.getElementsByTag("li")) {
- Element titleEl = chapEl.getElementsByTag("h5").first();
- String title = StringUtils.unhtml(titleEl.text()).trim();
- title = Integer.toString(i++); // because Atril does not support
- // strange file names
-
- Element linkEl = chapEl.getElementsByTag("h5").first()
- .getElementsByTag("a").first();
- String link = linkEl.absUrl("href");
-
- try {
- urls.add(new AbstractMap.SimpleEntry(title,
- new URL(link)));
- } catch (MalformedURLException e) {
- Instance.getTraceHandler().error(e);
+ 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));
+ }
}
}
- Collections.reverse(urls);
return urls;
}
@@ -190,16 +208,19 @@ class MangaLel extends BasicSupport {
StringBuilder builder = new StringBuilder();
- InputStream in = Instance.getCache().open(chapUrl, this, false);
+ InputStream in = Instance.getInstance().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 {
@@ -209,32 +230,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());
}
}