2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package saccubus.worker;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
10 import java.util.List;
11 import java.util.concurrent.ExecutionException;
12 import javax.swing.GroupLayout;
13 import javax.swing.JButton;
14 import javax.swing.JFrame;
15 import javax.swing.JPanel;
16 import javax.swing.JTextField;
17 import javax.swing.SwingUtilities;
18 import saccubus.worker.profile.CommentProfile;
19 import saccubus.worker.profile.ConvertProfile;
20 import saccubus.worker.profile.FfmpegProfile;
21 import saccubus.worker.profile.GeneralProfile;
22 import saccubus.worker.profile.LoginProfile;
23 import saccubus.worker.profile.OutputProfile;
24 import saccubus.worker.profile.DownloadProfile;
25 import saccubus.worker.profile.ProxyProfile;
26 import saccubus.worker.profile.VideoProfile;
32 public class TestFrame extends JFrame {
34 private static final long serialVersionUID = 1L;
35 private final JTextField fldVideoId = new JTextField();
36 private final JButton btnDownload = new JButton("DOWNLOAD");
37 private final JButton btnCancel = new JButton("Cancel");
38 private final JTextField fldStatus = new JTextField();
39 private final JButton btnConv = new JButton("Conv");
40 private final JButton btnConvCancel = new JButton("ConvCancl");
41 private Download downloader;
42 private Convert converter;
45 JPanel panel = new JPanel();
46 GroupLayout lo = new GroupLayout(panel);
49 lo.setHorizontalGroup(lo.createParallelGroup()
50 .addGroup(lo.createSequentialGroup()
51 .addComponent(fldVideoId).addComponent(btnDownload))
52 .addGroup(lo.createSequentialGroup()
53 .addComponent(fldStatus).addComponent(btnCancel))
54 .addGroup(lo.createSequentialGroup()
55 .addComponent(btnConv).addComponent(btnConvCancel)));
57 lo.setVerticalGroup(lo.createSequentialGroup()
58 .addGroup(lo.createParallelGroup()
59 .addComponent(fldVideoId).addComponent(btnDownload))
60 .addGroup(lo.createParallelGroup()
61 .addComponent(fldStatus).addComponent(btnCancel))
62 .addGroup(lo.createParallelGroup()
63 .addComponent(btnConv).addComponent(btnConvCancel)));
65 setContentPane(panel);
69 btnDownload.addActionListener(new DownloadListener());
70 btnCancel.addActionListener(new CancelListener());
71 btnConv.addActionListener(new ConvertListener());
72 btnConvCancel.addActionListener(new ConvCnclListener());
75 private class ConvCnclListener implements ActionListener {
78 public void actionPerformed(ActionEvent e) {
79 if (converter != null) {
80 converter.cancel(true);
85 private class ConvertListener implements ActionListener {
88 public void actionPerformed(ActionEvent e) {
89 converter = new Convert(new MyConvProfile(), new File("out/sm8994079.mp4"), new File("out/sm9.xml")) {
92 protected void process(List<ConvertProgress> chunks) {
93 ConvertProgress chunk = chunks.get(chunks.size() - 1);
94 fldStatus.setText(chunk.getMessage());
98 protected void done() {
99 btnConv.setEnabled(true);
101 ConvertResult res = get();
102 } catch (InterruptedException ex) {
103 ex.printStackTrace();
104 } catch (ExecutionException ex) {
105 ex.printStackTrace();
110 btnConv.setEnabled(false);
116 private class CancelListener implements ActionListener {
119 public void actionPerformed(ActionEvent e) {
120 if (downloader != null) {
121 downloader.cancel(true);
126 private class DownloadListener implements ActionListener {
129 public void actionPerformed(ActionEvent e) {
130 downloader = new Download(new MyProfile(), fldVideoId.getText()) {
133 protected void process(List<DownloadProgress> chunks) {
134 DownloadProgress chunk = chunks.get(chunks.size() - 1);
135 fldStatus.setText(chunk.getMessage());
139 protected void done() {
140 btnDownload.setEnabled(true);
142 DownloadResult res = get();
143 } catch (InterruptedException ex) {
144 ex.printStackTrace();
145 } catch (ExecutionException ex) {
146 ex.printStackTrace();
151 btnDownload.setEnabled(false);
152 downloader.execute();
157 public static void main(String[] args) {
158 SwingUtilities.invokeLater(new Runnable() {
162 TestFrame view = new TestFrame();
163 view.setDefaultCloseOperation(EXIT_ON_CLOSE);
164 view.setVisible(true);
169 private static class MyProfile implements DownloadProfile {
172 public LoginProfile getLoginInfo() {
173 return new LoginProfile() {
176 public String getMail() {
177 return "yamamoto5_5963@hotmail.com";
181 public String getPassword() {
188 public ProxyProfile getProxySetting() {
189 return new ProxyProfile() {
192 public boolean use() {
197 public String getHost() {
198 throw new UnsupportedOperationException("Not supported yet.");
202 public int getPort() {
203 throw new UnsupportedOperationException("Not supported yet.");
209 public VideoProfile getVideoSetting() {
210 return new VideoProfile() {
213 public boolean isDownload() {
218 public File getDir() {
219 return new File("out");
223 public String getFileName() {
228 public File getLocalFile() {
229 throw new UnsupportedOperationException("Not supported yet.");
235 public CommentProfile getCommentSetting() {
236 return new CommentProfile() {
239 public int getLengthRelatedCommentSize() {
244 public boolean isDisablePerMinComment() {
249 public int getPerMinCommentSize() {
254 public long getBackLogPoint() {
259 public boolean isDownload() {
264 public File getDir() {
265 return new File("out");
269 public String getFileName() {
270 return "{id}_{title}";
274 public File getLocalFile() {
275 throw new UnsupportedOperationException("Not supported yet.");
281 // public OutputProfile getOutputFileSetting() {
282 // return new OutputProfile() {
285 // public boolean isConvert() {
290 // public boolean isAddComment() {
291 // throw new UnsupportedOperationException("Not supported yet.");
295 // public File getDir() {
296 // throw new UnsupportedOperationException("Not supported yet.");
300 // public String getFileName() {
301 // throw new UnsupportedOperationException("Not supported yet.");
306 public GeneralProfile getGeneralSetting() {
307 return new GeneralProfile() {
310 public String getReplaceFrom() {
315 public String getReplaceTo() {
322 private class MyConvProfile implements ConvertProfile {
325 public FfmpegProfile getFfmpegOption() {
326 return new FfmpegProfile() {
329 public String getExtOption() {
334 public String getInOption() {
339 public String getMainOption() {
344 public String getOutOption() {
345 return "-f ipod -g 150 -qcomp 0.7 -qmin 20 -qmax 30 -qdiff 4 -subq 6 -me_range 16 -i_qfactor 0.714286";
349 public String getAvfilterOption() {
354 public boolean isResize() {
359 public int getResizeWidth() {
360 throw new UnsupportedOperationException("Not supported yet.");
364 public int getResizeHeight() {
365 throw new UnsupportedOperationException("Not supported yet.");
369 public boolean isAdjustRatio() {
370 throw new UnsupportedOperationException("Not supported yet.");
374 public GeneralProfile getGeneralSetting() {
375 throw new UnsupportedOperationException("Not supported yet.");
381 public File getFfmpeg() {
382 return new File("bin/ffmpeg.exe");
386 public boolean isVhookDisabled() {
391 public File getVhook() {
392 throw new UnsupportedOperationException("Not supported yet.");
396 public File getTempDir() {
397 return new File("out");
401 public File getFont() {
402 throw new UnsupportedOperationException("Not supported yet.");
406 public int getFontIndex() {
407 throw new UnsupportedOperationException("Not supported yet.");
411 public boolean isCommentOpaque() {
412 throw new UnsupportedOperationException("Not supported yet.");
416 public boolean isDisableFontSizeArrange() {
417 throw new UnsupportedOperationException("Not supported yet.");
421 public int getShadowIndex() {
422 throw new UnsupportedOperationException("Not supported yet.");
426 public boolean isShowConverting() {
427 throw new UnsupportedOperationException("Not supported yet.");
431 public int getMaxNumOfComment() {
432 throw new UnsupportedOperationException("Not supported yet.");
436 public HideCondition getNgSetting() {
437 throw new UnsupportedOperationException("Not supported yet.");
441 public OutputProfile getOutputProfile() {
442 return new OutputProfile() {
445 public boolean isConvert() {
450 public boolean isCommentOverlay() {
455 public File getDir() {
456 return new File("out");
460 public String getFileName() {
465 public String getVideoId() {
470 public String getTitile() {
477 public GeneralProfile getGeneralProfile() {
478 return new GeneralProfile() {
481 public String getReplaceFrom() {
486 public String getReplaceTo() {