OSDN Git Service

インタフェースを再考
[coroid/inqubus.git] / frontend / src / saccubus / converter / filegetter / CommentFileWebGetter.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package saccubus.converter.filegetter;
6
7 import java.io.File;
8 import java.io.IOException;
9 import saccubus.net.NicoClient;
10 import saccubus.net.TextProgressListener;
11 import saccubus.net.VideoInfo;
12
13 /**
14  *
15  * @author yuki
16  */
17 public class CommentFileWebGetter extends TcommFileWebGetter {
18
19     private final boolean autoCommentNum;
20     private final int backComment;
21
22     CommentFileWebGetter(NicoClient client, VideoInfo vi, boolean autoCommentNum, int backComment) {
23         super(client, vi);
24         this.autoCommentNum = autoCommentNum;
25         this.backComment = backComment;
26     }
27
28     @Override
29     public File get(File file, TextProgressListener listener) throws IOException {
30         String com = Integer.toString(backComment);
31         if (this.autoCommentNum) {
32             com = getBackCommentFromLength(getVideoInfo(), com);
33         }
34
35         File res = getClient().getComment(getVideoInfo(), file, listener, com);
36         if (res == null) {
37             throw new IOException("コメントファイルのダウンロードに失敗しました。");
38         }
39         return res;
40     }
41
42     private String getBackCommentFromLength(VideoInfo vi, String def) {
43         final int videoLength  = vi.getVideoLength();
44                 if (videoLength < 0) {
45                         return def;
46                 } else if (videoLength >= 0 && videoLength < 60) {
47                         return "100";
48                 } else if (videoLength >= 60 && videoLength < 300) {
49                         return "250";
50                 } else if (videoLength >= 300 && videoLength < 600) {
51                         return "500";
52                 } else {
53                         return "1000";
54                 }
55     }
56 }