import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
-import java.util.regex.Pattern;
import java.text.*;
import javax.net.ssl.HttpsURLConnection;
import saccubus.ConvertStopFlag;
+import saccubus.util.FileUtil;
/**
* <p>
return VideoTitle;
}
- private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
- private static String safeFileName(String str) {
- //\8eÀ\91Ì\8eQ\8fÆ\82Ì\83p\81[\83X
- 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++;
- }
- //\8dÅ\8cã\82É\92Ç\89Á
- sb.append(str,old_index,str.length());
- str = sb.toString();
- //\83t\83@\83C\83\8b\83V\83X\83e\83\80\82Å\88µ\82¦\82é\8c`\82É
- str = str.replace('/', '\81^');
- str = str.replace('\\', '\81\8f');
- str = str.replace('?', '\81H');
- str = str.replace('*', '\81\96');
- str = str.replace(':', '\81F');
- str = str.replace('|', '\81b');
- str = str.replace('\"', '\81h');
- str = str.replace('<', '\81\83');
- str = str.replace('>', '\81\84');
- str = str.replace('.', '\81D');
- str = safeFileName_SPACE.matcher(str).replaceAll(" ");
- return str;
- }
-
private String VideoTitle = null;
private int VideoLength = -1;
private static final String TITLE_PARSE_STR_START = "<title>";
- //RC2\82É\82È\82Á\82Ä\83^\83C\83g\83\8b\82ª\95Ï\8dX\81A\8eg\82í\82È\82\82È\82Á\82½\81B
- //private static final String TITLE_PARSE_STR_END = "</title>";
-
public boolean getVideoHistoryAndTitle(String tag) {
String url = "http://www.nicovideo.jp/watch/" + tag;
System.out.print("Getting video history...");
while ((ret = br.readLine()) != null && index < 0) {
if ((index = ret.indexOf(TITLE_PARSE_STR_START)) >= 0) {
VideoTitle = ret.substring(index+TITLE_PARSE_STR_START.length(), ret.indexOf("\81]", index));
- VideoTitle = safeFileName(VideoTitle);
+ VideoTitle = FileUtil.safeFileName(VideoTitle);
}
}
br.close();
--- /dev/null
+package saccubus.util;
+
+import java.util.regex.Pattern;
+
+public class FileUtil {
+ private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
+ public static String safeFileName(String str) {
+ //\8eÀ\91Ì\8eQ\8fÆ\82Ì\83p\81[\83X
+ 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++;
+ }
+ //\8dÅ\8cã\82É\92Ç\89Á
+ sb.append(str,old_index,str.length());
+ str = sb.toString();
+ //\83t\83@\83C\83\8b\83V\83X\83e\83\80\82Å\88µ\82¦\82é\8c`\82É
+ str = str.replace('/', '\81^');
+ str = str.replace('\\', '\81\8f');
+ str = str.replace('?', '\81H');
+ str = str.replace('*', '\81\96');
+ str = str.replace(':', '\81F');
+ str = str.replace('|', '\81b');
+ str = str.replace('\"', '\81h');
+ str = str.replace('<', '\81\83');
+ str = str.replace('>', '\81\84');
+ str = str.replace('.', '\81D');
+ str = safeFileName_SPACE.matcher(str).replaceAll(" ");
+ return str;
+ }
+
+}