1 package saccubus.properties;
4 import java.util.Properties;
5 import java.io.IOException;
6 import java.io.FileOutputStream;
7 import java.io.FileInputStream;
8 import java.util.logging.Level;
9 import java.util.logging.Logger;
10 import saccubus.VideoSaveKind;
11 import saccubus.converter.classic.profile.LoginInfo;
12 import saccubus.converter.classic.profile.CommentGetInfo;
13 import saccubus.converter.classic.profile.Ffmpeg;
14 import saccubus.converter.classic.profile.FfmpegOption;
15 import saccubus.converter.classic.profile.GeneralSetting;
16 import saccubus.converter.classic.profile.InputFileSetting;
17 import saccubus.converter.classic.profile.OutputFileSetting;
18 import saccubus.converter.classic.profile.Profile;
19 import saccubus.converter.classic.profile.Proxy;
20 import saccubus.converter.classic.profile.SFile;
28 * 説明: ニコニコ動画の動画をコメントつきで保存
32 * 著作権: Copyright (c) 2007 PSI
42 public class SProperties {
44 private static final String PROP_FILE = "./saccubus.xml";
45 public static final String[] ShadowKindArray = {
51 private final BasicSetting basicSetting;
52 private final InputVideoSetting inputVideoSetting;
53 private final InputCommentSetting inputCommentSetting;
54 private final InputTcommentSetting inputTcommentSetting;
55 private final OutputVideoSetting outputVideoSetting;
56 private final MovieSetting movieSetting;
57 private final ConvertSetting convertSetting;
60 BasicSetting basicSetting,
61 InputVideoSetting inputVideoSetting,
62 InputCommentSetting inputCommentSetting,
63 InputTcommentSetting tcommentSetting,
64 OutputVideoSetting outputVideoSetting,
65 MovieSetting movieSetting,
66 ConvertSetting convertSetting // String videoshownum,
68 // this.saveVideo = savevideo;
69 // if (videofile.lastIndexOf(".") < videofile.lastIndexOf("\\")) {
70 // videofile += ".flv";
72 // VideoFile = new File(videofile);
74 // if (commentfile.lastIndexOf(".") < commentfile.lastIndexOf("\\")) {
75 // commentfile += ".xml";
77 // CommentFile = new File(commentfile);
79 // if (convvideofile.lastIndexOf(".") < convvideofile.lastIndexOf("\\")) {
80 // convvideofile += ".avi";
83 this.basicSetting = basicSetting;
84 this.inputVideoSetting = inputVideoSetting;
85 this.inputCommentSetting = inputCommentSetting;
86 this.inputTcommentSetting = tcommentSetting;
87 this.outputVideoSetting = outputVideoSetting;
88 this.movieSetting = movieSetting;
89 this.convertSetting = convertSetting;
92 public Profile toProfile() throws IOException {
93 return new ProfileBuilder().build();
96 private class ProfileBuilder {
98 private Profile build() throws IOException {
99 GeneralSetting generalSetting = buildGeneralSetting();
100 LoginInfo loginInfo = buildLoginInfo();
101 InputFileSetting videoSetting = buildVideoSetting();
102 InputFileSetting commentSetting = buildCommentSetting();
103 CommentGetInfo commentGetInfo = buildCommentGetInfo();
104 InputFileSetting tcommentSetting = buildTcommentSetting();
105 OutputFileSetting outputFileSetting = buildOutputFileSetting();
106 Ffmpeg ffmpeg = buildFfmpeg();
108 return new Profile(generalSetting, loginInfo, videoSetting, commentSetting, commentGetInfo, tcommentSetting,
109 outputFileSetting, ffmpeg);
112 private GeneralSetting buildGeneralSetting() {
113 final BasicSetting basic = getBasicSetting();
114 return new GeneralSetting(basic.getTempDir());
117 private LoginInfo buildLoginInfo() {
118 final BasicSetting basic = getBasicSetting();
119 Proxy proxy = Proxy.NO_PROXY;
120 if (basic.isProxyUse()) {
121 proxy = new Proxy(basic.getProxyHost(), basic.getProxyPort());
123 final LoginInfo loginInfo = new LoginInfo(basic.getUser().getMail(), basic.getUser().getPassword(), proxy);
127 private InputFileSetting buildVideoSetting() {
128 final InputVideoSetting setting = getInputVideoSetting();
129 // Nicobrowserダウンロードファイルの場合は常にファイル指定.
130 final boolean isFile = (!setting.isAutoNaming() || setting.getProcessKind() == VideoSaveKind.NICOBROWSER);
132 if (setting.getProcessKind() == VideoSaveKind.NICOBROWSER) {
133 video = setting.getNicoBrowserFile();
135 if (setting.isAutoNaming()) {
136 video = setting.getFolder();
138 video = setting.getFile();
141 final SFile videoFile = new SFile(isFile, video);
142 // Nicobrowserダウンロードファイルは削除対象にならない.
143 boolean delete = setting.isDeleteAfterConvert() && (setting.getProcessKind() != VideoSaveKind.NICOBROWSER);
145 return new InputFileSetting(videoFile, (setting.getProcessKind() == VideoSaveKind.SAVE), delete);
148 private InputFileSetting buildCommentSetting() {
149 return createCommentSetting(getInputCommentSetting());
152 private CommentGetInfo buildCommentGetInfo() {
153 final InputCommentSetting setting = getInputCommentSetting();
154 return new CommentGetInfo(setting.isSelfAdjustNumOfComment(), setting.getNumOfComment(), setting.isReduceComment());
157 private InputFileSetting buildTcommentSetting() {
158 return createCommentSetting(getInputTcommentSetting());
161 private InputFileSetting createCommentSetting(saccubus.properties.InputFileSetting<Boolean> setting) {
162 SFile file = createSFile(setting);
164 return new InputFileSetting(file, setting.getProcessKind().booleanValue(), setting.isDeleteAfterConvert());
168 private SFile createSFile(ProcessFileSetting<Boolean> setting) {
170 if (setting.isAutoNaming()) {
171 f = setting.getFolder();
173 f = setting.getFile();
175 final SFile file = new SFile(!setting.isAutoNaming(), f);
179 private OutputFileSetting buildOutputFileSetting() {
180 final OutputVideoSetting setting = getOutputVideoSetting();
182 SFile file = createSFile(setting);
183 return new OutputFileSetting(file, setting.getProcessKind().booleanValue(), !setting.isCutIdName(), setting.
184 isAddComment(), setting.isAddTcomment());
187 private Ffmpeg buildFfmpeg() throws IOException {
188 final MovieSetting movie = getMovieSetting();
189 final ConvertSetting conv = getConvertSetting();
191 FfmpegOption fo = movie.getFfmpegOption();
192 if (movie.getOptionFile() != null) {
194 fo = FfmpegOption.load(movie.getOptionFile());
195 } catch (IOException ex) {
196 throw new IOException("オプションファイルの書式が誤っています:" + movie.getOptionFile().getName(), ex);
204 conv.isVhookDisabled(),
205 conv.getMaxNumOfComment(),
208 conv.getShadowIndex(),
209 conv.isShowConverting(),
210 conv.isSelfAdjustFontSize(),
211 conv.isCommentOpaque(),
212 conv.getNgSetting());
216 public static void saveSetting(SProperties setting) {
217 final Properties prop = new Properties();
218 setting.getBasicSetting().save(prop);
219 setting.getInputVideoSetting().save(prop);
220 setting.getInputCommentSetting().save(prop);
221 setting.getInputTcommentSetting().save(prop);
222 setting.getOutputVideoSetting().save(prop);
223 setting.getMovieSetting().save(prop);
224 setting.getConvertSetting().save(prop);
226 prop.storeToXML(new FileOutputStream(PROP_FILE), "settings");
227 } catch (IOException ex) {
228 Logger.getLogger(SProperties.class.getName()).log(Level.SEVERE, "コンフィグファイルの保存に失敗", ex);
232 public static SProperties loadSetting(String user, String password) {
233 Properties prop = new Properties();
235 prop.loadFromXML(new FileInputStream(PROP_FILE));
236 } catch (IOException ex) {
237 Logger.getLogger(SProperties.class.getName()).log(Level.INFO, "コンフィグファイルが存在しないため自動生成します", ex);
240 return new SProperties(
241 BasicSetting.load(prop, user, password),
242 InputVideoSetting.load(prop),
243 InputCommentSetting.load(prop),
244 InputTcommentSetting.load(prop),
245 OutputVideoSetting.load(prop),
246 MovieSetting.load(prop),
247 ConvertSetting.load(prop));
250 public BasicSetting getBasicSetting() {
254 public InputVideoSetting getInputVideoSetting() {
255 return inputVideoSetting;
258 public InputCommentSetting getInputCommentSetting() {
259 return inputCommentSetting;
262 public InputTcommentSetting getInputTcommentSetting() {
263 return inputTcommentSetting;
266 public OutputVideoSetting getOutputVideoSetting() {
267 return outputVideoSetting;
270 public MovieSetting getMovieSetting() {
274 public ConvertSetting getConvertSetting() {
275 return convertSetting;