OSDN Git Service

e2f284846e42b986f260f6b30e3e3c9b0a9d46c3
[coroid/inqubus.git] / frontend / src / saccubus / worker / TestFrame.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package saccubus.worker;
6
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.io.File;
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;
27
28 /**
29  *
30  * @author yuki
31  */
32 public class TestFrame extends JFrame {
33
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;
43
44     public TestFrame() {
45         JPanel panel = new JPanel();
46         GroupLayout lo = new GroupLayout(panel);
47         panel.setLayout(lo);
48
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)));
56
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)));
64
65         setContentPane(panel);
66         pack();
67
68
69         btnDownload.addActionListener(new DownloadListener());
70         btnCancel.addActionListener(new CancelListener());
71         btnConv.addActionListener(new ConvertListener());
72         btnConvCancel.addActionListener(new ConvCnclListener());
73     }
74
75     private class ConvCnclListener implements ActionListener {
76
77         @Override
78         public void actionPerformed(ActionEvent e) {
79             if (converter != null) {
80                 converter.cancel(true);
81             }
82         }
83     }
84
85     private class ConvertListener implements ActionListener {
86
87         @Override
88         public void actionPerformed(ActionEvent e) {
89             converter = new Convert(new MyConvProfile(), new File("out/sm8994079.mp4"), new File("out/sm9.xml")) {
90
91                 @Override
92                 protected void process(List<ConvertProgress> chunks) {
93                     ConvertProgress chunk = chunks.get(chunks.size() - 1);
94                     fldStatus.setText(chunk.getMessage());
95                 }
96
97                 @Override
98                 protected void done() {
99                     btnConv.setEnabled(true);
100                     try {
101                         ConvertResult res = get();
102                     } catch (InterruptedException ex) {
103                         ex.printStackTrace();
104                     } catch (ExecutionException ex) {
105                         ex.printStackTrace();
106                     }
107                 }
108             };
109
110             btnConv.setEnabled(false);
111             converter.execute();
112
113         }
114     }
115
116     private class CancelListener implements ActionListener {
117
118         @Override
119         public void actionPerformed(ActionEvent e) {
120             if (downloader != null) {
121                 downloader.cancel(true);
122             }
123         }
124     }
125
126     private class DownloadListener implements ActionListener {
127
128         @Override
129         public void actionPerformed(ActionEvent e) {
130             downloader = new Download(new MyProfile(), fldVideoId.getText()) {
131
132                 @Override
133                 protected void process(List<DownloadProgress> chunks) {
134                     DownloadProgress chunk = chunks.get(chunks.size() - 1);
135                     fldStatus.setText(chunk.getMessage());
136                 }
137
138                 @Override
139                 protected void done() {
140                     btnDownload.setEnabled(true);
141                     try {
142                         DownloadResult res = get();
143                     } catch (InterruptedException ex) {
144                         ex.printStackTrace();
145                     } catch (ExecutionException ex) {
146                         ex.printStackTrace();
147                     }
148                 }
149             };
150
151             btnDownload.setEnabled(false);
152             downloader.execute();
153
154         }
155     }
156
157     public static void main(String[] args) {
158         SwingUtilities.invokeLater(new Runnable() {
159
160             @Override
161             public void run() {
162                 TestFrame view = new TestFrame();
163                 view.setDefaultCloseOperation(EXIT_ON_CLOSE);
164                 view.setVisible(true);
165             }
166         });
167     }
168
169     private static class MyProfile implements DownloadProfile {
170
171         @Override
172         public LoginProfile getLoginInfo() {
173             return new LoginProfile() {
174
175                 @Override
176                 public String getMail() {
177                     return "yamamoto5_5963@hotmail.com";
178                 }
179
180                 @Override
181                 public String getPassword() {
182                     return "piyopiyo";
183                 }
184             };
185         }
186
187         @Override
188         public ProxyProfile getProxySetting() {
189             return new ProxyProfile() {
190
191                 @Override
192                 public boolean use() {
193                     return false;
194                 }
195
196                 @Override
197                 public String getHost() {
198                     throw new UnsupportedOperationException("Not supported yet.");
199                 }
200
201                 @Override
202                 public int getPort() {
203                     throw new UnsupportedOperationException("Not supported yet.");
204                 }
205             };
206         }
207
208         @Override
209         public VideoProfile getVideoSetting() {
210             return new VideoProfile() {
211
212                 @Override
213                 public boolean isDownload() {
214                     return true;
215                 }
216
217                 @Override
218                 public File getDir() {
219                     return new File("out");
220                 }
221
222                 @Override
223                 public String getFileName() {
224                     return "{id}";
225                 }
226
227                 @Override
228                 public File getLocalFile() {
229                     throw new UnsupportedOperationException("Not supported yet.");
230                 }
231             };
232         }
233
234         @Override
235         public CommentProfile getCommentSetting() {
236             return new CommentProfile() {
237
238                 @Override
239                 public int getLengthRelatedCommentSize() {
240                     return -1;
241                 }
242
243                 @Override
244                 public boolean isDisablePerMinComment() {
245                     return false;
246                 }
247
248                 @Override
249                 public int getPerMinCommentSize() {
250                     return -1;
251                 }
252
253                 @Override
254                 public long getBackLogPoint() {
255                     return -1;
256                 }
257
258                 @Override
259                 public boolean isDownload() {
260                     return true;
261                 }
262
263                 @Override
264                 public File getDir() {
265                     return new File("out");
266                 }
267
268                 @Override
269                 public String getFileName() {
270                     return "{id}_{title}";
271                 }
272
273                 @Override
274                 public File getLocalFile() {
275                     throw new UnsupportedOperationException("Not supported yet.");
276                 }
277             };
278         }
279
280 //        @Override
281 //        public OutputProfile getOutputFileSetting() {
282 //            return new OutputProfile() {
283 //
284 //                @Override
285 //                public boolean isConvert() {
286 //                    return false;
287 //                }
288 //
289 //                @Override
290 //                public boolean isAddComment() {
291 //                    throw new UnsupportedOperationException("Not supported yet.");
292 //                }
293 //
294 //                @Override
295 //                public File getDir() {
296 //                    throw new UnsupportedOperationException("Not supported yet.");
297 //                }
298 //
299 //                @Override
300 //                public String getFileName() {
301 //                    throw new UnsupportedOperationException("Not supported yet.");
302 //                }
303 //            };
304 //        }
305         @Override
306         public GeneralProfile getGeneralSetting() {
307             return new GeneralProfile() {
308
309                 @Override
310                 public String getReplaceFrom() {
311                     return "<>\\/#";
312                 }
313
314                 @Override
315                 public String getReplaceTo() {
316                     return "_";
317                 }
318             };
319         }
320     }
321
322     private class MyConvProfile implements ConvertProfile {
323
324         @Override
325         public FfmpegProfile getFfmpegOption() {
326             return new FfmpegProfile() {
327
328                 @Override
329                 public String getExtOption() {
330                     return "";
331                 }
332
333                 @Override
334                 public String getInOption() {
335                     return "";
336                 }
337
338                 @Override
339                 public String getMainOption() {
340                     return "";
341                 }
342
343                 @Override
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";
346                 }
347
348                 @Override
349                 public String getAvfilterOption() {
350                     return "";
351                 }
352
353                 @Override
354                 public boolean isResize() {
355                     return false;
356                 }
357
358                 @Override
359                 public int getResizeWidth() {
360                     throw new UnsupportedOperationException("Not supported yet.");
361                 }
362
363                 @Override
364                 public int getResizeHeight() {
365                     throw new UnsupportedOperationException("Not supported yet.");
366                 }
367
368                 @Override
369                 public boolean isAdjustRatio() {
370                     throw new UnsupportedOperationException("Not supported yet.");
371                 }
372
373                 @Override
374                 public GeneralProfile getGeneralSetting() {
375                     throw new UnsupportedOperationException("Not supported yet.");
376                 }
377             };
378         }
379
380         @Override
381         public File getFfmpeg() {
382            return new File("bin/ffmpeg.exe");
383         }
384
385         @Override
386         public boolean isVhookDisabled() {
387             return true;
388         }
389
390         @Override
391         public File getVhook() {
392             throw new UnsupportedOperationException("Not supported yet.");
393         }
394
395         @Override
396         public File getTempDir() {
397             return new File("out");
398         }
399
400         @Override
401         public File getFont() {
402             throw new UnsupportedOperationException("Not supported yet.");
403         }
404
405         @Override
406         public int getFontIndex() {
407             throw new UnsupportedOperationException("Not supported yet.");
408         }
409
410         @Override
411         public boolean isCommentOpaque() {
412             throw new UnsupportedOperationException("Not supported yet.");
413         }
414
415         @Override
416         public boolean isDisableFontSizeArrange() {
417             throw new UnsupportedOperationException("Not supported yet.");
418         }
419
420         @Override
421         public int getShadowIndex() {
422             throw new UnsupportedOperationException("Not supported yet.");
423         }
424
425         @Override
426         public boolean isShowConverting() {
427             throw new UnsupportedOperationException("Not supported yet.");
428         }
429
430         @Override
431         public int getMaxNumOfComment() {
432             throw new UnsupportedOperationException("Not supported yet.");
433         }
434
435         @Override
436         public HideCondition getNgSetting() {
437             throw new UnsupportedOperationException("Not supported yet.");
438         }
439
440         @Override
441         public OutputProfile getOutputProfile() {
442             return new OutputProfile() {
443
444                 @Override
445                 public boolean isConvert() {
446                     return true;
447                 }
448
449                 @Override
450                 public boolean isAddComment() {
451                     return false;
452                 }
453
454                 @Override
455                 public File getDir() {
456                     return new File("out");
457                 }
458
459                 @Override
460                 public String getFileName() {
461                     return "outconv";
462                 }
463
464                 @Override
465                 public String getVideoId() {
466                     return "";
467                 }
468
469                 @Override
470                 public String getTitile() {
471                     return "";
472                 }
473             };
474         }
475
476         @Override
477         public GeneralProfile getGeneralProfile() {
478             return new GeneralProfile() {
479
480                 @Override
481                 public String getReplaceFrom() {
482                     return "";
483                 }
484
485                 @Override
486                 public String getReplaceTo() {
487                     return "";
488                 }
489             };
490         }
491     }
492 }