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;
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();
}
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);
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();
// ランキング上位のコンテンツ保存
int num = 0;
for (NicoContent c : dailyList) {
- if (num >= config.getMaxDownloadNumber()) {
- break;
- }
save(manager, c);
num++;
}
}
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);