OSDN Git Service

新コンフィグフォーマット対応.
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 23 May 2009 22:03:05 +0000 (22:03 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 23 May 2009 22:03:05 +0000 (22:03 +0000)
git-svn-id: http://192.168.11.7/svn/repository/NicoBrowserBranches/release_20090323/NicoBrowser@125 bdf3b611-c98c-6041-8292-703d9c9adbe7

src/nicobrowser/main/Main.java

index dbcdb66..0390aa5 100644 (file)
@@ -14,6 +14,7 @@ import javax.persistence.EntityTransaction;
 import javax.persistence.Persistence;
 import javax.persistence.Query;
 import nicobrowser.Config;
+import nicobrowser.Config.NicoFeed;
 import nicobrowser.NicoHttpClient;
 import nicobrowser.entity.NicoContent;
 import nicobrowser.entity.NicoContent.Status;
@@ -24,7 +25,13 @@ public class Main {
 
     private static Log log = LogFactory.getLog(Main.class);
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
+        boolean res = Config.createNewConfigFiles();
+        if (res) {
+            System.out.println("コンフィグファイルを作成しました. 編集後, 再実行してください.");
+            return;
+        }
+
         new Main().start();
     }
 
@@ -32,23 +39,25 @@ public class Main {
         log.info("program start");
 
         Config config = Config.getInstance();
-        File saveLoc = new File(config.getSrcSaveDir());
-        if (!saveLoc.isDirectory()) {
-            try {
-                log.fatal("ディレクトリが存在しません: " + saveLoc.getCanonicalPath());
-            } catch (IOException ex) {
-                log.fatal("コンフィグファイルの記述が不正です: " + config.getSrcSaveDir());
-            }
-            return;
-        }
-        List<NicoContent> dailyList = null;
+        List<NicoContent> dailyList = new ArrayList<NicoContent>();
         ArrayList<List<NicoContent>> myLists = new ArrayList<List<NicoContent>>();
         NicoHttpClient instance = null;
         try {
             log.info("リストを取得します");
             instance = NicoHttpClient.getInstance();
-            dailyList = instance.loadMyListDaily();
-            String[] mylists = config.getDownLoadMyList();
+            List<NicoFeed> feeds = config.getNicoFeeds();
+            for (NicoFeed f : feeds) {
+                List<NicoContent> list = instance.getContentsFromRss(f.getUrl());
+                int count = 0;
+                for (NicoContent l : list) {
+                    if (count >= f.getNumber()) {
+                        break;
+                    }
+                    dailyList.add(l);
+                    count++;
+                }
+            }
+            List<String> mylists = config.getDownLoadMyList();
             for (String l : mylists) {
                 List<NicoContent> list = instance.loadMyList(l);
                 myLists.add(list);
@@ -64,7 +73,7 @@ public class Main {
         EntityManager manager;
 
         HashMap<String, String> map = new HashMap<String, String>();
-        map.put("toplink.jdbc.url", "jdbc:h2:" + config.getDbPath());
+        map.put("toplink.jdbc.url", "jdbc:h2:" + config.getDbFile());
         factory = Persistence.createEntityManagerFactory("NicoBrowserPU", map);
         manager = factory.createEntityManager();
 
@@ -75,9 +84,6 @@ public class Main {
             // ランキング上位のコンテンツ保存
             int num = 0;
             for (NicoContent c : dailyList) {
-                if (num >= config.getMaxDownloadNumber()) {
-                    break;
-                }
                 save(manager, c);
                 num++;
             }
@@ -111,12 +117,12 @@ public class Main {
                 }
                 prevDate = Calendar.getInstance().getTime();
                 File saveLocation = new File(config.getSrcSaveDir(), c.getFileName());
-                log.info("ファイルを取得します: " + c.getFileName());
+                log.info("ファイルを取得します: " + c.getNicoId() + " " + c.getTitle());
                 Status status;
                 try {
                     status = instance.getFlvFile(c.getNicoId(),
                             saveLocation.getCanonicalPath(), c.getStatus(),
-                            config.isExtMp4Use());
+                            true);
                     c.setStatus(status);
                     if (status == Status.GET_INFO) {
                         c.setFailTimes(c.getFailTimes() + 1);