OSDN Git Service

WayBackKey, WayBackTimeをNicoCacneImplのフィールドから削除しコメント用情報クラスに移す.
[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.CommentInfo;
10 import saccubus.net.NicoClient;
11 import saccubus.net.TextProgressListener;
12 import saccubus.net.VideoInfo;
13
14 /**
15  *
16  * @author yuki
17  */
18 public class CommentFileWebGetter extends TcommFileWebGetter {
19
20     private final boolean autoCommentNum;
21     private final int backComment;
22     private final CommentInfo commentInfo;
23
24     CommentFileWebGetter(NicoClient client, VideoInfo vi, CommentInfo ci, boolean autoCommentNum, int backComment) {
25         super(client, vi);
26         this.autoCommentNum = autoCommentNum;
27         this.backComment = backComment;
28         this.commentInfo = ci;
29     }
30
31     @Override
32     public File get(File file, TextProgressListener listener) throws IOException {
33         String com = Integer.toString(backComment);
34         if (this.autoCommentNum) {
35             com = getBackCommentFromLength(getVideoInfo(), com);
36         }
37
38         File res = getClient().getComment(getVideoInfo(), getCommentInfo(), file, listener, com);
39         if (res == null) {
40             throw new IOException("コメントファイルのダウンロードに失敗しました。");
41         }
42         return res;
43     }
44
45     private String getBackCommentFromLength(VideoInfo vi, String def) {
46         final int videoLength  = vi.getVideoLength();
47                 if (videoLength < 0) {
48                         return def;
49                 } else if (videoLength >= 0 && videoLength < 60) {
50                         return "100";
51                 } else if (videoLength >= 60 && videoLength < 300) {
52                         return "250";
53                 } else if (videoLength >= 300 && videoLength < 600) {
54                         return "500";
55                 } else {
56                         return "1000";
57                 }
58     }
59
60     private CommentInfo getCommentInfo() {
61         return commentInfo;
62     }
63 }