]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
More work on Horizon fetcher, looking good now
authorJan-Pascal van Best <janpascal@vanbest.org>
Tue, 5 Mar 2013 11:10:33 +0000 (12:10 +0100)
committerJan-Pascal van Best <janpascal@vanbest.org>
Tue, 5 Mar 2013 11:10:33 +0000 (12:10 +0100)
.classpath
src/main/java/org/vanbest/xmltv/Config.java
src/main/java/org/vanbest/xmltv/Horizon.java
src/main/java/org/vanbest/xmltv/Programme.java
src/main/java/org/vanbest/xmltv/ProgrammeCache.java
src/main/resources/tv_grab_nl_java.properties

index d90b9173dca0e9187a99987117e280f8c7cb3e9d..f32149e8639a6920c39fd0bca61094822bffdb68 100644 (file)
@@ -1,9 +1,31 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <classpath>\r
-       <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
-       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
-       <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
-       <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>\r
+       <classpathentry kind="src" output="target/classes" path="src/main/java">\r
+               <attributes>\r
+                       <attribute name="optional" value="true"/>\r
+                       <attribute name="maven.pomderived" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
+       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">\r
+               <attributes>\r
+                       <attribute name="maven.pomderived" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
+       <classpathentry kind="src" output="target/test-classes" path="src/test/java">\r
+               <attributes>\r
+                       <attribute name="optional" value="true"/>\r
+                       <attribute name="maven.pomderived" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">\r
+               <attributes>\r
+                       <attribute name="maven.pomderived" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
+       <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">\r
+               <attributes>\r
+                       <attribute name="maven.pomderived" value="true"/>\r
+               </attributes>\r
+       </classpathentry>\r
        <classpathentry kind="output" path="target/classes"/>\r
 </classpath>\r
index 54eda717a2e1a840ceacb3b8cf6cf8f9dcbd25e4..8a999dcbe5bed86f5419f3ed62eac828d4a080f4 100644 (file)
@@ -126,6 +126,7 @@ public class Config {
                result.put("sport", "Sports");
                result.put("theater", "Arts/Culture");
                result.put("wetenschap", "Science/Nature");
+               result.put("news", "News");
                return result;
        }
 
