From 9005532ff4a232aab5bb302979457d9da54948b1 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 28 Mar 2018 08:46:41 +0200 Subject: [PATCH] Fix most irregularities found by conversion tests --- src/be/nikiroo/fanfix/output/Cbz.java | 2 +- .../fanfix/supported/BasicSupport.java | 161 +++++++++--------- .../supported/BasicSupport_Deprecated.java | 1 - src/be/nikiroo/fanfix/supported/Cbz.java | 2 +- .../nikiroo/fanfix/test/ConversionTest.java | 11 ++ test/expected/cbz.cbz | Bin 1409 -> 1407 bytes test/expected/epub.epub | Bin 6261 -> 6253 bytes test/expected/html/html.info | 4 +- test/expected/info_text.info | 4 +- 9 files changed, 101 insertions(+), 84 deletions(-) diff --git a/src/be/nikiroo/fanfix/output/Cbz.java b/src/be/nikiroo/fanfix/output/Cbz.java index 490ba8f..3d90082 100644 --- a/src/be/nikiroo/fanfix/output/Cbz.java +++ b/src/be/nikiroo/fanfix/output/Cbz.java @@ -73,7 +73,7 @@ class Cbz extends BasicOutput { new FileOutputStream(new File(dir, "URL")), "UTF-8")); try { if (meta != null) { - writer.write(meta.getUuid()); + writer.write(meta.getUrl()); } } finally { writer.close(); diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index c35ed86..8154a15 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -240,15 +240,6 @@ public abstract class BasicSupport { protected void login() throws IOException { } - /** - * Prepare the support if needed before processing. - * - * @throws IOException - * on I/O error - */ - protected void preprocess() throws IOException { - } - /** * Now that we have processed the {@link Story}, close the resources if any. */ @@ -265,10 +256,9 @@ public abstract class BasicSupport { * @throws IOException * in case of I/O error */ - public Story processMeta() throws IOException { + public final Story processMeta() throws IOException { Story story = null; - preprocess(); try { story = processMeta(false, null); } finally { @@ -330,6 +320,32 @@ public abstract class BasicSupport { return story; } + /** + * Actual processing step, without the calls to other methods. + *

+ * Will convert the story resource into a fully filled {@link Story} object. + * + * @param pg + * the optional progress reporter + * + * @return the {@link Story}, never NULL + * + * @throws IOException + * in case of I/O error + */ + // TODO: add final + public Story process(Progress pg) throws IOException { + setCurrentReferer(source); + login(); + sourceNode = loadDocument(source); + + try { + return doProcess(pg); + } finally { + close(); + } + } + /** * Process the given story resource into a fully filled {@link Story} * object. @@ -342,87 +358,78 @@ public abstract class BasicSupport { * @throws IOException * in case of I/O error */ - public Story process(Progress pg) throws IOException { + public Story doProcess(Progress pg) throws IOException { if (pg == null) { pg = new Progress(); } else { pg.setMinMax(0, 100); } - setCurrentReferer(source); - login(); - sourceNode = loadDocument(source); - pg.setProgress(1); - try { - Progress pgMeta = new Progress(); - pg.addProgress(pgMeta, 10); - preprocess(); - Story story = processMeta(true, pgMeta); - if (!pgMeta.isDone()) { - pgMeta.setProgress(pgMeta.getMax()); // 10% - } + Progress pgMeta = new Progress(); + pg.addProgress(pgMeta, 10); + Story story = processMeta(true, pgMeta); + if (!pgMeta.isDone()) { + pgMeta.setProgress(pgMeta.getMax()); // 10% + } - pg.setName("Retrieving " + story.getMeta().getTitle()); + pg.setName("Retrieving " + story.getMeta().getTitle()); - Progress pgGetChapters = new Progress(); - pg.addProgress(pgGetChapters, 10); - story.setChapters(new ArrayList()); - List> chapters = getChapters(pgGetChapters); - if (!pgGetChapters.isDone()) { - pgGetChapters.setProgress(pgGetChapters.getMax()); // 20% - } + Progress pgGetChapters = new Progress(); + pg.addProgress(pgGetChapters, 10); + story.setChapters(new ArrayList()); + List> chapters = getChapters(pgGetChapters); + if (!pgGetChapters.isDone()) { + pgGetChapters.setProgress(pgGetChapters.getMax()); // 20% + } + + if (chapters != null) { + Progress pgChaps = new Progress("Extracting chapters", 0, + chapters.size() * 300); + pg.addProgress(pgChaps, 80); + + long words = 0; + int i = 1; + for (Entry chap : chapters) { + pgChaps.setName("Extracting chapter " + i); + URL chapUrl = chap.getValue(); + String chapName = chap.getKey(); + if (chapUrl != null) { + setCurrentReferer(chapUrl); + } + + pgChaps.setProgress(i * 100); + Progress pgGetChapterContent = new Progress(); + Progress pgMakeChapter = new Progress(); + pgChaps.addProgress(pgGetChapterContent, 100); + pgChaps.addProgress(pgMakeChapter, 100); + + String content = getChapterContent(chapUrl, i, + pgGetChapterContent); + if (!pgGetChapterContent.isDone()) { + pgGetChapterContent.setProgress(pgGetChapterContent + .getMax()); + } - if (chapters != null) { - Progress pgChaps = new Progress("Extracting chapters", 0, - chapters.size() * 300); - pg.addProgress(pgChaps, 80); - - long words = 0; - int i = 1; - for (Entry chap : chapters) { - pgChaps.setName("Extracting chapter " + i); - URL chapUrl = chap.getValue(); - String chapName = chap.getKey(); - if (chapUrl != null) { - setCurrentReferer(chapUrl); - } - - pgChaps.setProgress(i * 100); - Progress pgGetChapterContent = new Progress(); - Progress pgMakeChapter = new Progress(); - pgChaps.addProgress(pgGetChapterContent, 100); - pgChaps.addProgress(pgMakeChapter, 100); - - String content = getChapterContent(chapUrl, i, - pgGetChapterContent); - if (!pgGetChapterContent.isDone()) { - pgGetChapterContent.setProgress(pgGetChapterContent - .getMax()); - } - - Chapter cc = BasicSupportPara.makeChapter(this, chapUrl, i, - chapName, content, isHtml(), pgMakeChapter); - if (!pgMakeChapter.isDone()) { - pgMakeChapter.setProgress(pgMakeChapter.getMax()); - } - - words += cc.getWords(); - story.getChapters().add(cc); - story.getMeta().setWords(words); - - i++; + Chapter cc = BasicSupportPara.makeChapter(this, chapUrl, i, + chapName, content, isHtml(), pgMakeChapter); + if (!pgMakeChapter.isDone()) { + pgMakeChapter.setProgress(pgMakeChapter.getMax()); } - pgChaps.setName("Extracting chapters"); - } else { - pg.setProgress(80); + words += cc.getWords(); + story.getChapters().add(cc); + story.getMeta().setWords(words); + + i++; } - return story; - } finally { - close(); + pgChaps.setName("Extracting chapters"); + } else { + pg.setProgress(80); } + + return story; } /** diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java index 591ba58..e22724a 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport_Deprecated.java @@ -75,7 +75,6 @@ public abstract class BasicSupport_Deprecated extends BasicSupport { throw new RuntimeException("should not be used by legacy code"); } - @Override public Story process(Progress pg) throws IOException { return process(getSource(), pg); } diff --git a/src/be/nikiroo/fanfix/supported/Cbz.java b/src/be/nikiroo/fanfix/supported/Cbz.java index ca0f48d..9d71046 100644 --- a/src/be/nikiroo/fanfix/supported/Cbz.java +++ b/src/be/nikiroo/fanfix/supported/Cbz.java @@ -58,7 +58,7 @@ class Cbz extends Epub { } @Override - public Story process(Progress pg) throws IOException { + public Story doProcess(Progress pg) throws IOException { if (pg == null) { pg = new Progress(); } else { diff --git a/src/be/nikiroo/fanfix/test/ConversionTest.java b/src/be/nikiroo/fanfix/test/ConversionTest.java index 51b6deb..9d9fac3 100644 --- a/src/be/nikiroo/fanfix/test/ConversionTest.java +++ b/src/be/nikiroo/fanfix/test/ConversionTest.java @@ -216,6 +216,17 @@ class ConversionTest extends TestLauncher { .length()); } + if (expectedLines.size() != resultLines.size()) { + System.out.println(); + System.out.println("expected: ["); + for (String line : expectedLines) + System.out.println(line); + System.out.println("]"); + System.out.println("actual: ["); + for (String line : resultLines) + System.out.println(line); + System.out.println("]"); + } testCase.assertEquals(errMess + ": " + name + ": the number of lines is not the same", expectedLines.size(), resultLines.size()); diff --git a/test/expected/cbz.cbz b/test/expected/cbz.cbz index 569c3950e185a009d712f6aadfa46d9948e1aacf..28cc25b18b0a9b5733d99b8b3645e648ffcf8b4e 100644 GIT binary patch delta 526 zcmZqV{?El5;LXe;!ob17!SLCoW+Jb7J&^KYKmr^#!Q=Tn!nw+aPGyuAD0JjaMGIabmw>D4Mp`kE7BSj5<>C? zie|FrxTw1rd2?L(wcy#g<+om5vgEybVaCCi<@=t?+|IjSKQ;R4g7~%m=QIi>%lBsP zHjZd=vt+z7vC!i|z0}Fp?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