OSDN Git Service

ニコニコ動画仕様変更対応. swfの取得にas3=1を追加.
authoryuki <yuki@c066991c-cf13-ec4a-a49a-846e61667af5>
Sat, 9 May 2009 10:19:05 +0000 (10:19 +0000)
committeryuki <yuki@c066991c-cf13-ec4a-a49a-846e61667af5>
Sat, 9 May 2009 10:19:05 +0000 (10:19 +0000)
swf取得時, 圧縮ファイル(CWS)を展開(FWS)してからffmpegに渡すように変更. ffmpegがCWSに対応していないため.

git-svn-id: http://192.168.11.7/svn/saccubus/trunk@25 c066991c-cf13-ec4a-a49a-846e61667af5

frontend/src/saccubus/Converter.java
frontend/src/saccubus/net/NicoClient.java
frontend/src/saccubus/util/Cws2Fws.java [new file with mode: 0644]

index 4aac34d..c4906dd 100644 (file)
@@ -7,6 +7,7 @@ import java.io.*;
 import saccubus.conv.ConvertToVideoHook;
 import java.net.URLEncoder;
 import java.util.Properties;
+import saccubus.util.Cws2Fws;
 
 /**
  * <p>\83^\83C\83g\83\8b\82³\82«\82ã\82Î\82·</p>
@@ -327,6 +328,8 @@ public class Converter extends Thread {
        private static final int CODE_CONVERTING_ABORTED = 100;
 
        private int converting_video(String vhook_path) {
+               File fwsFile = Cws2Fws.createFws(VideoFile);
+
                StringBuffer sb = new StringBuffer();
                sb.append("\"");
                sb.append(Setting.getFFmpegPath().replace("\\", "\\\\"));
@@ -336,9 +339,13 @@ public class Converter extends Thread {
                sb.append(" ");
                sb.append(InOption);
                sb.append(" -i ");
-               sb.append("\"");
-               sb.append(VideoFile.getPath().replace("\\", "\\\\"));
-               sb.append("\"");
+               if (fwsFile == null) {
+                       sb.append("\"");
+                       sb.append(VideoFile.getPath().replace("\\", "\\\\"));
+                       sb.append("\"");
+               } else {
+                       sb.append(fwsFile.getPath().replace("\\", "\\\\"));
+               }
                sb.append(" ");
                sb.append(OutOption);
                sb.append(" \"");
@@ -377,6 +384,10 @@ public class Converter extends Thread {
                } catch (IOException ex) {
                        ex.printStackTrace();
                        return -1;
+               } finally {
+                       if (fwsFile != null) {
+                               fwsFile.delete();
+                       }
                }
        }
 
index 38f2eb9..ad50122 100644 (file)
@@ -293,7 +293,10 @@ public class NicoClient {
                        return false;
                }
                try {
-                       String url = "http://www.nicovideo.jp/api/getflv?v=" + tag;
+                       String url = "http://www.nicovideo.jp/api/getflv/" + tag;
+                       if (tag.startsWith("nm")) {
+                               url += "?as3=1";
+                       }
                        System.out.print("Getting video informations...");
                        HttpURLConnection con = (HttpURLConnection) (new URL(url))
                                        .openConnection(ConProxy);
diff --git a/frontend/src/saccubus/util/Cws2Fws.java b/frontend/src/saccubus/util/Cws2Fws.java
new file mode 100644 (file)
index 0000000..01e9980
--- /dev/null
@@ -0,0 +1,101 @@
+package saccubus.util;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.InflaterInputStream;
+
+/**
+ *
+ * @author yuki
+ */
+public class Cws2Fws {
+
+       private static final String CWS = "CWS";
+       private static final String FWS = "FWS";
+
+       /**
+        * \88³\8fkSWF\82©\82Ç\82¤\82©\94»\92è\82·\82é.
+        * @param file \94»\92è\91Î\8fÛ.
+        * @return \88³\8fkSWF\82Å\82 \82ê\82Îtrue.
+        */
+       public static boolean isCws(File file) {
+               BufferedInputStream bis = null;
+               try {
+                       bis = new BufferedInputStream(new FileInputStream(file));
+                       byte header[] = new byte[CWS.length()];
+                       bis.read(header, 0, header.length);
+                       if (CWS.equals(new String(header))) {
+                               return true;
+                       }
+               } catch (IOException ex) {
+                       Logger.getLogger(Cws2Fws.class.getName()).log(Level.SEVERE, null, ex);
+               } finally {
+                       if (bis != null) {
+                               try {
+                                       bis.close();
+                               } catch (IOException ex) {
+                                       Logger.getLogger(Cws2Fws.class.getName()).log(Level.SEVERE, null, ex);
+                               }
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * \88³\8fkSWF\82ð\93W\8aJ\82·\82é.
+        * @param in \93W\8aJ\91Î\8fÛ.
+        * @return \93W\8aJ\8cã\82Ì\83t\83@\83C\83\8b\91Î\8fÛ\82ª\88³\8fkSWF\82Å\82È\82¯\82ê\82Înull.
+        */
+       public static File createFws(File in) {
+               if (!isCws(in)) {
+                       return null;
+               }
+               File out = new File("fws_tmp.swf");
+               BufferedInputStream bis = null;
+               BufferedOutputStream bos = null;
+               try {
+                       byte buffer[] = new byte[1024];
+                       bis = new BufferedInputStream(new FileInputStream(in));
+                       bis.read(buffer, 0, CWS.length()); // CWS
+                       bis.read(buffer, 0, 5); // \82»\82Ì\91¼\83w\83b\83_
+
+                       bos = new BufferedOutputStream(new FileOutputStream(out));
+                       bos.write(FWS.getBytes());
+                       bos.write(buffer);
+
+                       InflaterInputStream iis = new InflaterInputStream(bis);
+                       while (true) {
+                               int res = iis.read(buffer);
+                               if (res < 0) {
+                                       break;
+                               }
+                               bos.write(buffer, 0, res);
+                       }
+                       return out;
+               } catch (IOException ex) {
+                       Logger.getLogger(Cws2Fws.class.getName()).log(Level.SEVERE, null, ex);
+               } finally {
+                       if (bis != null) {
+                               try {
+                                       bis.close();
+                               } catch (IOException ex) {
+                                       Logger.getLogger(Cws2Fws.class.getName()).log(Level.SEVERE, null, ex);
+                               }
+                       }
+                       if (bos != null) {
+                               try {
+                                       bos.close();
+                               } catch (IOException ex) {
+                                       Logger.getLogger(Cws2Fws.class.getName()).log(Level.SEVERE, null, ex);
+                               }
+                       }
+               }
+               return null;
+       }
+}