]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Fix crash when getting tvgids detail page fails
authorJan-Pascal van Best <janpascal@vanbest.org>
Mon, 16 Apr 2012 15:23:15 +0000 (17:23 +0200)
committerJan-Pascal van Best <janpascal@vanbest.org>
Mon, 16 Apr 2012 15:23:15 +0000 (17:23 +0200)
- Fix exception when more than MAX_TRIES tries are needed for fetching
a url, ignore and log instead
- Set loglevel to 0 when --debug is used
- Remove <p class="..."> tags from description text (TvGids)

src/main/java/org/vanbest/xmltv/AbstractEPGSource.java
src/main/java/org/vanbest/xmltv/Main.java
src/main/java/org/vanbest/xmltv/Programme.java
src/main/java/org/vanbest/xmltv/RTL.java
src/main/java/org/vanbest/xmltv/TvGids.java

index d9e268468af1e94c19a30cd294aa55c04694b7a9..b24e27aebb9148a9fd7f8951456bc8ed7f9d1ba0 100644 (file)
@@ -55,8 +55,7 @@ public abstract class AbstractEPGSource implements EPGSource {
                Thread.sleep(config.niceMilliseconds);
                StringBuffer buf = new StringBuffer();
                boolean done = false;
-               IOException finalException = null;
-               for(int count = 0; count<MAX_FETCH_TRIES && !done; count++) {
+               for(int count = 0; !done; count++) {
                        try {
                                BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream()));
                                String s;
@@ -66,13 +65,13 @@ public abstract class AbstractEPGSource implements EPGSource {
                                if (!config.quiet) {
                                        System.out.println("Error fetching from url " + url + ", count="+count);
                                }
-                               finalException = e;
+                               if (count>=MAX_FETCH_TRIES) { 
+                                       stats.fetchErrors++;
+                                       if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+                                       throw new Exception("Error getting program data from url " + url, e);
+                               }
                        }
                }
-               if (!done) {
-                       stats.fetchErrors++;
-                       throw new Exception("Error getting program data from url " + url, finalException);
-               }
                return buf.toString();  
        }
        
index 61cc184e8e8f736a997ab96effb37689f2460db9..843b9dc562459bb38f4547771cd26d4a2f6ee2d0 100644 (file)
@@ -389,6 +389,7 @@ public class Main {
                }
                if (line.hasOption("log-level")) {
                        config.logLevel = Integer.parseInt(line.getOptionValue("log-level"));
+                       if (config.quiet) config.logLevel = 0;
                }
                if (line.hasOption("cache")) {
                        config.setCacheFile(line.getOptionValue("cache"));
index 8c1d787e44f86cf3863562be78c324b8920f0d05..644ebd2a167693e3b412e341709fe38741ae14f7 100644 (file)
@@ -346,4 +346,17 @@ public class Programme implements Serializable {
                writer.writeEndElement();
                writer.writeCharacters(System.getProperty("line.separator"));
        }
+       
+       public String getFirstTitle() {
+               if (titles==null || titles.isEmpty()) return null;
+               return titles.get(0).title;
+       }
+       
+       public String toString() {
+               StringBuilder s = new StringBuilder();
+               s.append("[Programme ").append(getFirstTitle());
+               s.append("@ ").append(startTime.toString());
+               s.append("(").append(channel).append(")]");
+               return s.toString();
+       }
 }
index 0341af6f7998e0bb3eebe7967bc68397e9596091..ac6ca50d0be300e6ceeb25729e2198abc8368d46 100644 (file)
@@ -311,7 +311,7 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
                                String programme_id = p.getString(2);\r
                                String genre_id = p.getString(3); // 1 = amusement, etc\r
                                String quark2 = p.getString(4); // 0 of 1, movie flag?\r
