-package org.vanbest.xmltv;
-
-/*
- Copyright (c) 2012 Jan-Pascal van Best <janpascal@vanbest.org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- The full license text can be found in the LICENSE file.
-*/
-
-public class Channel {
- int id;
- String name;
- String shortName;
- String iconUrl;
- boolean selected;
-
- public Channel(int id, String name, String shortName) {
- this.id = id;
- this.name = name;
- this.shortName = shortName;
- }
- public String toString() {
- return "id: " + id + "; name: " + name + "; shortName: " + shortName;
- }
-
- public String getChannelId() {
- return id+".tvgids.nl";
- }
-
- public void fixup() {
- this.name = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(name);
- this.shortName = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(shortName);
- }
- public void setIconUrl(String url) {
- this.iconUrl = url;
- }
-}
+package org.vanbest.xmltv;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+public class Channel {\r
+ String id;\r
+ List<String> names; // at least one name is obligatory\r
+ List<Icon> icons;\r
+ List<String> urls;\r
+ protected boolean selected;\r
+ \r
+ protected Channel() {\r
+ names = new ArrayList<String>();\r
+ icons = new ArrayList<Icon>();\r
+ urls = new ArrayList<String>();\r
+ }\r
+ \r
+ public String defaultName() {\r
+ return names.get(0);\r
+ }\r
+ \r
+ static Channel getChannel(String id, String name) {\r
+ Channel c = new Channel();\r
+ c.names.add(name);\r
+ return c;\r
+ }\r
+\r
+ static Channel getChannel(String id, String name, String iconUrl) {\r
+ Channel c = new Channel();\r
+ c.names.add(name);\r
+ c.icons.add(new Icon(iconUrl));\r
+ return c;\r
+ }\r
+ \r
+ public void serialize(XMLStreamWriter writer) throws XMLStreamException {\r
+ writer.writeStartElement("channel");\r
+ writer.writeAttribute("id", id);\r
+ for(String name: names) {\r
+ writer.writeStartElement("display-name");\r
+ writer.writeAttribute("lang", "nl");\r
+ writer.writeCharacters(name);\r
+ writer.writeEndElement();\r
+ }\r
+ for(Icon i: icons) {\r
+ i.serialize(writer);\r
+ }\r
+ for(String url: urls) {\r
+ writer.writeStartElement("url");\r
+ writer.writeCharacters(url);\r
+ writer.writeEndElement();\r
+ }\r
+ writer.writeEndElement();\r
+ writer.writeCharacters(System.getProperty("line.separator"));\r
+ }\r
+\r
+ // Convenience method\r
+ public void addIcon(String url) {\r
+ icons.add(new Icon(url));\r
+ }\r
+}
\ No newline at end of file
if (!c.selected) {
out.print("#");
}
- out.print("channel: " + c.id + ": " + escape(c.name));
- if (c.iconUrl != null) {
- out.print(" : " + escape(c.iconUrl));
+ // FIXME: handle multiple channels names, icons and urls
+ out.print("channel: " + c.id + ": " + escape(c.defaultName()));
+ if (!c.icons.isEmpty()) {
+ out.print(" : " + escape(c.icons.get(0).url));
}
out.println();
}
if (s.startsWith("#")) continue;
List<String> parts = splitLine(s);
if (parts.get(0).toLowerCase().equals("channel")) {
- Channel c = new Channel(Integer.parseInt(parts.get(1)), parts.get(2), "");
+ Channel c = Channel.getChannel(parts.get(1), parts.get(2));
if (parts.size()>3) {
- c.setIconUrl(parts.get(3));
+ c.addIcon(parts.get(3));
}
result.channels.add(c);
}
for (int day=offset; day<offset+days; day++) {
if (!config.quiet) System.out.print("Fetching information for day " + day);
Set<Programme> programmes = new HashSet<Programme>();
- for( Channel c: config.channels ) {
+ for(Channel c: config.channels) {
if (!config.quiet) System.out.print(".");
- ArrayList<Channel> cs = new ArrayList<Channel>(2);
+ ArrayList<TvGidsChannel> cs = new ArrayList<TvGidsChannel>(2);
cs.add(c);
Set<Programme> p = gids.getProgrammes(cs, day, true);
writer.writePrograms(p);
TvGids gids = new TvGids(config);
Set<Integer> oldChannels = new HashSet<Integer>();
- for (Channel c: config.channels) {
+ for (TvGidsChannel c: config.channels) {
oldChannels.add(c.id);
}
List<Channel> channels = gids.getChannels();
boolean keep = false;
for (Channel c: channels) {
boolean selected = oldChannels.contains(c.id);
- System.out.print("add channel " + c.id + " (" + c.name + ") [[y]es,[n]o,[a]ll,[none],[k]eep selection (default=" + (selected?"yes":"no") + ")] ");
+ System.out.print("add channel " + c.id + " (" + c.defaultName() + ") [[y]es,[n]o,[a]ll,[none],[k]eep selection (default=" + (selected?"yes":"no") + ")] ");
if (keep) {
c.selected = selected;
System.out.println(selected?"Y":"N");
String highlight_afbeelding;
String highlight_content;
ProgrammeDetails details = null;
- Channel channel = null;
+ TvGidsChannel channel = null;
public void fixup(Config config) {
this.titel = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(titel);
JSONObject zender = jsonArray.getJSONObject(i);
//System.out.println( "id: " + zender.getString("id"));
//System.out.println( "name: " + zender.getString("name"));
- Channel c = new Channel(zender.getInt("id"), zender.getString("name"), zender.getString("name_short"));
- c.setIconUrl("http://tvgidsassets.nl/img/channels/53x27/" + c.id + ".png");
- c.fixup();
+ //TvGidsChannel c = new TvGidsChannel(zender.getInt("id"), zender.getString("name"), zender.getString("name_short"));
+ //c.setIconUrl("http://tvgidsassets.nl/img/channels/53x27/" + c.id + ".png");
+ int id = zender.getInt("id");
+ String name = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(zender.getString("name"));
+ String icon = "http://tvgidsassets.nl/img/channels/53x27/" + id + ".png";
+ Channel c = Channel.getChannel(Integer.toString(id), name, icon);
result.add(c);
}
}
- public static URL programmeUrl(List<Channel> channels, int day) throws Exception {
+ public static URL programmeUrl(List<TvGidsChannel> channels, int day) throws Exception {
StringBuilder s = new StringBuilder(programme_base_url);
if (channels.size() < 1) {
throw new Exception("should have at least one channel");
}
s.append("?channels=");
boolean first = true;
- for(Channel i: channels) {
+ for(TvGidsChannel i: channels) {
if (first) {
s.append(i.id);
first = false;
return new URL(s.toString());
}
- public Set<Programme> getProgrammes(List<Channel> channels, int day, boolean fetchDetails) throws Exception {
+ public Set<Programme> getProgrammes(List<TvGidsChannel> channels, int day, boolean fetchDetails) throws Exception {
Set<Programme> result = new HashSet<Programme>();
URL url = programmeUrl(channels, day);
JSONObject jsonObject = fetchJSON(url);
//System.out.println( jsonObject );
- for( Channel c: channels) {
+ for( TvGidsChannel c: channels) {
JSON ps = (JSON) jsonObject.get(""+c.id);
if ( ps.isArray() ) {
JSONArray programs = (JSONArray) ps;
--- /dev/null
+package org.vanbest.xmltv;
+
+/*
+ Copyright (c) 2012 Jan-Pascal van Best <janpascal@vanbest.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ The full license text can be found in the LICENSE file.
+*/
+
+public class TvGidsChannel {
+ int id;
+ String name;
+ String shortName;
+ String iconUrl;
+ boolean selected;
+
+ public TvGidsChannel(int id, String name, String shortName) {
+ this.id = id;
+ this.name = name;
+ this.shortName = shortName;
+ }
+ public String toString() {
+ return "id: " + id + "; name: " + name + "; shortName: " + shortName;
+ }
+
+ public String getChannelId() {
+ return id+".tvgids.nl";
+ }
+
+ public void fixup() {
+ this.name = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(name);
+ this.shortName = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(shortName);
+ }
+ public void setIconUrl(String url) {
+ this.iconUrl = url;
+ }
+}
public void writeChannels(List<Channel> channels) throws XMLStreamException {
for(Channel c: channels) {
- writer.writeStartElement("channel");
- writer.writeAttribute("id", c.getChannelId());
- writer.writeStartElement("display-name");
- writer.writeAttribute("lang", "nl");
- writer.writeCharacters(c.name);
- writer.writeEndElement();
-
- if (c.iconUrl != null) {
- writer.writeStartElement("icon");
- writer.writeAttribute("src", c.iconUrl);
- writer.writeEndElement();
- }
-
- writer.writeEndElement();
- writeln(); }
+ c.serialize(writer);
+ writeln();
+ }
}
/* TODO: