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         prop.loadFromXML(new FileInputStream(file));
29         String ext = prop.getProperty("EXT");
30         String main = prop.getProperty("MAIN", "");
31         String in = prop.getProperty("IN", "");
32         String out = prop.getProperty("OUT", "");
33         String avfilter = prop.getProperty("AVFILTER", "");
34         boolean resize = Boolean.getBoolean(prop.getProperty("RESIZE", "false"));
35         String width = prop.getProperty("WIDTH", "");
36         String height = prop.getProperty("HEIGHT", "");
37         boolean adjust = Boolean.getBoolean(prop.getProperty("ADJST_RATIO", "true"));
38
39         if (StringUtils.isBlank(ext)) {
40             throw new IOException("変換オプションファイル書式誤り ext: "
41                     + ext + ", main: " + main + ", in: " + in + ", out: " + out + ", avfilter: " + avfilter);
42         }
43         return new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust);
44     }
45
46     public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption,
47             boolean resize, String width, String height, boolean adjust) {
48         this.extOption = (extOption.startsWith(".")) ? extOption : "." + extOption;
49         this.mainOption = mainOption;
50         this.inOption = inOption;
51         this.outOption = outOption;
52         this.avfilterOption = avfilterOption;
53         this.resize = resize;
54         this.resizeWidth = (width.isEmpty()) ? 0 : Integer.parseInt(width);
55         this.resizeHeight = (height.isEmpty()) ? 0 : Integer.parseInt(height);
56         this.adjustRatio = adjust;
57     }
58
59     public String getExtOption() {
60         return extOption;
61     }
62
63     public String getMainOption() {
64         return mainOption;
65     }
66
67     public String getInOption() {
68         return inOption;
69     }
70
71     public String getOutOption() {
72         return outOption;
73     }
74
75     public String getAvfilterOption() {
76         return avfilterOption;
77     }
78
79     public boolean isResize() {
80         return resize;
81     }
82
83     public int getResizeWidth() {
84         return resizeWidth;
85     }
86
87     public int getResizeHeight() {
88         return resizeHeight;
89     }
90
91     public boolean isAdjustRatio() {
92         return adjustRatio;
93     }
94 }