OSDN Git Service

fix #26016. NicoBrowserに渡す動画ファイル名に拡張子を含めない.
authoryukihane <yukihane.feather@gmail.com>
Mon, 15 Aug 2011 01:57:01 +0000 (10:57 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 15 Aug 2011 01:58:35 +0000 (10:58 +0900)
frontend/src/saccubus/util/FileUtil.java
frontend/src/yukihane/inqubus/saccubus_adapter/NicoBrowserAdapter.java

index cc71c09..adb98cf 100644 (file)
@@ -11,36 +11,53 @@ import java.util.regex.Pattern;
  *
  */
 public class FileUtil {
  *
  */
 public class FileUtil {
-       private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
-       public static String safeFileName(String str) {
-               //実体参照のパース
-               int old_index = 0;
-               int new_index = 0;
-               StringBuffer sb = new StringBuffer();
-               String ch;
-               while((new_index = str.indexOf("&#",old_index)) >= 0){
-                       sb.append(str,old_index,new_index);
-                       old_index = str.indexOf(";",new_index);
-                       ch = str.substring(new_index+2,old_index);
-                       sb.append(new String(new char[]{(char) Integer.parseInt(ch)}));
-                       old_index++;
-               }
-               //最後に追加
-               sb.append(str,old_index,str.length());
-               str = sb.toString();
-               //ファイルシステムで扱える形に
-               str = str.replace('/', '/');
-               str = str.replace('\\', '¥');
-               str = str.replace('?', '?');
-               str = str.replace('*', '*');
-               str = str.replace(':', ':');
-               str = str.replace('|', '|');
-               str = str.replace('\"', '”');
-               str = str.replace('<', '<');
-               str = str.replace('>', '>');
-               str = str.replace('.', '.');
-               str = safeFileName_SPACE.matcher(str).replaceAll(" ");
-               return str;
-       }
 
 
+    private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
+
+    private FileUtil() {
+    }
+
+    public static String safeFileName(String str) {
+        //実体参照のパース
+        int old_index = 0;
+        int new_index = 0;
+        StringBuffer sb = new StringBuffer();
+        String ch;
+        while ((new_index = str.indexOf("&#", old_index)) >= 0) {
+            sb.append(str, old_index, new_index);
+            old_index = str.indexOf(";", new_index);
+            ch = str.substring(new_index + 2, old_index);
+            sb.append(new String(new char[]{(char) Integer.parseInt(ch)}));
+            old_index++;
+        }
+        //最後に追加
+        sb.append(str, old_index, str.length());
+        str = sb.toString();
+        //ファイルシステムで扱える形に
+        str = str.replace('/', '/');
+        str = str.replace('\\', '¥');
+        str = str.replace('?', '?');
+        str = str.replace('*', '*');
+        str = str.replace(':', ':');
+        str = str.replace('|', '|');
+        str = str.replace('\"', '”');
+        str = str.replace('<', '<');
+        str = str.replace('>', '>');
+        str = str.replace('.', '.');
+        str = safeFileName_SPACE.matcher(str).replaceAll(" ");
+        return str;
+    }
+
+    /**
+     * ファイル名から拡張子を取り除きます. 拡張子が無ければ与えられた文字列をそのまま返します.
+     * @param fileName 対象ファイル名.
+     * @return  拡張子が取り除かれたファイル名.
+     */
+    public static String removeExtension(String fileName) {
+        int index = fileName.lastIndexOf(".");
+        if (index >= 0) {
+            return fileName.substring(0, index);
+        }
+        return fileName;
+    }
 }
 }
index 16cc1ef..0465661 100644 (file)
@@ -91,7 +91,8 @@ public class NicoBrowserAdapter implements NicoClient {
     @Override
     public File getVideo(final VideoInfo videoInfo, File file, final TextProgressListener listener) {
         try {
     @Override
     public File getVideo(final VideoInfo videoInfo, File file, final TextProgressListener listener) {
         try {
-            GetFlvResult res = client.getFlvFile(nicoBrowserVi, file.getPath(), new ProgressListener() {
+            final String fileName = FileUtil.removeExtension(file.getPath());
+            GetFlvResult res = client.getFlvFile(nicoBrowserVi, fileName, new ProgressListener() {
 
                 @Override
                 public void progress(long fileSize, long downloadSize) {
 
                 @Override
                 public void progress(long fileSize, long downloadSize) {