fix custom author covers
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / cli / CliReader.java
CommitLineData
16a81ef7 1package be.nikiroo.fanfix.reader.cli;
08fe2e33
NR
2
3import java.io.IOException;
08fe2e33
NR
4import java.util.List;
5
6import be.nikiroo.fanfix.Instance;
08fe2e33
NR
7import be.nikiroo.fanfix.bundles.StringId;
8import be.nikiroo.fanfix.data.Chapter;
9import be.nikiroo.fanfix.data.MetaData;
10import be.nikiroo.fanfix.data.Paragraph;
11import be.nikiroo.fanfix.data.Story;
16a81ef7 12import be.nikiroo.fanfix.reader.BasicReader;
08fe2e33
NR
13
14/**
15 * Command line {@link Story} reader.
16 * <p>
17 * Will output stories to the console.
18 *
19 * @author niki
20 */
3727aae2 21class CliReader extends BasicReader {
211f7ddb 22 @Override
350bc060 23 public void read(boolean sync) throws IOException {
bc2ea776
NR
24 MetaData meta = getMeta();
25
26 if (meta == null) {
89cb07a6 27 throw new IOException("No story to read");
08fe2e33 28 }
08fe2e33 29
08fe2e33
NR
30 String title = "";
31 String author = "";
32
bc2ea776
NR
33 if (meta.getTitle() != null) {
34 title = meta.getTitle();
35 }
08fe2e33 36
bc2ea776
NR
37 if (meta.getAuthor() != null) {
38 author = "©" + meta.getAuthor();
39 if (meta.getDate() != null && !meta.getDate().isEmpty()) {
40 author = author + " (" + meta.getDate() + ")";
08fe2e33
NR
41 }
42 }
43
44 System.out.println(title);
45 System.out.println(author);
46 System.out.println("");
47
bc2ea776
NR
48 // TODO: progress?
49 for (Chapter chap : getStory(null)) {
08fe2e33
NR
50 if (chap.getName() != null && !chap.getName().isEmpty()) {
51 System.out.println(Instance.getTrans().getString(
52 StringId.CHAPTER_NAMED, chap.getNumber(),
53 chap.getName()));
54 } else {
55 System.out.println(Instance.getTrans().getString(
56 StringId.CHAPTER_UNNAMED, chap.getNumber()));
57 }
58 }
59 }
60
edd46289 61 public void read(int chapter) throws IOException {
bc2ea776
NR
62 MetaData meta = getMeta();
63
64 if (meta == null) {
edd46289
NR
65 throw new IOException("No story to read");
66 }
67
bc2ea776
NR
68 // TODO: progress?
69 if (chapter > getStory(null).getChapters().size()) {
08fe2e33
NR
70 System.err.println("Chapter " + chapter + ": no such chapter");
71 } else {
bc2ea776 72 Chapter chap = getStory(null).getChapters().get(chapter - 1);
08fe2e33
NR
73 System.out.println("Chapter " + chap.getNumber() + ": "
74 + chap.getName());
75
76 for (Paragraph para : chap) {
77 System.out.println(para.getContent());
78 System.out.println("");
79 }
80 }
81 }
82
211f7ddb 83 @Override
b0e88ebd 84 public void browse(String source) {
08fe2e33 85 List<MetaData> stories;
b0e88ebd 86 stories = getLibrary().getListBySource(source);
08fe2e33
NR
87
88 for (MetaData story : stories) {
89 String author = "";
90 if (story.getAuthor() != null && !story.getAuthor().isEmpty()) {
91 author = " (" + story.getAuthor() + ")";
92 }
93
94 System.out.println(story.getLuid() + ": " + story.getTitle()
95 + author);
96 }
97 }
98}