X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaLel.java;h=9929699cc43839b93e1b98752d205d562a08a845;hb=a5d1f0e6320710cc4c8163adf2dc402e8f05fb96;hp=1ba51bc0f5d8a5c32a0341526a5aac142ae3fff6;hpb=c4cefaa04ec122fc02efb6542451a31fdf722c32;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/supported/MangaLel.java b/src/be/nikiroo/fanfix/supported/MangaLel.java
deleted file mode 100644
index 1ba51bc..0000000
--- a/src/be/nikiroo/fanfix/supported/MangaLel.java
+++ /dev/null
@@ -1,241 +0,0 @@
-package be.nikiroo.fanfix.supported;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map.Entry;
-
-import org.jsoup.helper.DataUtil;
-import org.jsoup.nodes.Element;
-import org.jsoup.select.Elements;
-
-import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.utils.Image;
-import be.nikiroo.utils.Progress;
-import be.nikiroo.utils.StringUtils;
-
-class MangaLel extends BasicSupport {
- @Override
- protected boolean isHtml() {
- return true;
- }
-
- @Override
- protected MetaData getMeta() throws IOException {
- MetaData meta = new MetaData();
-
- meta.setTitle(getTitle());
- meta.setAuthor(getAuthor());
- meta.setDate(getDate());
- meta.setTags(getTags());
- meta.setSource(getType().getSourceName());
- meta.setUrl(getSource().toString());
- meta.setPublisher(getType().getSourceName());
- meta.setUuid(getSource().toString());
- meta.setLuid("");
- meta.setLang("fr");
- meta.setSubject("manga");
- meta.setType(getType().toString());
- meta.setImageDocument(true);
- meta.setCover(getCover());
-
- return meta;
- }
-
- private String getTitle() {
- Element doc = getSourceNode();
- Element h4 = doc.getElementsByTag("h4").first();
- if (h4 != null) {
- return StringUtils.unhtml(h4.text()).trim();
- }
-
- return null;
- }
-
- 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("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;
- }
-
- 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();
- }
- }
- }
-
- if (!value.isEmpty()) {
- try {
- long time = StringUtils.toTime(value);
- value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
- .format(time);
- } catch (ParseException e) {
- }
- }
-
- return value;
- }
-
- @Override
- protected String getDesc() {
- Element doc = getSourceNode();
- Element tabEls = doc.getElementsByClass("presentation-projet").first();
- if (tabEls != null) {
- String[] tab = tabEls.outerHtml().split("
");
- return getVal(tab, 4);
- }
-
- return "";
- }
-
- private Image getCover() {
- Element doc = getSourceNode();
- 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 (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();
- }
- } 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)
- throws IOException {
- List> urls = new ArrayList>();
-
- 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));
- }
- }
- }
-
- return urls;
- }
-
- @Override
- protected String getChapterContent(URL chapUrl, int number, Progress pg)
- throws IOException {
- if (pg == null) {
- pg = new Progress();
- }
-
- StringBuilder builder = new StringBuilder();
-
- InputStream in = Instance.getCache().open(chapUrl, this, false);
- try {
- Element pageDoc = DataUtil.load(in, "UTF-8", chapUrl.toString());
- Element content = pageDoc.getElementById("content");
- Elements linkEls = content.getElementsByTag("img");
- for (Element linkEl : linkEls) {
- if (linkEl.absUrl("src").isEmpty()) {
- continue;
- }
-
- builder.append("[");
- builder.append(linkEl.absUrl("src"));
- builder.append("]
");
- }
-
- } finally {
- in.close();
- }
-
- return builder.toString();
- }
-
- @Override
- protected boolean supports(URL url) {
- // 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());
- }
-}