]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Put quiet flag in Config but do not save. Make sure splitting a title
authorJP <jp@here>
Thu, 15 Mar 2012 16:50:57 +0000 (17:50 +0100)
committerJP <jp@here>
Thu, 15 Mar 2012 16:50:57 +0000 (17:50 +0100)
only writes to stdout if !quiet

tv_grab_nl_java/src/org/vanbest/xmltv/Config.java
tv_grab_nl_java/src/org/vanbest/xmltv/Main.java
tv_grab_nl_java/src/org/vanbest/xmltv/ProgrammeDetails.java
tv_grab_nl_java/src/org/vanbest/xmltv/TvGids.java

index e5aa1802187ccbe7c98099a22b8922f4c4220867..71222def9c777e21c4fc0d41e0e6632a8525300a 100644 (file)
@@ -21,6 +21,7 @@ public class Config {
        public List<Channel> channels;
        public Map<String, String> cattrans;
        protected File cacheFile;
+       boolean quiet = false;
        
        private Config() {
        }
@@ -146,7 +147,6 @@ public class Config {
                        result.setChannels(channels);
                        result.cattrans = cattrans;
                        result.cacheFile = cacheFile;
-                       //System.out.println("CAche file: "+cacheFile.getPath());
                } catch (IOException e) {
                        System.out.println("Cannot read configuration file, continuing with empty configuration");
                        return getDefaultConfig();
index bef8acde73949bc235cb83c45f1b2339a1d75626..6ec1b1ab0d2a669eb5825dac9daf5def1504c45e 100644 (file)
@@ -30,7 +30,6 @@ public class Main {
        private PrintStream outputWriter;
        private int days = 5;
        private int offset = 0;
-       private boolean quiet = false;
        /**
         * @param args
         */
@@ -41,7 +40,7 @@ public class Main {
        }
        
        public void run() throws FactoryConfigurationError, Exception {
-               if (!quiet) {
+               if (!config.quiet) {
                        System.out.println("Fetching programme data for days " + this.offset + "-" + (this.offset+this.days-1));
                        System.out.println("... from " + config.channels.size() + " channels");
                        System.out.println("... using cache file " + config.cacheFile.getCanonicalPath());
@@ -53,17 +52,17 @@ public class Main {
                TvGids gids = new TvGids(config);
 
                for (int day=offset; day<offset+days; day++) {
-                       if (!quiet) System.out.print("Fetching information for day " + day);
+                       if (!config.quiet) System.out.print("Fetching information for day " + day);
                        Set<Programme> programmes = new HashSet<Programme>();
                        for( Channel c: config.channels ) {
-                               if (!quiet) System.out.print(".");
+                               if (!config.quiet) System.out.print(".");
                                ArrayList<Channel> cs = new ArrayList<Channel>(2);
                                cs.add(c);
                                Set<Programme> p = gids.getProgrammes(cs, day, true);
                                writer.writePrograms(p);
                                writer.flush();
                        }
-                       if (!quiet) System.out.println();
+                       if (!config.quiet) System.out.println();
                }
                
                try {
@@ -77,7 +76,7 @@ public class Main {
                }
 
                writer.close();
-               if (!quiet) {
+               if (!config.quiet) {
                        System.out.println("Number of programmes from cache: " + gids.cacheHits);
                        System.out.println("Number of programmes fetched: " + gids.cacheMisses);
                        System.out.println("Number of fetch errors: " + gids.fetchErrors);
@@ -169,13 +168,13 @@ public class Main {
                        formatter.printHelp( "tv_grab_nl_java", options );
                        System.exit(0);
                }
-               if (line.hasOption("q")) {
-                       this.quiet = true;
-               }
                if(line.hasOption("f")) { 
                        configFile = new File(line.getOptionValue("f"));        
                }
                config = Config.readConfig(configFile);
+               if (line.hasOption("q")) {
+                       config.quiet = true;
+               }
                
                if (line.hasOption("o")) {
                        this.outputWriter = new PrintStream( new FileOutputStream(line.getOptionValue("o")));
index 2d4b9f73d194807c40acb7a95e55ce511c8d6500..69c7484ca1be7ffa820daa6aa1db9510be8d2940 100644 (file)
@@ -16,7 +16,7 @@ public class ProgrammeDetails implements Serializable {
        String regisseur;
        String zender_id;
        
-       public void fixup(Programme p) {
+       public void fixup(Programme p, boolean quiet) {
                this.titel = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(titel);
                this.genre = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(genre);
                this.synop = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(synop);
@@ -35,7 +35,9 @@ public class ProgrammeDetails implements Serializable {
                                titel = parts[0].trim();
                                p.titel = titel;
                                synop = parts[1].trim();
-                               System.out.println("Splitting title to : \"" + p.titel + "\"; synop: \"" + synop + "\"");
+                               if (!quiet) {
+                                       System.out.println("Splitting title to : \"" + p.titel + "\"; synop: \"" + synop + "\"");
+                               }
                        }
                }
                this.presentatie = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(presentatie);
index 30e6a31e350c26e786f8a63328853a81456a91ec..61c535160214fabcf5b9adaba5d2b930effba4b0 100644 (file)
@@ -196,7 +196,7 @@ public class TvGids {
                        URL url = detailUrl(p.db_id);
                        JSONObject json = fetchJSON(url);
                        p.details = (ProgrammeDetails) JSONObject.toBean(json, ProgrammeDetails.class);
-                       p.details.fixup(p);
+                       p.details.fixup(p, config.quiet);
                        cache.add(p.db_id, p.details);
                } else {
                        cacheHits++;