*
* @author yuki
*/
-public class Ffmpeg extends SwingWorker<FfmpegResult, FfmpegProgress> {
+public class Convert extends SwingWorker<ConvertResult, ConvertProgress> {
- private static final Logger logger = Logger.getLogger(Ffmpeg.class.getName());
+ private static final Logger logger = Logger.getLogger(Convert.class.getName());
private final File commentMiddleFile;
private final File tcommMiddleFile;
private final File TMP_CWS;
private final File convertedVideoFile;
private final ConvertProfile ffmpeg;
- Ffmpeg(File commentFile, File videoFile, File convertedVideoFile, ConvertProfile ffmpeg) throws IOException {
+ Convert(ConvertProfile ffmpeg, File commentFile, File videoFile, File convertedVideoFile) throws IOException {
this.commentFile = commentFile;
this.videoFile = videoFile;
this.convertedVideoFile = convertedVideoFile;
}
@Override
- protected FfmpegResult doInBackground() throws Exception {
+ protected ConvertResult doInBackground() throws Exception {
try {
return exec();
} finally {
}
}
- private FfmpegResult exec() throws InterruptedException, IOException {
+ private ConvertResult exec() throws InterruptedException, IOException {
final HideCondition ngSetting = getFfmpeg().getNgSetting();
if (commentFile != null) {
- publish(new FfmpegProgress("コメントの中間ファイルへの変換中"));
+ publish(new ConvertProgress("コメントの中間ファイルへの変換中"));
boolean conv = ConvertToVideoHook.convert(commentFile, commentMiddleFile, ngSetting.getId(), ngSetting.
getWord());
if (!conv) {
- publish(new FfmpegProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
- return new FfmpegResult(false);
+ publish(new ConvertProgress("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?"));
+ return new ConvertResult(false);
}
}
checkStop();
// }
// }
// stopFlagReturn();
- publish(new FfmpegProgress("動画の変換を開始"));
+ publish(new ConvertProgress("動画の変換を開始"));
int code;
if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(),
false, tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
- publish(new FfmpegProgress("変換が正常に終了しました。"));
- return new FfmpegResult(true);
+ publish(new ConvertProgress("変換が正常に終了しました。"));
+ return new ConvertResult(true);
} else {
- publish(new FfmpegProgress("変換エラー:" + convertedVideoFile.getPath()));
+ publish(new ConvertProgress("変換エラー:" + convertedVideoFile.getPath()));
}
- return new FfmpegResult(false);
+ return new ConvertResult(false);
}
private int converting_video(File videoFile, File convertedVideoFile, boolean addComment, String commPath,
while ((e = ebr.readLine()) != null) {
String state = e;
if (state.startsWith("frame=")) {
- publish(new FfmpegProgress(state));
+ publish(new ConvertProgress(state));
} else if (!state.endsWith("No accelerated colorspace conversion found")) {
logger.log(Level.INFO, e);
}
--- /dev/null
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package saccubus.converter;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import saccubus.converter.profile.CommentProfile;
+import saccubus.converter.profile.GeneralProfile;
+import saccubus.converter.profile.LoginProfile;
+import saccubus.converter.profile.OutputProfile;
+import saccubus.converter.profile.Profile;
+import saccubus.converter.profile.ProxyProfile;
+import saccubus.converter.profile.VideoProfile;
+
+/**
+ *
+ * @author yuki
+ */
+public class TestFrame extends JFrame {
+
+ private static final long serialVersionUID = 1L;
+ private final JTextField fldVideoId = new JTextField();
+ private final JButton btnDownload = new JButton("DOWNLOAD");
+ private final JButton btnCancel = new JButton("Cancel");
+ private final JTextField fldStatus = new JTextField();
+ private Download downloadWorker;
+
+ 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.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());
+ }
+
+ private class CancelListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(downloadWorker != null){
+ downloadWorker.cancel(true);
+ }
+ }
+ }
+
+ private class DownloadListener implements ActionListener {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ downloadWorker = new Download(new MyProfile(), fldVideoId.getText()){
+ @Override
+ protected void process(List<DownloadProgress> chunks){
+ DownloadProgress chunk = chunks.get(chunks.size()-1);
+ fldStatus.setText(chunk.getMessage());
+ }
+
+ @Override
+ protected void done(){
+ btnDownload.setEnabled(true);
+ try {
+ DownloadResult res = get();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ } catch (ExecutionException ex) {
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ btnDownload.setEnabled(false);
+ downloadWorker.execute();
+
+ }
+
+ }
+
+ public static void main(String[] args){
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ TestFrame view = new TestFrame();
+ view.setDefaultCloseOperation(EXIT_ON_CLOSE);
+ view.setVisible(true);
+ }
+ });
+ }
+
+ private static class MyProfile implements Profile{
+
+ @Override
+ public LoginProfile getLoginInfo() {
+ return new LoginProfile() {
+
+ @Override
+ public String getMail() {
+ return "yamamoto5_5963@hotmail.com";
+ }
+
+ @Override
+ public String getPassword() {
+ return "piyopiyo";
+ }
+ };
+ }
+
+ @Override
+ public ProxyProfile getProxySetting() {
+ return new ProxyProfile() {
+
+ @Override
+ public boolean use() {
+ return false;
+ }
+
+ @Override
+ public String getHost() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public int getPort() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ }
+
+ @Override
+ public VideoProfile getVideoSetting() {
+ return new VideoProfile() {
+
+ @Override
+ public boolean isDownload() {
+ return true;
+ }
+
+ @Override
+ public File getDir() {
+ return new File("out");
+ }
+
+ @Override
+ public String getFileName() {
+ return "{id}_{title}";
+ }
+
+ @Override
+ public File getLocalFile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ }
+
+ @Override
+ public CommentProfile getCommentSetting() {
+ return new CommentProfile() {
+
+ @Override
+ public int getLengthRelatedCommentSize() {
+ return -1;
+ }
+
+ @Override
+ public boolean isDisablePerMinComment() {
+ return false;
+ }
+
+ @Override
+ public int getPerMinCommentSize() {
+ return -1;
+ }
+
+ @Override
+ public long getBackLogPoint() {
+ return -1;
+ }
+
+ @Override
+ public boolean isDownload() {
+ return true;
+ }
+
+ @Override
+ public File getDir() {
+ return new File("out");
+ }
+
+ @Override
+ public String getFileName() {
+ return "{id}_{title}";
+ }
+
+ @Override
+ public File getLocalFile() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ }
+
+ @Override
+ public OutputProfile getOutputFileSetting() {
+ return new OutputProfile() {
+
+ @Override
+ public boolean isConvert() {
+ return false;
+ }
+
+ @Override
+ public boolean isAddComment() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public File getDir() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public String getFileName() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+ }
+
+ @Override
+ public GeneralProfile getGeneralSetting() {
+ return new GeneralProfile() {
+
+ @Override
+ public String getReplaceFrom() {
+ return "<>\\/#";
+ }
+
+ @Override
+ public String getReplaceTo() {
+ return "_";
+ }
+ };
+ }
+
+ }
+
+}