reformat
[fanfix.git] / src / be / nikiroo / fanfix / supported / InfoText.java
CommitLineData
08fe2e33
NR
1package be.nikiroo.fanfix.supported;
2
3import java.io.File;
08fe2e33 4import java.io.IOException;
08fe2e33 5import java.net.URL;
08fe2e33 6
68686a37 7import be.nikiroo.fanfix.data.MetaData;
08fe2e33
NR
8
9/**
10 * Support class for <tt>.info</tt> text files ({@link Text} files with a
11 * <tt>.info</tt> metadata file next to them).
12 * <p>
13 * The <tt>.info</tt> file is supposed to be written by this program, or
14 * compatible.
15 *
16 * @author niki
17 */
18class InfoText extends Text {
19 @Override
20 public String getSourceName() {
21 return "info-text";
22 }
23
7445f856
NR
24 protected File getInfoFile() {
25 return new File(assureNoTxt(getSourceFile()).getPath() + ".info");
26 }
68686a37 27
7445f856
NR
28 @Override
29 protected MetaData getMeta() throws IOException {
30 MetaData meta = InfoReader.readMeta(getInfoFile(), true);
31
32 // Some old .info files don't have those now required fields...
33 String test = meta.getTitle() == null ? "" : meta.getTitle();
34 test += meta.getAuthor() == null ? "" : meta.getAuthor();
35 test += meta.getDate() == null ? "" : meta.getDate();
36 test += meta.getUrl() == null ? "" : meta.getUrl();
37 if (test.isEmpty()) {
38 MetaData superMeta = super.getMeta();
39 if (meta.getTitle() == null || meta.getTitle().isEmpty()) {
40 meta.setTitle(superMeta.getTitle());
41 }
42 if (meta.getAuthor() == null || meta.getAuthor().isEmpty()) {
43 meta.setAuthor(superMeta.getAuthor());
44 }
45 if (meta.getDate() == null || meta.getDate().isEmpty()) {
46 meta.setDate(superMeta.getDate());
47 }
48 if (meta.getUrl() == null || meta.getUrl().isEmpty()) {
49 meta.setUrl(superMeta.getUrl());
08fe2e33 50 }
68686a37 51 }
7445f856
NR
52
53 return meta;
08fe2e33
NR
54 }
55
56 @Override
57 protected boolean supports(URL url) {
86d49dbc 58 return supports(url, true);
08fe2e33 59 }
08fe2e33 60}