From: Jan-Pascal van Best Date: Tue, 5 Mar 2013 11:10:33 +0000 (+0100) Subject: More work on Horizon fetcher, looking good now X-Git-Tag: 1.2.0~1 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=6a6541a65bdc9f2f26f9ee04f61cee65a71631dd;p=tv_grab_nl_java More work on Horizon fetcher, looking good now --- diff --git a/.classpath b/.classpath index d90b917..f32149e 100644 --- a/.classpath +++ b/.classpath @@ -1,9 +1,31 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/vanbest/xmltv/Config.java b/src/main/java/org/vanbest/xmltv/Config.java index 54eda71..8a999dc 100644 --- a/src/main/java/org/vanbest/xmltv/Config.java +++ b/src/main/java/org/vanbest/xmltv/Config.java @@ -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; } diff --git a/src/main/java/org/vanbest/xmltv/Horizon.java b/src/main/java/org/vanbest/xmltv/Horizon.java index 70f714f..01c50fe 100644 --- a/src/main/java/org/vanbest/xmltv/Horizon.java +++ b/src/main/java/org/vanbest/xmltv/Horizon.java @@ -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; jmaxSize) { + 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 channels = horizon.getChannels(); System.out.println("Channels: " + channels); diff --git a/src/main/java/org/vanbest/xmltv/Programme.java b/src/main/java/org/vanbest/xmltv/Programme.java index be17c00..884ecd3 100644 --- a/src/main/java/org/vanbest/xmltv/Programme.java +++ b/src/main/java/org/vanbest/xmltv/Programme.java @@ -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 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 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 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) { diff --git a/src/main/java/org/vanbest/xmltv/ProgrammeCache.java b/src/main/java/org/vanbest/xmltv/ProgrammeCache.java index 01de8a4..9248120 100644 --- a/src/main/java/org/vanbest/xmltv/ProgrammeCache.java +++ b/src/main/java/org/vanbest/xmltv/ProgrammeCache.java @@ -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"); diff --git a/src/main/resources/tv_grab_nl_java.properties b/src/main/resources/tv_grab_nl_java.properties index 2efb1d9..0051cac 100644 --- a/src/main/resources/tv_grab_nl_java.properties +++ b/src/main/resources/tv_grab_nl_java.properties @@ -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