OSDN Git Service

Merge branch 'delete_replace'
authoryukihane <yukihane.feather@gmail.com>
Wed, 21 Mar 2012 15:07:03 +0000 (00:07 +0900)
committeryukihane <yukihane.feather@gmail.com>
Wed, 21 Mar 2012 15:07:03 +0000 (00:07 +0900)
src/nicobrowser/NamePattern.java
src/nicobrowser/NicoHttpClient.java
src/nicobrowser/config/Config.java
src/nicobrowser/gui/config/ConfigFrame.form
src/nicobrowser/gui/config/ConfigFrame.java
src/nicobrowser/main/Main.java
test/nicobrowser/NamePatternTest.java

index 49b794f..9fd64f1 100644 (file)
@@ -15,8 +15,6 @@ public class NamePattern {
     private static final String lowPattern = "{low}";
     private static Logger log = LoggerFactory.getLogger(NamePattern.class);
     private final String pattern;
-    private String replaceFrom = "";
-    private String replaceTo = "";
     private String id = "";
     private String title = "";
     private boolean isNotLow = true;
@@ -33,10 +31,8 @@ public class NamePattern {
      * @param replaceTo 禁則文字をこの文字列に置換する.
      * @param title ファイル名に用いるタイトル文字列.
      */
-    public NamePattern(String pattern, String replaceFrom, String replaceTo, String title) {
+    public NamePattern(String pattern, String title) {
         this.pattern = pattern;
-        this.replaceFrom = replaceFrom;
-        this.replaceTo = replaceTo;
         this.title = title;
     }
 
@@ -60,14 +56,6 @@ public class NamePattern {
         this.isNotLow = isNotLow;
     }
 
-    public final void setReplaceFrom(String replaceFrom) {
-        this.replaceFrom = replaceFrom;
-    }
-
-    public final void setReplaceTo(String replaceTo) {
-        this.replaceTo = replaceTo;
-    }
-
     public final void setTitle(String title) {
         this.title = title;
     }
index c27666f..adf435b 100644 (file)
@@ -823,7 +823,7 @@ public class NicoHttpClient {
             ProgressListener listener) throws IOException, URISyntaxException, HttpException, InterruptedException {
         String file = FilenameUtils.getName(fileName);
         String dir = fileName.substring(0, fileName.length() - file.length());
-        NamePattern np = new NamePattern(file, "", "", "");
+        NamePattern np = new NamePattern(file, "");
         return getFlvFile(vi, new File(dir), np, nowStatus, needLowFile, listener);
     }
 
index bb691c6..f834311 100644 (file)
@@ -1,11 +1,7 @@
 /*$Id$*/
 package nicobrowser.config;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -34,8 +30,6 @@ public final class Config {
     public static final String P_PATH_DB = "path.db";
     public static final String P_PATH_SAVEFILE = "path.savefile";
     public static final String P_SAVEFILE_PATTERN = "savefilename.pattern";
-    public static final String P_SAVEFILE_REPLACE_FROM = "savefilename.replace.from";
-    public static final String P_SAVEFILE_REPLACE_TO = "savefilename.replace.to";
     public static final String P_FILE_ENCODING = "encoding";
     public static final String P_NICOVIDEO_MAIL = "nicovideo.mail";
     public static final String P_NICOVIDEO_PASSWORD = "nicovideo.password";
@@ -108,8 +102,6 @@ public final class Config {
         updatePropertyValue(p, P_PATH_DB);
         updatePropertyValue(p, P_PATH_SAVEFILE);
         updatePropertyValue(p, P_SAVEFILE_PATTERN);
-        updatePropertyValue(p, P_SAVEFILE_REPLACE_FROM);
-        updatePropertyValue(p, P_SAVEFILE_REPLACE_TO);
 
         updatePropertyValue(p, P_DOWNLOAD_RETRY);
         updatePropertyValue(p, P_DOWNLOAD_WAIT);
@@ -155,8 +147,6 @@ public final class Config {
         props.add(savepath);
 
         props.add(P_SAVEFILE_PATTERN + "={title}");
-        props.add(P_SAVEFILE_REPLACE_FROM + "=\\/\\\\:*?\\\"<>|.");
-        props.add(P_SAVEFILE_REPLACE_TO + "=_");
 
         props.add(P_FILE_ENCODING + "=" + System.getProperty("file.encoding"));
 
@@ -260,14 +250,6 @@ public final class Config {
         return properties.getString(P_SAVEFILE_PATTERN, "{title}");
     }
 
-    public String getFileNameReplaceFrom() {
-        return properties.getString(P_SAVEFILE_REPLACE_FROM, "/\\:*?\"<>|.");
-    }
-
-    public String getFileNameReplaceTo() {
-        return properties.getString(P_SAVEFILE_REPLACE_TO, "_");
-    }
-
     /** @return feedurl.txtの文字エンコーディング. */
     public String getEncoding() {
         String res = properties.getString(P_FILE_ENCODING, System.getProperty("file.encoding"));
index d1b7cda..85fc06b 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.1" encoding="UTF-8" ?>
+<?xml version="1.0" encoding="UTF-8" ?>
 
 <Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
   <Properties>
@@ -51,7 +51,7 @@
               <Component id="jPanel3" min="-2" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
               <Component id="jPanel5" min="-2" max="-2" attributes="0"/>
-              <EmptySpace min="-2" max="-2" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
                           <EmptySpace max="-2" attributes="0"/>
                           <Component id="namePatternField" pref="399" max="32767" attributes="0"/>
                       </Group>
-                      <Group type="102" alignment="0" attributes="0">
-                          <Group type="103" groupAlignment="0" attributes="0">
-                              <Component id="replaceToLabel" alignment="0" min="-2" max="-2" attributes="0"/>
-                              <Component id="replaceFromLabel" alignment="0" min="-2" max="-2" attributes="0"/>
-                          </Group>
-                          <EmptySpace max="-2" attributes="0"/>
-                          <Group type="103" groupAlignment="0" attributes="0">
-                              <Component id="replaceFromField" alignment="0" pref="371" max="32767" attributes="0"/>
-                              <Component id="replaceToField" alignment="0" pref="371" max="32767" attributes="0"/>
-                          </Group>
-                      </Group>
                   </Group>
                   <EmptySpace max="-2" attributes="0"/>
               </Group>
                   </Group>
                   <EmptySpace max="-2" attributes="0"/>
                   <Component id="namePatternScroll" min="-2" pref="71" max="-2" attributes="0"/>
-                  <EmptySpace max="-2" attributes="0"/>
-                  <Group type="103" groupAlignment="3" attributes="0">
-                      <Component id="replaceFromLabel" alignment="3" min="-2" max="-2" attributes="0"/>
-                      <Component id="replaceFromField" alignment="3" min="-2" max="-2" attributes="0"/>
-                  </Group>
-                  <EmptySpace max="-2" attributes="0"/>
-                  <Group type="103" groupAlignment="3" attributes="0">
-                      <Component id="replaceToLabel" alignment="3" min="-2" max="-2" attributes="0"/>
-                      <Component id="replaceToField" alignment="3" min="-2" max="-2" attributes="0"/>
-                  </Group>
                   <EmptySpace max="32767" attributes="0"/>
               </Group>
           </Group>
             <Property name="text" type="java.lang.String" value="&#x547d;&#x540d;&#x898f;&#x5247;"/>
           </Properties>
         </Component>
-        <Component class="javax.swing.JLabel" name="replaceFromLabel">
-          <Properties>
-            <Property name="text" type="java.lang.String" value="&#x7f6e;&#x63db;&#x5bfe;&#x8c61;&#x6587;&#x5b57;"/>
-          </Properties>
-        </Component>
-        <Component class="javax.swing.JLabel" name="replaceToLabel">
-          <Properties>
-            <Property name="text" type="java.lang.String" value="&#x3053;&#x306e;&#x6587;&#x5b57;&#x306b;&#x7f6e;&#x63db;"/>
-          </Properties>
-        </Component>
-        <Component class="javax.swing.JTextField" name="replaceFromField">
-        </Component>
-        <Component class="javax.swing.JTextField" name="replaceToField">
-        </Component>
       </SubComponents>
     </Container>
   </SubComponents>
index ef511a3..2427ba3 100644 (file)
@@ -52,10 +52,6 @@ public class ConfigFrame extends javax.swing.JFrame {
         String filePattern = config.getFileNamePattern();
         namePatternField.setText(filePattern);
         namePatternArea.setCaretPosition(0);
-        String replaceFrom = config.getFileNameReplaceFrom();
-        replaceFromField.setText(replaceFrom);
-        String replaceTo = config.getFileNameReplaceTo();
-        replaceToField.setText(replaceTo);
 
         // 動作
         waitSpinner.setValue(config.getWaitTime());
@@ -111,10 +107,6 @@ public class ConfigFrame extends javax.swing.JFrame {
         namePatternScroll = new javax.swing.JScrollPane();
         namePatternArea = new javax.swing.JTextArea();
         namePatternLabel = new javax.swing.JLabel();
-        replaceFromLabel = new javax.swing.JLabel();
-        replaceToLabel = new javax.swing.JLabel();
-        replaceFromField = new javax.swing.JTextField();
-        replaceToField = new javax.swing.JTextField();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
         setTitle("NicoBrowser - コンフィグ設定");
@@ -154,7 +146,7 @@ public class ConfigFrame extends javax.swing.JFrame {
             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
             .add(jPanel1Layout.createSequentialGroup()
                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
-                    .add(org.jdesktop.layout.GroupLayout.LEADING, mylistFileLabel, 0, 0, Short.MAX_VALUE)
+                    .add(org.jdesktop.layout.GroupLayout.LEADING, mylistFileLabel, 0, 1, Short.MAX_VALUE)
                     .add(org.jdesktop.layout.GroupLayout.LEADING, configFileLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .add(org.jdesktop.layout.GroupLayout.LEADING, feedFileLabel))
                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
@@ -366,10 +358,6 @@ public class ConfigFrame extends javax.swing.JFrame {
 
         namePatternLabel.setText("命名規則");
 
-        replaceFromLabel.setText("置換対象文字");
-
-        replaceToLabel.setText("この文字に置換");
-
         org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
         jPanel6.setLayout(jPanel6Layout);
         jPanel6Layout.setHorizontalGroup(
@@ -380,15 +368,7 @@ public class ConfigFrame extends javax.swing.JFrame {
                     .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel6Layout.createSequentialGroup()
                         .add(namePatternLabel)
                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                        .add(namePatternField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))
-                    .add(jPanel6Layout.createSequentialGroup()
-                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
-                            .add(replaceToLabel)
-                            .add(replaceFromLabel))
-                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
-                            .add(replaceFromField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
-                            .add(replaceToField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE))))
+                        .add(namePatternField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)))
                 .addContainerGap())
         );
         jPanel6Layout.setVerticalGroup(
@@ -399,14 +379,6 @@ public class ConfigFrame extends javax.swing.JFrame {
                     .add(namePatternLabel))
                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                 .add(namePatternScroll, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
-                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
-                    .add(replaceFromLabel)
-                    .add(replaceFromField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
-                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
-                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
-                    .add(replaceToLabel)
-                    .add(replaceToField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
 
@@ -464,8 +436,6 @@ public class ConfigFrame extends javax.swing.JFrame {
         p.setProperty(Config.P_PATH_DB, dbPathField.getText());
         p.setProperty(Config.P_PATH_SAVEFILE, flvPathField.getText());
         p.setProperty(Config.P_SAVEFILE_PATTERN, namePatternField.getText());
-        p.setProperty(Config.P_SAVEFILE_REPLACE_FROM, replaceFromField.getText());
-        p.setProperty(Config.P_SAVEFILE_REPLACE_TO, replaceToField.getText());
 
         p.setProperty(Config.P_DOWNLOAD_WAIT, waitSpinner.getValue().toString());
         p.setProperty(Config.P_DOWNLOAD_RETRY, retrySpinner.getValue().toString());
@@ -566,10 +536,6 @@ public class ConfigFrame extends javax.swing.JFrame {
     private javax.swing.JScrollPane namePatternScroll;
     private javax.swing.JPasswordField passField;
     private javax.swing.JLabel passLabel;
-    private javax.swing.JTextField replaceFromField;
-    private javax.swing.JLabel replaceFromLabel;
-    private javax.swing.JTextField replaceToField;
-    private javax.swing.JLabel replaceToLabel;
     private javax.swing.JSpinner retrySpinner;
     private javax.swing.JButton savaButton;
     private javax.swing.JSpinner waitSpinner;
index ac58805..16cb41f 100644 (file)
@@ -195,8 +195,7 @@ public class Main {
                 }
                 prevDate = Calendar.getInstance().getTime();
                 File saveDir = new File(config.getSrcSaveDir());
-                NamePattern np = new NamePattern(config.getFileNamePattern(), config.getFileNameReplaceFrom(), config.
-                        getFileNameReplaceTo(), c.getTitle());
+                NamePattern np = new NamePattern(config.getFileNamePattern(), c.getTitle());
                 log.info("ファイルを取得します: " + c.getNicoId() + " " + c.getTitle());
                 final boolean authed = instance.challengeAuth();
                 if (!authed) {
index 59ea520..da93bc7 100644 (file)
@@ -21,21 +21,21 @@ public class NamePatternTest {
         String res;
 
         System.out.println("createFileName");
-        NamePattern np = new NamePattern("{title}{title}", "*\\/\"", "_", title);
+        NamePattern np = new NamePattern("{title}{title}", title);
         res = np.createFileName("sm9", true);
-        assertEquals("_タ_イ_ト_ル_タ_イ_ト_ル", res);
+        assertEquals("*タ¥イ/ト”ル*タ¥イ/ト”ル", res);
 
-        NamePattern np2 = new NamePattern("[{id}]{title}", "9タ", "-", title);
+        NamePattern np2 = new NamePattern("[{id}]{title}", title);
         res = np2.createFileName(id, false);
-        assertEquals("[sm----]*-¥イ/ト”ル", res);
+        assertEquals("[sm9999]*タ¥イ/ト”ル", res);
 
-        NamePattern np3 = new NamePattern("{id}{low}_{title}", "", "", title);
+        NamePattern np3 = new NamePattern("{id}{low}_{title}", title);
         res = np3.createFileName(id, false);
         assertEquals("sm9999low_*タ¥イ/ト”ル", res);
 
-        NamePattern np4 = new NamePattern("{id}{low}_{title}", "/*-", "*", title);
+        NamePattern np4 = new NamePattern("{id}{low}_{title}", title);
         res = np4.createFileName(id, true);
-        assertEquals("sm9999_ï¼\8aã\82¿ï¿¥ã\82¤ï¼\8aト”ル", res);
+        assertEquals("sm9999_ï¼\8aã\82¿ï¿¥ã\82¤ï¼\8fト”ル", res);
 
     }
 }