OSDN Git Service

コメントファイルパース時, 通常コメントと投稿者コメントを分けてパース出来るようにする
[coroid/inqubus.git] / frontend / src / saccubus / FfmpegOption.java
1 /* $Id$ */
2 package saccubus;
3
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.util.Properties;
8 import org.apache.commons.lang.StringUtils;
9
10 /**
11  *
12  * @author yuki
13  */
14 public class FfmpegOption {
15
16     private final String extOption;
17     private final String mainOption;
18     private final String inOption;
19     private final String outOption;
20     private final String avfilterOption;
21     private final boolean resize;
22     private final int resizeWidth;
23     private final int resizeHeight;
24     private final boolean adjustRatio;
25
26     public static FfmpegOption load(File file) throws IOException {
27         Properties prop = new Properties();
28         try (final FileInputStream fis = new FileInputStream(file)) {
29             prop.loadFromXML(fis);
30         }
31         String ext = prop.getProperty("EXT");
32         String main = prop.getProperty("MAIN", "");
33         String in = prop.getProperty("IN", "");
34         String out = prop.getProperty("OUT", "");
35         String avfilter = prop.getProperty("AVFILTER", "");
36         boolean resize = Boolean.getBoolean(prop.getProperty("RESIZE", "false"));
37         String width = prop.getProperty("WIDTH", "");
38         String height = prop.getProperty("HEIGHT", "");
39         boolean adjust = Boolean.getBoolean(prop.getProperty("ADJST_RATIO", "true"));
40
41         if (StringUtils.isBlank(ext)) {
42             throw new IOException("変換オプションファイル書式誤り ext: "
43                     + ext + ", main: " + main + ", in: " + in + ", out: " + out + ", avfilter: " + avfilter);
44         }
45         return new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust);
46     }
47
48     public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption,
49             boolean resize, String width, String height, boolean adjust) {
50         this.extOption = (extOption.startsWith(".")) ? extOption : "." + extOption;
51         this.mainOption = mainOption;
52         this.inOption = inOption;
53         this.outOption = outOption;
54         this.avfilterOption = avfilterOption;
55         this.resize = resize;
56         this.resizeWidth = (width.isEmpty()) ? 0 : Integer.parseInt(width);
57         this.resizeHeight = (height.isEmpty()) ? 0 : Integer.parseInt(height);
58         this.adjustRatio = adjust;
59     }
60
61     public String getExtOption() {
62         return extOption;
63     }
64
65     public String getMainOption() {
66         return mainOption;
67     }
68
69     public String getInOption() {
70         return inOption;
71     }
72
73     public String getOutOption() {
74         return outOption;
75     }
76
77     public String getAvfilterOption() {
78         return avfilterOption;
79     }
80
81     public boolean isResize() {
82         return resize;
83     }
84
85     public int getResizeWidth() {
86         return resizeWidth;
87     }
88
89     public int getResizeHeight() {
90         return resizeHeight;
91     }
92
93     public boolean isAdjustRatio() {
94         return adjustRatio;
95     }
96 }