OSDN Git Service

コメント追加
[coroid/inqubus.git] / frontend / src / saccubus / conv / ConvertToVideoHook.java
1 package saccubus.conv;
2
3 import java.io.*;
4 import java.util.EnumSet;
5 import java.util.Set;
6 import org.xml.sax.*;
7 import javax.xml.parsers.*;
8
9 /**
10  * <p>
11  * タイトル: さきゅばす
12  * </p>
13  *
14  * <p>
15  * 説明: ニコニコ動画の動画をコメントつきで保存
16  * </p>
17  *
18  * <p>
19  * 著作権: Copyright (c) 2007 PSI
20  * </p>
21  *
22  * <p>
23  * 会社名:
24  * </p>
25  *
26  * @author 未入力
27  * @version 1.0
28  */
29 public final class ConvertToVideoHook {
30
31     private ConvertToVideoHook() {
32     }
33
34     @Deprecated
35     public static void convert(File file, File out, String ng_id, String ng_word) throws IOException {
36         convert(EnumSet.allOf(NicoXMLReader.ProcessType.class), file, out, ng_id, ng_word);
37     }
38
39     public static void convert(Set<NicoXMLReader.ProcessType> types, File file, File out, String ng_id, String ng_word)
40             throws IOException {
41         try {
42             final Packet packet = new Packet();
43             // SAXパーサーファクトリを生成
44             final SAXParserFactory spfactory = SAXParserFactory.newInstance();
45             // SAXパーサーを生成
46             final SAXParser parser = spfactory.newSAXParser();
47             // XMLファイルを指定されたデフォルトハンドラーで処理します
48             final NicoXMLReader nico_reader = new NicoXMLReader(types, packet, ng_id, ng_word);
49
50             parser.parse(file, nico_reader);
51
52             try (final FileOutputStream fos = new FileOutputStream(out)) {
53                 packet.write(fos);
54             }
55         } catch (IOException | SAXException | ParserConfigurationException ex) {
56             throw new IOException("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?", ex);
57         }
58     }
59 }