/* $Id$ */
package saccubus.worker;
+import static org.apache.commons.io.FilenameUtils.getBaseName;
+import static org.apache.commons.lang.StringUtils.*;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingWorker;
-import org.apache.commons.lang.StringUtils;
import saccubus.conv.ConvertToVideoHook;
import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.ConvertProfile.HideCondition;
import saccubus.worker.profile.FfmpegProfile;
+import saccubus.worker.profile.GeneralProfile;
+import saccubus.worker.profile.OutputProfile;
+import yukihane.inqubus.util.OutputNamePattern;
import yukihane.mediainfowrapper.Info;
import yukihane.mediainfowrapper.MediaInfo;
import yukihane.mediainfowrapper.Size;
-import saccubus.worker.profile.ConvertProfile.HideCondition;
import yukihane.swf.Cws2Fws;
/**
* @param output 変換後出力動画.
* @throws IOException 変換失敗.
*/
- public Convert(ConvertProfile profile, File video, File comment, File output) throws IOException {
+ public Convert(ConvertProfile profile, File video, File comment) {
this.profile = profile;
this.videoFile = video;
this.commentFile = comment;
- this.outputFile = output;
+
+ final GeneralProfile gene = profile.getGeneralProfile();
+ final OutputProfile outprof = profile.getOutputProfile();
+ final OutputNamePattern pattern = new OutputNamePattern(outprof.getFileName());
+ final String id = outprof.getVideoId();
+ pattern.setId(isNotEmpty(id) ? id : "");
+ final String title = outprof.getTitile();
+ pattern.setTitle(isNotEmpty(title) ? title : "");
+ final String fileName = getBaseName(video.getPath());
+ pattern.setFileName(fileName);
+ pattern.setReplaceFrom(gene.getReplaceFrom());
+ pattern.setReplaceFrom(gene.getReplaceTo());
+ this.outputFile = new File(outprof.getDir(), pattern.createFileName());
}
@Override
protected ConvertResult doInBackground() throws Exception {
try {
- transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
- final HideCondition hide = profile.getNgSetting();
- if (commentFile != null) {
+ if (profile.getOutputProfile().isCommentOverlay()) {
+ transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
+ final HideCondition hide = profile.getNgSetting();
publish(new ConvertProgress("コメントの中間ファイルへの変換中"));
- final boolean conv = ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.
+ ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.
getWord());
if (!conv) {
throw new IOException("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?");
final int code = convert();
if (code != 0) {
publish(new ConvertProgress("変換エラー:" + outputFile.getPath()));
- return new ConvertResult(false);
+ return new ConvertResult(false, null);
}
publish(new ConvertProgress("変換が正常に終了しました。"));
- return new ConvertResult(true);
+ return new ConvertResult(true, outputFile.getName());
} finally {
if (transformedComment != null && transformedComment.exists()) {
transformedComment.delete();
cmdList.add("-y");
final String[] mainOptions = ffop.getMainOption().split(" +");
for (String opt : mainOptions) {
- if (StringUtils.isNotBlank(opt)) {
+ if (isNotBlank(opt)) {
cmdList.add(opt);
}
}
final String[] inOptions = ffop.getInOption().split(" +");
for (String opt : inOptions) {
- if (StringUtils.isNotBlank(opt)) {
+ if (isNotBlank(opt)) {
cmdList.add(opt);
}
}
cmdList.add(targetVideoFile.getPath());
final String[] outOptions = ffop.getOutOption().split(" +");
for (String opt : outOptions) {
- if (StringUtils.isNotBlank(opt)) {
+ if (isNotBlank(opt)) {
cmdList.add(opt);
}
}
if (!profile.isVhookDisabled()) {
final boolean addComment = (commentFile != null);
final String vhookArg = getVhookArg(profile, addComment, transformedComment.getPath(), isHD);
- if (StringUtils.isNotBlank(vhookArg)) {
+ if (isNotBlank(vhookArg)) {
avfilterArgs.add(vhookArg);
}
}
if (!avfilterArgs.isEmpty()) {
cmdList.add("-vfilters");
- final String args = "\"" + StringUtils.join(avfilterArgs, ", ") + "\"";
+ final String args = "\"" + join(avfilterArgs, ", ") + "\"";
cmdList.add(args);
}
cmdList.add(outputFile.getPath());
private static List<String> createAvfilterOptions(String avfilterOption) {
final List<String> avfilterArgs = new ArrayList<String>();
- if (StringUtils.isNotBlank(avfilterOption)) {
+ if (isNotBlank(avfilterOption)) {
avfilterArgs.add(avfilterOption);
}
return avfilterArgs;