/* $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();
+ 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
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;
public class ConvertResult {
private final boolean resultValue;
+ private final String title;
- ConvertResult(boolean b) {
+ ConvertResult(boolean b, String title) {
this.resultValue = b;
+ this.title = title;
}
public boolean isResultValue() {
return resultValue;
}
+
+ public String getTitle() {
+ return title;
+ }
}
// }
@Override
protected DownloadResult doInBackground() throws Exception {
- if (!needsDownload(profile)) {
- publish(new DownloadProgress("何もすることがありません"));
- return new DownloadResult(true);
- }
publish(new DownloadProgress("ログイン中"));
checkStop();
File videoFile;
- GetFlvResult vf = null;
+ GetFlvResult vf;
if (profile.getVideoSetting().isDownload()) {
vf = client.getFlvFile(vi, profile.getVideoSetting().getDir(), videoNamePattern,
Status.GET_INFO, true, new ProgressListener() {
} else {
videoFile = profile.getVideoSetting().getLocalFile();
}
- return new DownloadResult(true);
+ return new DownloadResult(true, videoFile, commentFile);
// TODO FFMPEG 実行開始は別タスクとして実装する.
package saccubus.worker;
+import java.io.File;
+
/**
*
* @author yuki
public class DownloadResult {
private final boolean resultValue;
+ private final File downloadVideo;
+ private final File downloadComment;
- DownloadResult(boolean b) {
+ DownloadResult(boolean b, File downloadVideo, File downloadComment) {
this.resultValue = b;
+ this.downloadVideo = downloadVideo;
+ this.downloadComment = downloadComment;
}
public boolean getResultValue() {
return resultValue;
}
+
+ public File getDownloadComment() {
+ return downloadComment;
+ }
+
+ public File getDownloadVideo() {
+ return downloadVideo;
+ }
}
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import saccubus.worker.profile.CommentProfile;
+import saccubus.worker.profile.ConvertProfile;
+import saccubus.worker.profile.FfmpegProfile;
import saccubus.worker.profile.GeneralProfile;
import saccubus.worker.profile.LoginProfile;
import saccubus.worker.profile.OutputProfile;
private final JButton btnDownload = new JButton("DOWNLOAD");
private final JButton btnCancel = new JButton("Cancel");
private final JTextField fldStatus = new JTextField();
- private Download downloadWorker;
+ private final JButton btnConv = new JButton("Conv");
+ private final JButton btnConvCancel = new JButton("ConvCancl");
+ private Download downloader;
+ private Convert converter;
public TestFrame() {
JPanel panel = new JPanel();
GroupLayout lo = new GroupLayout(panel);
panel.setLayout(lo);
- lo.setHorizontalGroup(lo.createParallelGroup()
- .addGroup(lo.createSequentialGroup()
- .addComponent(fldVideoId).addComponent(btnDownload))
- .addGroup(lo.createSequentialGroup()
- .addComponent(fldStatus).addComponent(btnCancel)));
+ lo.setHorizontalGroup(lo.createParallelGroup().addGroup(lo.createSequentialGroup().addComponent(fldVideoId).
+ addComponent(btnDownload)).addGroup(lo.createSequentialGroup().addComponent(fldStatus).addComponent(
+ btnCancel)));
- lo.setVerticalGroup(lo.createSequentialGroup()
- .addGroup(lo.createParallelGroup()
- .addComponent(fldVideoId).addComponent(btnDownload))
- .addGroup(lo.createParallelGroup()
- .addComponent(fldStatus).addComponent(btnCancel)));
+ lo.setVerticalGroup(lo.createSequentialGroup().addGroup(lo.createParallelGroup().addComponent(fldVideoId).
+ addComponent(btnDownload)).addGroup(lo.createParallelGroup().addComponent(fldStatus).addComponent(
+ btnCancel)));
setContentPane(panel);
pack();
btnDownload.addActionListener(new DownloadListener());
btnCancel.addActionListener(new CancelListener());
+ btnConv.addActionListener(new ConvertListener());
+ btnConvCancel.addActionListener(new ConvCnclListener());
+ }
+
+ private class ConvCnclListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (converter != null) {
+ converter.cancel(true);
+ }
+ }
+ }
+
+ private class ConvertListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ converter = new Convert(new MyConvProfile(), new File("out/sm9.flv"), new File("out/sm9.xml")) {
+
+ @Override
+ protected void process(List<ConvertProgress> chunks) {
+ ConvertProgress chunk = chunks.get(chunks.size() - 1);
+ fldStatus.setText(chunk.getMessage());
+ }
+
+ @Override
+ protected void done() {
+ btnConv.setEnabled(true);
+ try {
+ ConvertResult res = get();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ } catch (ExecutionException ex) {
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ btnConv.setEnabled(false);
+ converter.execute();
+
+ }
}
private class CancelListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
- if(downloadWorker != null){
- downloadWorker.cancel(true);
+ if (downloader != null) {
+ downloader.cancel(true);
}
}
}
private class DownloadListener implements ActionListener {
+
@Override
public void actionPerformed(ActionEvent e) {
- downloadWorker = new Download(new MyProfile(), fldVideoId.getText()){
+ downloader = new Download(new MyProfile(), fldVideoId.getText()) {
+
@Override
- protected void process(List<DownloadProgress> chunks){
- DownloadProgress chunk = chunks.get(chunks.size()-1);
+ protected void process(List<DownloadProgress> chunks) {
+ DownloadProgress chunk = chunks.get(chunks.size() - 1);
fldStatus.setText(chunk.getMessage());
}
@Override
- protected void done(){
+ protected void done() {
btnDownload.setEnabled(true);
try {
DownloadResult res = get();
};
btnDownload.setEnabled(false);
- downloadWorker.execute();
+ downloader.execute();
}
-
}
- public static void main(String[] args){
+ public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
});
}
- private static class MyProfile implements DownloadProfile{
+ private static class MyProfile implements DownloadProfile {
@Override
public LoginProfile getLoginInfo() {
// }
// };
// }
-
@Override
public GeneralProfile getGeneralSetting() {
return new GeneralProfile() {
}
};
}
-
}
+ private class MyConvProfile implements ConvertProfile {
+
+ @Override
+ public FfmpegProfile getFfmpegOption() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public File getFfmpeg() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isVhookDisabled() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public File getVhook() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public File getTempDir() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public File getFont() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public int getFontIndex() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isCommentOpaque() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isDisableFontSizeArrange() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public int getShadowIndex() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean isShowConverting() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public int getMaxNumOfComment() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public HideCondition getNgSetting() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public OutputProfile getOutputProfile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public GeneralProfile getGeneralProfile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
}
package saccubus.worker.classic.profile;
import java.io.File;
+import saccubus.worker.profile.GeneralProfile;
import saccubus.worker.profile.OutputProfile;
/**
}
@Override
- public OutputProfile getOutputProvile() {
+ public OutputProfile getOutputProfile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public GeneralProfile getGeneralProfile() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
+import saccubus.worker.profile.GeneralProfile;
/**
*
public boolean isAdjustRatio() {
return adjustRatio;
}
+
+ @Override
+ public GeneralProfile getGeneralSetting() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
public String getFileName() {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ @Override
+ public String getVideoId() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public String getTitile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
*/
public interface ConvertProfile {
- OutputProfile getOutputProvile();
+ OutputProfile getOutputProfile();
+
+ GeneralProfile getGeneralProfile();
FfmpegProfile getFfmpegOption();
--- /dev/null
+package saccubus.worker.profile;
+
+/**
+ * {@link saccubus.converter.Converter.Converter}が必要とするプロファイルです.
+ * Converterを使用するクライアントは, このインタフェースを実装するクラスのインスタンスで
+ * Converterへ処理させる内容を通知します.
+ * @author yuki
+ */
+public interface DownloadProfile {
+
+ LoginProfile getLoginInfo();
+
+ ProxyProfile getProxySetting();
+
+ VideoProfile getVideoSetting();
+
+ CommentProfile getCommentSetting();
+
+ GeneralProfile getGeneralSetting();
+}
int getResizeHeight();
boolean isAdjustRatio();
+
+ GeneralProfile getGeneralSetting();
}
* 変換した動画のファイル名パターン.
* {@link #isConvert()}がfalseの場合未定義.
*/
- public String getFileName();
+ String getFileName();
+
+ /**
+ * ファイル名パターンを置換するのに用いる情報.
+ * @return {@link #isConvert()}がtrueの場合に
+ * 変換した動画の動画ID.
+ * {@link #isConvert()}がfalseの場合未定義.
+ */
+ String getVideoId();
+
+ /**
+ * ファイル名パターンを置換するのに用いる情報.
+ * @return {@link #isConvert()}がtrueの場合に
+ * 変換した動画のタイトル.
+ * {@link #isConvert()}がfalseの場合未定義.
+ */
+ String getTitile();
}
--- /dev/null
+package yukihane.inqubus.util;
+
+import nicobrowser.NamePattern;
+
+/**
+ *
+ * @author yuki
+ */
+public class OutputNamePattern extends NamePattern {
+
+ private static final String FILE_NAME_PATTERN = "{filename}";
+ private String fileName = "";
+
+ public OutputNamePattern() {
+ super();
+ setIsNotLow(true);
+ }
+
+ public final void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ @Override
+ protected String replacePlaceHolder(String str) {
+ String res = super.replacePlaceHolder(str);
+ return res.replace(FILE_NAME_PATTERN, fileName);
+ }
+}