-                               debugWriter.print("\""+id+"\",\""+starttime+"\",\""+title+"\",\""+genre_id+"\",\""+quark2+"\",");\r
+                               if(debug) debugWriter.print("\""+id+"\",\""+starttime+"\",\""+title+"\",\""+genre_id+"\",\""+quark2+"\",");\r
                                Programme prog = cache.get(getId(), programme_id);\r
                                if (prog == null) {\r
                                        stats.cacheMisses++;\r
@@ -367,6 +367,25 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
         * @throws FileNotFoundException \r
         */\r
        public static void main(String[] args) throws FileNotFoundException {\r
+               Calendar result = Calendar.getInstance();\r
+               Calendar d = Calendar.getInstance();\r
+               try {\r
+                       d.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2012-04-16"));\r
+               } catch (ParseException e2) {\r
+                       // TODO Auto-generated catch block\r
+                       e2.printStackTrace();\r
+               }\r
+\r
+               SimpleDateFormat df = new SimpleDateFormat("HH:mm");\r
+               try {\r
+                       result.setTime(df.parse("04:50"));\r
+                       result.set(d.get(Calendar.YEAR), d.get(Calendar.MONTH), d.get(Calendar.DAY_OF_MONTH));\r
+                       System.out.println(result.getTime());\r
+                       System.exit(1);\r
+               } catch (ParseException e1) {\r
+                       // TODO Auto-generated catch block\r
+                       e1.printStackTrace();\r
+               }\r
                debug = true;\r
                Config config = Config.getDefaultConfig();\r
                config.niceMilliseconds = 50;\r
@@ -408,8 +427,10 @@ public class RTL extends AbstractEPGSource implements EPGSource  {
                                System.out.println("Number of programmes fetched: " + stats.cacheMisses);\r
                                System.out.println("Number of fetch errors: " + stats.fetchErrors);\r
                        }\r
-                       rtl.debugWriter.flush();\r
-                       rtl.debugWriter.close();\r
+                       if (debug) {\r
+                               rtl.debugWriter.flush();\r
+                               rtl.debugWriter.close();\r
+                       }\r
                        rtl.close();\r
                } catch (Exception e) {\r
                        // TODO Auto-generated catch block\r
index 91582f347baf8433a2f01382619ec92fbecc9f52..02bd9cb838f3640a53f63f63f31cd152ade5ac90 100644 (file)
@@ -281,15 +281,23 @@ public class TvGids extends AbstractEPGSource implements EPGSource {
        }
 
        private void fillDetails(String id, Programme result) throws Exception {
-               fillJSONDetails(id, result);
-               fillScraperDetails(id, result);
+               try {
+                       fillJSONDetails(id, result);
+               } catch (Exception e) {
+                       if (!config.quiet) System.out.println("Error fetching details for programme " + result.toString() );
+               }
+               try {
+                       fillScraperDetails(id, result);
+               } catch (Exception e) {
+                       if (!config.quiet) System.out.println("Error fetching details for programme " + result.toString() );
+               }
                
                if ((result.secondaryTitles==null || result.secondaryTitles.isEmpty()) && 
                                  (!result.hasCategory("movies") && !result.hasCategory("film"))) {
                        for(Programme.Title t: result.titles) {
                                String[] parts = t.title.split("\\s*:\\s*", 2);
-                               if (parts.length >= 2 ) {
-                                       if (!config.quiet) {
+                               if (parts.length >= 2 && parts[0].length()>=5) {
+                                       if (config.logLevel >= Config.LOG_DEBUG) {
                                                System.out.println("Splitting title from \"" + t.title + "\" to: \"" + parts[0].trim() + "\"; sub-title: \"" + parts[1].trim() + "\"");
                                        }
                                        t.title = parts[0].trim();
@@ -323,7 +331,7 @@ public class TvGids extends AbstractEPGSource implements EPGSource {
                        if(key.equals("synop")) {
                                value = value.replaceAll("<br>", " ").
                                                replaceAll("<br />", " ").
-                                               replaceAll("<p>", " ").
+                                               replaceAll("<p[^>]*>", " ").
                                                replaceAll("</p>", " ").
                                                replaceAll("<strong>", " ").
                                                replaceAll("</strong>", " ").