OSDN Git Service

Profileインタフェースを導入し, 従来のProfileクラスはclassicへ移動
[coroid/inqubus.git] / frontend / src / saccubus / converter / filegetter / WebFileInstanciator.java
1 /* $Id$ */
2 package saccubus.converter.filegetter;
3
4 import java.io.IOException;
5 import java.text.Normalizer;
6 import saccubus.ConvertStopFlag;
7 import saccubus.converter.classic.profile.Proxy;
8 import saccubus.net.NicoClient;
9 import saccubus.net.VideoInfo;
10
11 /**
12  * 動画ファイル, コメントファイルなど必要なファイルのうち, 1つでもダウンロード処理を必要とする場合のインスタンス化クラス.
13  * @author yuki
14  */
15 public class WebFileInstanciator extends FileInstanciator {
16
17     private final NicoClient client;
18     private final VideoInfo videoInfo;
19
20     WebFileInstanciator(
21             ConvertStopFlag stopFlag,
22             InstanciationType videoType,
23             CommentInstanciationType commentType,
24             InstanciationType tcommType,
25             LoginInfo li,
26             String tag,
27             String time) throws IOException {
28         super(videoType, commentType, tcommType, tag);
29
30         if (li.getMail() == null || li.getPass() == null || li.getMail().equals("") || li.getPass().equals("")) {
31             throw new IllegalArgumentException("メールアドレスかパスワードが空白です。");
32         }
33
34         String host;
35         int port;
36         if (li.getProxy() != Proxy.NO_PROXY) {
37             host = li.getProxy().getHost();
38             port = li.getProxy().getPort();
39         } else {
40             host = null;
41             port = -1;
42         }
43         client = new NicoClient(li.getMail(), li.getPass(), stopFlag, host, port);
44
45         if (!client.isLoggedIn()) {
46             throw new IOException("ログインに失敗");
47         }
48
49         try {
50             videoInfo = client.getVideoInfo(tag, time);
51         } catch (IOException ex) {
52             throw new IOException(tag + "の情報の取得に失敗", ex);
53         }
54
55         if (videoType.isDoanload()) {
56             setVideoFileGetter(new VideoFileWebGetter(client, videoInfo));
57         }
58
59         if (commentType.isDoanload()) {
60             setCommentFileGetter(new CommentFileWebGetter(client, videoInfo, commentType.isAutoCommentNum(),
61                     commentType.getBackComment()));
62         }
63
64         if (tcommType.isDoanload()) {
65             setTcommFileGetter(new TcommFileWebGetter(client, videoInfo));
66         }
67     }
68
69     /**
70      * 動画のタイトルを取得する。
71      * 実際の動画タイトルはファイル名に用いることが出来ない文字を含んである場合があるため、ファイル名に適合するように編集した値が返る。
72      * @return
73      */
74     @Override
75     public String getVideoTitle() {
76         String name = videoInfo.getVideoTitle();
77         name = Normalizer.normalize(name, Normalizer.Form.NFKC);
78         name = name.replaceAll("[\\\\/:*?\"<>|.]", "_");
79         name = name.replace('\u2212', '\uff0d'); // - U+2212(MINUS SIGN) -> U+FF0D(FULLWIDTH HYPHEN-MINUS)
80         name = name.replace('\u301c', '\uff5e'); // ~ U+301C(WAVE DASH) -> U+FF5E(FULLWIDTH TILDE)
81         name = name.replace('\u223c', '\uff5e'); // ~ U+223C(TILDE OPERATOR) -> U+FF5E(FULLWIDTH TILDE)
82         name = name.replace('\u00a2', '\uffe0'); // ¢ U+00A2(CENT SIGN) -> U+FFE0(FULLWIDTH CENT SIGN)
83         name = name.replace('\u00a3', '\uffe1'); // £ U+00A3(POUND SIGN) -> U+FFE1(FULLWIDTH POUND SIGN)
84         name = name.replace('\u00ac', '\uffe2'); // ¬ U+00AC(NOT SIGN) -> U+FFE2(FULLWIDHT NOT SIGN)
85         return name;
86     }
87 }