X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FEHentai.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FEHentai.java;h=eae377c81d9feb53d5bdb2dcdda21623227d348d;hb=f0608ab10e762c1aed9608720b97c1901b5e2614;hp=0000000000000000000000000000000000000000;hpb=70c9b112926f1cf95b2fddd0bb504ab37d6ddd1e;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/EHentai.java b/src/be/nikiroo/fanfix/supported/EHentai.java new file mode 100644 index 0000000..eae377c --- /dev/null +++ b/src/be/nikiroo/fanfix/supported/EHentai.java @@ -0,0 +1,264 @@ +package be.nikiroo.fanfix.supported; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Scanner; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.data.Chapter; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.utils.Progress; +import be.nikiroo.utils.StringUtils; + +/** + * Support class for e-hentai.org, a website + * supporting mostly but not always NSFW comics, including some of MLP. + * + * @author niki + */ +class EHentai extends BasicSupport { + @Override + public String getSourceName() { + return "e-hentai.org"; + } + + @Override + protected MetaData getMeta(URL source, InputStream in) throws IOException { + MetaData meta = new MetaData(); + + meta.setTitle(getTitle(reset(in))); + meta.setAuthor(getAuthor(reset(in))); + meta.setDate(""); + meta.setTags(getTags(reset(in))); + meta.setSource(getSourceName()); + meta.setUrl(source.toString()); + meta.setPublisher(getSourceName()); + meta.setUuid(source.toString()); + meta.setLuid(""); + meta.setLang("EN"); + meta.setSubject("Furry"); + meta.setType(getType().toString()); + meta.setImageDocument(true); + meta.setCover(getCover(source, reset(in))); + meta.setFakeCover(true); + + return meta; + } + + @Override + public Story process(URL url, Progress pg) throws IOException { + // There is no chapters on e621, just pagination... + Story story = super.process(url, pg); + + Chapter only = new Chapter(1, null); + for (Chapter chap : story) { + only.getParagraphs().addAll(chap.getParagraphs()); + } + + story.getChapters().clear(); + story.getChapters().add(only); + + return story; + } + + @Override + protected boolean supports(URL url) { + return "e-hentai.org".equals(url.getHost()); + } + + @Override + protected boolean isHtml() { + return true; + } + + private BufferedImage getCover(URL source, InputStream in) + throws IOException { + BufferedImage author = null; + String coverLine = getKeyLine(in, "
tagsAuthor = getTagsAuthor(in); + if (!tagsAuthor.isEmpty()) { + author = tagsAuthor.get(0); + } + + return author; + } + + private List getTags(InputStream in) { + List tags = new ArrayList(); + List tagsAuthor = getTagsAuthor(in); + + for (int i = 1; i < tagsAuthor.size(); i++) { + tags.add(tagsAuthor.get(i)); + } + + return tags; + } + + private List getTagsAuthor(InputStream in) { + List tags = new ArrayList(); + String tagLine = getKeyLine(in, "", 0); + if (title != null) { + title = StringUtils.unhtml(title).trim(); + if (title.endsWith(siteName)) { + title = title.substring(0, title.length() - siteName.length()) + .trim(); + } + } + + return title; + } + + @Override + protected String getDesc(URL source, InputStream in) throws IOException { + String desc = null; + + String descLine = getKeyLine(in, "Uploader Comment", null, + "
> getChapters(URL source, InputStream in, + Progress pg) throws IOException { + List> urls = new ArrayList>(); + int last = 0; // no pool/show when only one page, first page == page 0 + + @SuppressWarnings("resource") + Scanner scan = new Scanner(in, "UTF-8"); + scan.useDelimiter(">"); + while (scan.hasNext()) { + String line = scan.next(); + if (line.contains(source.toString())) { + String page = line.substring(line.indexOf(source.toString())); + String pkey = "?p="; + if (page.contains(pkey)) { + page = page.substring(page.indexOf(pkey) + pkey.length()); + String number = ""; + while (!page.isEmpty() && page.charAt(0) >= '0' + && page.charAt(0) <= '9') { + number += page.charAt(0); + page = page.substring(1); + } + if (number.isEmpty()) { + number = "0"; + } + + int current = Integer.parseInt(number); + if (last < current) { + last = current; + } + } + } + } + + for (int i = 0; i <= last; i++) { + final String key = Integer.toString(i + 1); + final URL value = new URL(source.toString() + "?p=" + i); + urls.add(new Entry() { + public URL setValue(URL value) { + return null; + } + + public URL getValue() { + return value; + } + + public String getKey() { + return key; + } + }); + } + + return urls; + } + + @Override + protected String getChapterContent(URL source, InputStream in, int number, + Progress pg) throws IOException { + String staticSite = "https://e-hentai.org/s/"; + List pages = new ArrayList(); + + @SuppressWarnings("resource") + Scanner scan = new Scanner(in, "UTF-8"); + scan.useDelimiter("\""); + while (scan.hasNext()) { + String line = scan.next(); + if (line.startsWith(staticSite)) { + try { + pages.add(new URL(line)); + } catch (MalformedURLException e) { + Instance.syserr(new IOException( + "Parsing error, a link is not correctly parsed: " + + line, e)); + } + } + } + + if (pg == null) { + pg = new Progress(); + } + pg.setMinMax(0, pages.size()); + pg.setProgress(0); + + StringBuilder builder = new StringBuilder(); + + for (URL page : pages) { + InputStream pageIn = Instance.getCache().open(page, this, false); + try { + String link = getKeyLine(pageIn, "id=\"img\"", "src=\"", "\""); + if (link != null && !link.isEmpty()) { + builder.append("["); + builder.append(link); + builder.append("]
"); + } + pg.add(1); + } finally { + if (pageIn != null) { + pageIn.close(); + } + } + } + + pg.done(); + return builder.toString(); + } +}