index 70f714f8b6303f3305a50449bec440e41e2fb8c3..01c50fe9236b93f2ae7805d063e4f78d0a05360c 100644 (file)
@@ -121,11 +121,21 @@ public class Horizon extends AbstractEPGSource implements EPGSource {
                        
                        JSONObject firstSchedule = stationSchedules.getJSONObject(0);
                        JSONObject station = firstSchedule.getJSONObject("station");
-                       logger.info("firstschedule: " + firstSchedule.toString());
+                       logger.debug("firstschedule: " + firstSchedule.toString());
                        int id = station.getInt("id");
                        String name = station.getString("title");
+                       // Use the largest available station logo as icon
                        JSONArray images = station.getJSONArray("images");
                        String icon = "";
+                       int maxSize = 0;
+                       for( int j=0; j<images.size(); j++) {
+                               JSONObject image = images.getJSONObject(j);
+                               if (image.getString("assetType").startsWith("station-logo") &&
+                                               image.getInt("width")>maxSize) {
+                                       icon = image.getString("url");
+                                       maxSize = image.getInt("width");
+                               }
+                       }
                        Channel c = Channel.getChannel(getId(), Integer.toString(id), name,
                                        icon);
                        result.add(c);
@@ -150,9 +160,9 @@ public class Horizon extends AbstractEPGSource implements EPGSource {
 
                for (Channel c : channels) {
                        URL url = programmeUrl(c, day);
-                       logger.info("Programme url:" + url);
+                       logger.debug("Programme url:" + url);
                        JSONObject jsonObject = fetchJSON(url);
-                       logger.info(jsonObject.toString());
+                       logger.debug(jsonObject.toString());
                        JSONArray listings = jsonObject.getJSONArray("listings");
                        for (int i = 0; i < listings.size(); i++) {
                                JSONObject listing = listings.getJSONObject(i);
@@ -212,7 +222,45 @@ public class Horizon extends AbstractEPGSource implements EPGSource {
                        result.startTime = new Date(json.getLong("startTime"));
                        result.endTime = new Date(json.getLong("endTime"));
                        JSONObject prog = json.getJSONObject("program");
-                       result.addTitle(prog.getString("title"));
+                       if (prog.containsKey("secondaryTitle")){
+                               result.addTitle(prog.getString("secondaryTitle"));
+                       } else {
+                               result.addTitle(prog.getString("title"));
+                       }
+                       String description = prog.getString("longDescription");
+                       if (description==null || description.isEmpty()) {
+                       description = prog.getString("description");
+                               if (description==null || description.isEmpty()) {
+                                       description = prog.getString("shortDescription");
+                               }
+                       }
+                       result.addDescription(description);
+
+                       JSONArray cast = prog.getJSONArray("cast");
+                       for( int j=0; j<cast.size(); j++) {
+                               result.addActor(cast.getString(j));
+                       }
+
+                       JSONArray directors = prog.getJSONArray("directors");
+                       for( int j=0; j<directors.size(); j++) {
+                               result.addDirector(directors.getString(j));
+                       }
+                       JSONArray categories = prog.getJSONArray("categories");
+                       for( int j=0; j<categories.size(); j++) {
+                               String cat = categories.getJSONObject(j).getString("title");
+                               if (!cat.contains("/")) {
+                                       // Remove things like "drama/drama" and subcategories
+                                       result.addCategory(config.translateCategory(cat));
+                               }
+                       }
+                       if (prog.containsKey("seriesEpisodeNumber")){
+                               String episode = prog.getString("seriesEpisodeNumber");
+                               result.addEpisode(episode,"onscreen");
+                       }
+                       if (prog.containsKey("parentalRating")){
+                               String rating  = prog.getString("parentalRating");
+                               result.addRating("kijkwijzer", "Afgeraden voor kinderen jonger dan "+rating+" jaar");
+                       }
                        /*
                        // Do this here, because we can only add to these fields. Pity if
                        // they're updated
@@ -253,7 +301,8 @@ public class Horizon extends AbstractEPGSource implements EPGSource {
         */
        public static void main(String[] args) {
                Config config = Config.getDefaultConfig();
-               Horizon horizon = new Horizon(1, config);
+               Horizon horizon = new Horizon(3, config);
+               horizon.clearCache();
                try {
                        List<Channel> channels = horizon.getChannels();
                        System.out.println("Channels: " + channels);
index be17c00491ba2c4544947b41fc302d3daabae515..884ecd3cbe03e7fc199c2d0f953d55e17130e2f7 100644 (file)
@@ -152,6 +152,15 @@ public class Programme implements Serializable {
                descriptions.add(new Title(title, lang));
        }
 
+       public void addEpisode(String episode, String system) {
+               if (episodes == null)
+                       episodes = new ArrayList<Episode>();
+               Episode e = new Episode();
+               e.episode = episode;
+               e.system = system;
+               episodes.add(e);
+       }
+               
        public void addCategory(String category) {
                addCategory(category, null);
        }
@@ -323,6 +332,20 @@ public class Programme implements Serializable {
                }
        }
 
+       private void writeEpisodeList(List<Episode> episodes, XMLStreamWriter writer)
+                       throws XMLStreamException {
+               if (episodes == null)
+                       return;
+               for (Episode e: episodes) {
+                       writer.writeStartElement("episode");
+                       if (e.system != null)
+                               writer.writeAttribute("system", e.system);
+                       if (e.episode != null)
+                               writer.writeCharacters(e.episode);
+                       writer.writeEndElement();
+               }
+       }
+
        private void writeIconList(List<Icon> icons, XMLStreamWriter writer)
                        throws XMLStreamException {
                if (icons == null)
@@ -355,6 +378,7 @@ public class Programme implements Serializable {
                writeTitleList(categories, "category", writer);
                writeIconList(icons, writer);
                writeStringList(urls, "url", writer);
+               writeEpisodeList(episodes,writer);
                if (video != null) {
                        writer.writeStartElement("video");
                        if (!video.present) {
index 01de8a4bee886f2bdaaba7a88cbba02698dbe8f6..9248120cc90d8396ee09446f2906b8ec01c76ae8 100644 (file)
@@ -52,7 +52,7 @@ public class ProgrammeCache {
     private PreparedStatement clearSourceStatement;
 
     /** The Constant SCHEMA_VERSION. */
-    private final static Integer SCHEMA_VERSION = 1;
+    private final static Integer SCHEMA_VERSION = 2;
 
     /** The Constant SCHEMA_KEY. */
     private final static String SCHEMA_KEY = "TV_GRAB_NL_JAVA_SCHEMA_VERSION";
@@ -128,7 +128,7 @@ public class ProgrammeCache {
                     // System.out.println("Dropping old table");
                     stat.execute("DROP TABLE IF EXISTS cache");
                     // System.out.println("Creating new table");
-                    stat.execute("CREATE CACHED TABLE IF NOT EXISTS cache (source INTEGER, id VARCHAR(64), date DATE, programme OTHER, PRIMARY KEY (source,id))");
+                    stat.execute("CREATE CACHED TABLE IF NOT EXISTS cache (source INTEGER, id VARCHAR(128), date DATE, programme OTHER, PRIMARY KEY (source,id))");
                     stat.close();
 
                     // System.out.println("Writing new schema version to database");
index 2efb1d944765eac47d505b7c870a008211945baa..0051cac57366b426839e306b8cabf0066b145030 100644 (file)
@@ -3,4 +3,5 @@ project.name=${project.name}
 project.description=${project.description}
 build.time=${build.time}
 org.vanbest.xmltv.epgsource.impl.1=org.vanbest.xmltv.TvGids
-org.vanbest.xmltv.epgsource.impl.2=org.vanbest.xmltv.RTL
\ No newline at end of file
+org.vanbest.xmltv.epgsource.impl.2=org.vanbest.xmltv.RTL
+org.vanbest.xmltv.epgsource.impl.3=org.vanbest.xmltv.Horizon
\ No newline at end of file