]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Put tvgids.nl nice time in config file
authorJan-Pascal van Best <janpascal@vanbest.org>
Fri, 16 Mar 2012 12:17:43 +0000 (13:17 +0100)
committerJan-Pascal van Best <janpascal@vanbest.org>
Fri, 16 Mar 2012 12:17:43 +0000 (13:17 +0100)
tv_grab_nl_java/.classpath
tv_grab_nl_java/.settings/org.eclipse.jdt.core.prefs
tv_grab_nl_java/src/org/vanbest/xmltv/Config.java
tv_grab_nl_java/src/org/vanbest/xmltv/TvGids.java

index 591744aa8da69378b8be4623a3b00e19b9154677..6c7804fdaed2183236b492a638e5d32dfb3cd23c 100644 (file)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-       <classpathentry kind="src" path="src"/>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-       <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
-       <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>\r
+       <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>\r
+       <classpathentry kind="output" path="target/classes"/>\r
+</classpath>\r
index 8be742ff87054667bc9b0fba736a88cbcfe448de..f4217b01dd2e048b7250aa1835ddf636fb75d6ea 100644 (file)
@@ -1,13 +1,12 @@
-#Fri Mar 09 20:00:25 CET 2012
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7\r
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\r
+org.eclipse.jdt.core.compiler.compliance=1.7\r
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate\r
+org.eclipse.jdt.core.compiler.debug.localVariable=generate\r
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning\r
+org.eclipse.jdt.core.compiler.source=1.7\r
index 71222def9c777e21c4fc0d41e0e6632a8525300a..f62f94492d9c42dedd3544570a768fb70779c52b 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Map;
 import org.apache.commons.io.FileUtils;
 
 public class Config {
+       public int niceMilliseconds;
        public List<Channel> channels;
        public Map<String, String> cattrans;
        protected File cacheFile;
@@ -26,10 +27,23 @@ public class Config {
        private Config() {
        }
        
+       public static Config getDefaultConfig() {
+               Config result = new Config();
+               result.channels = new ArrayList<Channel>();
+               result.cattrans = getDefaultCattrans();
+               result.cacheFile = defaultCacheFile();
+               result.niceMilliseconds = 500;
+               return result;
+       }
+               
        public Map<String,String> getCategories() {
                return cattrans;
        }
 
+       public void setChannels(List<Channel> channels) {
+               this.channels = channels;
+       }
+
        public static File defaultCacheFile() {
                return FileUtils.getFile(FileUtils.getUserDirectory(), ".xmltv", "tv_grab_nl_java.cache");
        }
@@ -63,6 +77,7 @@ public class Config {
                FileUtils.forceMkdir(configFile.getParentFile());
                PrintWriter out = new PrintWriter(new OutputStreamWriter( new FileOutputStream( configFile )));
                out.println("cache-file: " + escape(cacheFile.getPath()));
+               out.println("nice-time-milliseconds: " + niceMilliseconds);
                for(Channel c: channels) {
                        if (!c.selected) {
                                out.print("#");
@@ -117,13 +132,13 @@ public class Config {
                }
                return parts;
        }
+
        public static Config readConfig(File file) {
-               Config result = new Config();
+               Config result = getDefaultConfig();
+               result.cattrans = new HashMap<String,String>();
                try {
                        BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream( file)));
-                       List<Channel> channels = new ArrayList<Channel>();
-                       Map<String,String> cattrans = new HashMap<String,String>();
-                       File cacheFile = defaultCacheFile();
+                       
                        while(true) {
                                String s = reader.readLine();
                                if(s==null) break;
@@ -135,36 +150,26 @@ public class Config {
                                        if (parts.size()>3) {
                                                c.setIconUrl(parts.get(3));
                                        }
-                                       channels.add(c);
-                               }
-                               if (parts.get(0).toLowerCase().equals("category")) {
-                                       cattrans.put(parts.get(1), parts.get(2));
+                                       result.channels.add(c);
                                }
-                               if (parts.get(0).toLowerCase().equals("cache-file")) {
-                                       cacheFile = new File(parts.get(1));
+                               switch (parts.get(0).toLowerCase()) {
+                               case "category" :
+                                       result.cattrans.put(parts.get(1), parts.get(2));
+                                       break;
+                               case "cache-file":
+                                       result.cacheFile = new File(parts.get(1));
+                                       break;
+                               case "nice-time-milliseconds":
+                                       result.niceMilliseconds = Integer.parseInt(parts.get(1));
                                }
                        }
-                       result.setChannels(channels);
-                       result.cattrans = cattrans;
-                       result.cacheFile = cacheFile;
                } catch (IOException e) {
-                       System.out.println("Cannot read configuration file, continuing with empty configuration");
+                       e.printStackTrace();
+                       System.out.println("Error reading configuration file, continuing with empty configuration");
                        return getDefaultConfig();
                }
                return result;
        }
-       
-       public static Config getDefaultConfig() {
-               Config result = new Config();
-               result.channels = new ArrayList<Channel>();
-               result.cattrans = getDefaultCattrans();
-               result.cacheFile = defaultCacheFile();
-               return result;
-       }
-       
-       public void setChannels(List<Channel> channels) {
-               this.channels = channels;
-       }
 
 }
 
index 61c535160214fabcf5b9adaba5d2b930effba4b0..5612b7ea4a80fc7d11abdf31ec5134c24a93fdfe 100644 (file)
@@ -176,7 +176,7 @@ public class TvGids {
        }
        
        private JSONObject fetchJSON(URL url) throws Exception {
-               Thread.sleep(100);
+               Thread.sleep(config.niceMilliseconds);
                StringBuffer json = new StringBuffer();
                try {
                        BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream()));