X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaLel.java;h=47efad8594a71830a33e5de698e47256c3d87616;hp=43d0b2cff22972d6e45dc245ae4b3669ae4bfd9a;hb=cfdaf6052ddc5ca44cf19f1f6d9f154cc8443024;hpb=af1f506fb4bb7265645e34cd03c6c7178d6a4da7 diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java index 43d0b2c..47efad8 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,29 +26,19 @@ 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(bsHelper.formatDate(getDate())); + meta.setTags(getTags()); meta.setUrl(getSource().toString()); - meta.setPublisher(getSourceName()); meta.setUuid(getSource().toString()); meta.setLuid(""); meta.setLang("fr"); meta.setSubject("manga"); - meta.setType(getType().toString()); meta.setImageDocument(true); meta.setCover(getCover()); @@ -57,127 +47,149 @@ 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("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("
"); + return getVal(tab, 1); + } - 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 ""; + } + + private List getTags() { + Element doc = getSourceNode(); + 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; } - for (int i = 0; i < 3; i++) { - String list = ""; - for (String item : explode(tab[i])) { - if (!list.isEmpty()) { - list = list + ", "; + 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(); } - list += item; } - 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); try { - return new Image(coverIn); - } finally { - coverIn.close(); + InputStream coverIn = Instance.getInstance().getCache() + .open(new URL(coverUrl), this, true); + try { + Image ii = new Image(coverIn); + if (ii.getSize() == 0) { + ii.close(); + throw new IOException("Empty image not accepted"); + } + + return ii; + } 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 +202,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 +224,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()); } }