OSDN Git Service

コマンドラインからのダウンロード処理実装
[coroid/inqubus.git] / frontend / src / saccubus / prompt / DownloadProfileImpl.java
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package saccubus.prompt;
6
7 import java.io.File;
8 import saccubus.worker.profile.CommentProfile;
9 import saccubus.worker.profile.DownloadProfile;
10 import saccubus.worker.profile.GeneralProfile;
11 import saccubus.worker.profile.LoginProfile;
12 import saccubus.worker.profile.ProxyProfile;
13 import saccubus.worker.profile.VideoProfile;
14 import yukihane.inqubus.Config;
15
16 /**
17  *
18  * @author user
19  */
20 public class DownloadProfileImpl implements DownloadProfile {
21
22     private final LoginProfile loginProfile;
23     private final ProxyProfile proxyProfile;
24     private final VideoProfile videoProfile;
25     private final CommentProfile commentProfile;
26     private final GeneralProfile generalProfile;
27
28     DownloadProfileImpl(final String mail, final String pass, final long time) {
29         this.loginProfile = new LoginProfile() {
30
31             @Override
32             public String getMail() {
33                 return mail;
34             }
35
36             @Override
37             public String getPassword() {
38                 return pass;
39             }
40         };
41
42         this.proxyProfile = new ProxyProfileImpl();
43         this.videoProfile = new VideoProfileImpl();
44         this.commentProfile = new CommentProfileImpl(time);
45         this.generalProfile = new GeneralProfileImpl();
46     }
47
48     @Override
49     public LoginProfile getLoginInfo() {
50         return loginProfile;
51     }
52
53     @Override
54     public ProxyProfile getProxyProfile() {
55         return this.proxyProfile;
56     }
57
58     @Override
59     public VideoProfile getVideoProfile() {
60         return this.videoProfile;
61     }
62
63     @Override
64     public CommentProfile getCommentProfile() {
65         return this.commentProfile;
66     }
67
68     @Override
69     public GeneralProfile getGeneralProfile() {
70         return this.generalProfile;
71     }
72 }
73
74 class ProxyProfileImpl implements ProxyProfile {
75
76     private final boolean use;
77     private final String host;
78     private final int port;
79
80     ProxyProfileImpl() {
81         final Config p = Config.INSTANCE;
82         use = p.getProxyUse();
83         host = p.getProxyHost();
84         port = Integer.parseInt(p.getProxyPort());
85     }
86
87     @Override
88     public boolean use() {
89         return use;
90     }
91
92     @Override
93     public String getHost() {
94         return host;
95     }
96
97     @Override
98     public int getPort() {
99         return port;
100     }
101 }
102
103 class VideoProfileImpl implements VideoProfile {
104
105     private final boolean download;
106     private final File dir;
107     private final String fileName;
108
109     VideoProfileImpl() {
110         final Config p = Config.INSTANCE;
111         this.download = !p.getVideoUseLocal();
112         this.dir = new File(p.getVideoDir());
113         this.fileName = p.getVideoFileNamePattern();
114     }
115
116     @Override
117     public boolean isDownload() {
118         return download;
119     }
120
121     @Override
122     public File getDir() {
123         return dir;
124     }
125
126     @Override
127     public String getFileName() {
128         return fileName;
129     }
130
131     @Override
132     public File getLocalFile() {
133         return getDir();
134     }
135 }
136
137 class CommentProfileImpl implements CommentProfile {
138
139     private final int lengthRelatedCommentSize;
140     private final int perMinCommentSize;
141     private final boolean disablePerMinComment;
142     private final long backLogPoint;
143     private final boolean download;
144     private final File dir;
145     private final String fileName;
146
147     CommentProfileImpl(final long backLogPoint) {
148         final Config p = Config.INSTANCE;
149         this.lengthRelatedCommentSize = (p.getCommentSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentSizeManual());
150         this.perMinCommentSize = (p.getCommentMinSizeAutosize()) ? -1 : Integer.parseInt(p.getCommentMinSizeManual());
151         // TODO disablePerMinComment がデフォルト設定値に無い
152         this.disablePerMinComment = false;
153         this.backLogPoint = backLogPoint;
154         this.download = !p.getCommentUseLocal();
155         this.dir = new File(p.getCommentDir());
156         this.fileName = p.getCommentFileNamePattern();
157     }
158
159     @Override
160     public int getLengthRelatedCommentSize() {
161         return lengthRelatedCommentSize;
162     }
163
164     @Override
165     public boolean isDisablePerMinComment() {
166         return disablePerMinComment;
167     }
168
169     @Override
170     public int getPerMinCommentSize() {
171         return perMinCommentSize;
172     }
173
174     @Override
175     public long getBackLogPoint() {
176         return backLogPoint;
177     }
178
179     @Override
180     public boolean isDownload() {
181         return download;
182     }
183
184     @Override
185     public File getDir() {
186         return dir;
187     }
188
189     @Override
190     public String getFileName() {
191         return fileName;
192     }
193
194     @Override
195     public File getLocalFile() {
196         return getDir();
197     }
198 }
199
200 class GeneralProfileImpl implements GeneralProfile {
201
202     private final String replaceFrom;
203     private final String replaceTo;
204
205     GeneralProfileImpl() {
206         final Config p = Config.INSTANCE;
207         this.replaceFrom = p.getReplaceFrom();
208         this.replaceTo = p.getReplaceTo();
209     }
210
211     @Override
212     public String getReplaceFrom() {
213         return replaceFrom;
214     }
215
216     @Override
217     public String getReplaceTo() {
218         return replaceTo;
219     }
220 }