X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=supported%2FBasicSupport.java;h=bcfcca1bdbb16cfd3bd8849e8fdb2bfb55a22de0;hp=0a5ec3686e1be43c52a328d1a1be86e805ad21fe;hb=258e065f81071a861711ef935dca3ec5563f4360;hpb=bff19b54d345ceb9e14aef616b53c013e93a0417 diff --git a/supported/BasicSupport.java b/supported/BasicSupport.java index 0a5ec36..bcfcca1 100644 --- a/supported/BasicSupport.java +++ b/supported/BasicSupport.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Scanner; import java.util.Map.Entry; +import org.json.JSONException; import org.json.JSONObject; import org.jsoup.helper.DataUtil; import org.jsoup.nodes.Document; @@ -271,7 +272,12 @@ public abstract class BasicSupport { pg.setProgress(30); Story story = new Story(); + MetaData meta = getMeta(); + meta.setType(getType().toString()); + meta.setSource(getType().getSourceName()); + meta.setPublisher(getType().getSourceName()); + if (meta.getCreationDate() == null || meta.getCreationDate().trim().isEmpty()) { meta.setCreationDate(bsHelper @@ -347,6 +353,8 @@ public abstract class BasicSupport { scan.useDelimiter("\0"); try { return new JSONObject(scan.next()); + } catch (JSONException e) { + throw new IOException(e); } finally { scan.close(); } @@ -374,7 +382,25 @@ public abstract class BasicSupport { sourceNode = loadDocument(source); try { - return doProcess(pg); + Story story = doProcess(pg); + + // Check for "no chapters" stories + if (story.getChapters().isEmpty() + && story.getMeta().getResume() != null + && !story.getMeta().getResume().getParagraphs().isEmpty()) { + Chapter resume = story.getMeta().getResume(); + resume.setName(""); + resume.setNumber(1); + story.getChapters().add(resume); + story.getMeta().setWords(resume.getWords()); + + String descChapterName = Instance.getInstance().getTrans() + .getString(StringId.DESCRIPTION); + resume = new Chapter(0, descChapterName); + story.getMeta().setResume(resume); + } + + return story; } finally { close(); } @@ -414,7 +440,7 @@ public abstract class BasicSupport { story.setChapters(new ArrayList()); List> chapters = getChapters(pgGetChapters); pgGetChapters.done(); // 20% - + if (chapters != null) { Progress pgChaps = new Progress("Extracting chapters", 0, chapters.size() * 300); @@ -445,10 +471,11 @@ public abstract class BasicSupport { words += cc.getWords(); story.getChapters().add(cc); - story.getMeta().setWords(words); i++; } + + story.getMeta().setWords(words); pgChaps.setName("Extracting chapters"); pgChaps.done(); @@ -471,7 +498,8 @@ public abstract class BasicSupport { * the chapter name * @param content * the content of the chapter - * @return the {@link Chapter} + * + * @return the {@link Chapter}, never NULL * * @throws IOException * in case of I/O error