package org.vanbest.xmltv;\r
\r
+import java.io.PrintWriter;\r
import java.util.ArrayList;\r
import java.util.List;\r
import javax.xml.stream.XMLStreamException;\r
import javax.xml.stream.XMLStreamWriter;\r
+import org.apache.log4j.Logger;\r
\r
public class Channel {\r
String id;\r
List<String> urls;\r
protected boolean enabled = true;\r
int source;\r
+ static Logger logger = Logger.getLogger(Channel.class);\r
\r
protected Channel(int source, String id) {\r
this.id = id;\r
}\r
\r
static Channel getChannel(int source, String id, String name) {\r
- Channel c = new Channel(source, id);\r
+ Channel c;\r
+ if(EPGSourceFactory.getChannelSourceName(source).equals(Horizon.NAME)) {\r
+ long horizonId=Long.parseLong(id);\r
+ c = new Horizon.HorizonChannel(source, id, horizonId);\r
+ } else {\r
+ c = new Channel(source, id);\r
+ }\r
c.names.add(name);\r
return c;\r
}\r
\r
- static Channel getChannel(int source, String id, String name, String iconUrl) {\r
- Channel c = new Channel(source, id);\r
- c.names.add(name);\r
- if (iconUrl != null) {\r
- c.icons.add(new Icon(iconUrl));\r
+ static Channel getChannel(int source, String id, String name, String extraConfig) {\r
+ Channel c;\r
+ if(EPGSourceFactory.getChannelSourceName(source).equals(Horizon.NAME)) {\r
+ long horizonId=Long.parseLong(extraConfig);\r
+ c = new Horizon.HorizonChannel(source, id, horizonId);\r
+ } else {\r
+ c = new Channel(source, id);\r
}\r
+ c.names.add(name);\r
return c;\r
}\r
\r
this.enabled = b;\r
}\r
\r
+ public String extraConfig() {\r
+ return "";\r
+ }\r
+\r
+ // must start with channel: <sourcename>\r
+ public void writeConfig(PrintWriter out) {\r
+ // FIXME: handle multiple channels names, icons and urls\r
+ out.print("channel: " + getSourceName() + ": "\r
+ + id + ": "\r
+ + (enabled ? "enabled" : "disabled") + ": "\r
+ + Config.escape(defaultName()) + ": "\r
+ + Config.escape(extraConfig()));\r
+ if (!icons.isEmpty()) {\r
+ out.print(" : " + Config.escape(icons.get(0).url));\r
+ }\r
+ out.println();\r
+ }\r
+\r
+ public static Channel parseConfig(int fileformat, List<String> parts) {\r
+ Channel c = null;\r
+ switch (fileformat) {\r
+ case 0:\r
+ c = Channel.getChannel(EPGSourceFactory.newInstance()\r
+ .getChannelSourceId("tvgids.nl"), parts.get(1),\r
+ parts.get(2));\r
+ if (parts.size() > 3) {\r
+ c.addIcon(parts.get(3));\r
+ }\r
+ break;\r
+ case 1:\r
+ c = Channel.getChannel(EPGSourceFactory.newInstance()\r
+ .getChannelSourceId("tvgids.nl"), parts.get(1),\r
+ parts.get(3));\r
+ if (parts.size() > 4) {\r
+ c.addIcon(parts.get(4));\r
+ }\r
+ String value = parts.get(2);\r
+ if (value.equals("enabled")) {\r
+ c.setEnabled(true);\r
+ } else if (value.equals("disabled")) {\r
+ c.setEnabled(false);\r
+ } else {\r
+ logger.error("Error in config file, unknown channel status \""\r
+ + parts.get(2)\r
+ + "\", should be enabled or disabled");\r
+ }\r
+ break;\r
+ case 2:\r
+ case 3:\r
+ case 4:\r
+ case 5:\r
+ int source;\r
+ if (fileformat == 2) {\r
+ source = Integer.parseInt(parts.get(1));\r
+ } else {\r
+ source = EPGSourceFactory.newInstance()\r
+ .getChannelSourceId(parts.get(1));\r
+ }\r
+ if(fileformat<5) {\r
+ c = Channel.getChannel(source, parts.get(2),\r
+ parts.get(4));\r
+ } else {\r
+ c = Channel.getChannel(source, parts.get(2),\r
+ parts.get(4), parts.get(5));\r
+ }\r
+ int iconPart = (fileformat<5?5:6);\r
+ if (parts.size() > iconPart) {\r
+ c.addIcon(parts.get(iconPart));\r
+ }\r
+ value = parts.get(3);\r
+ if (value.equals("enabled")) {\r
+ c.setEnabled(true);\r
+ } else if (value.equals("disabled")) {\r
+ c.setEnabled(false);\r
+ } else {\r
+ logger.error("Error in config file, unknown channel status \""\r
+ + parts.get(3)\r
+ + "\", should be enabled or disabled");\r
+ }\r
+ }\r
+ return c;\r
+ }\r
+\r
public String toString() {\r
return "Channel " + source + "::" + id + " (" + defaultName() + ")";\r
}\r
public class Config {
// constants
- private final static int CURRENT_FILE_FORMAT = 4;
+ private final static int CURRENT_FILE_FORMAT = 5;
// in config file
public int niceMilliseconds;
out.println("fetch-channel-logos: " + (fetchLogos?"yes":"no"));
out.println("nice-time-milliseconds: " + niceMilliseconds);
for (Channel c : channels) {
- // FIXME: handle multiple channels names, icons and urls
- out.print("channel: " + c.getSourceName() + ": " + c.id + ": "
- + (c.enabled ? "enabled" : "disabled") + ": "
- + escape(c.defaultName()));
- if (!c.icons.isEmpty()) {
- out.print(" : " + escape(c.icons.get(0).url));
- }
- out.println();
+ c.writeConfig(out);
}
for (Map.Entry<String, String> entry : cattrans.entrySet()) {
out.println("category: " + escape(entry.getKey()) + ": "
List<String> parts = splitLine(s);
String key = parts.get(0).toLowerCase();
if (key.equals("channel")) {
- Channel c = null;
// System.out.println("Adding channel " + parts +
// " in file format " + fileformat);
- switch (fileformat) {
- case 0:
- c = Channel.getChannel(EPGSourceFactory.newInstance()
- .getChannelSourceId("tvgids.nl"), parts.get(1),
- parts.get(2));
- if (parts.size() > 3) {
- c.addIcon(parts.get(3));
- }
- break;
- case 1:
- c = Channel.getChannel(EPGSourceFactory.newInstance()
- .getChannelSourceId("tvgids.nl"), parts.get(1),
- parts.get(3));
- if (parts.size() > 4) {
- c.addIcon(parts.get(4));
- }
- String value = parts.get(2);
- if (value.equals("enabled")) {
- c.setEnabled(true);
- } else if (value.equals("disabled")) {
- c.setEnabled(false);
- } else {
- logger.error("Error in config file, unknown channel status \""
- + parts.get(2)
- + "\", should be enabled or disabled");
- }
- break;
- case 2:
- case 3:
- case 4:
- int source;
- if (fileformat == 2) {
- source = Integer.parseInt(parts.get(1));
- } else {
- source = EPGSourceFactory.newInstance()
- .getChannelSourceId(parts.get(1));
- }
- c = Channel.getChannel(source, parts.get(2),
- parts.get(4));
- if (parts.size() > 5) {
- c.addIcon(parts.get(5));
- }
- value = parts.get(3);
- if (value.equals("enabled")) {
- c.setEnabled(true);
- } else if (value.equals("disabled")) {
- c.setEnabled(false);
- } else {
- logger.error("Error in config file, unknown channel status \""
- + parts.get(3)
- + "\", should be enabled or disabled");
- }
- }
+ Channel c = Channel.parseConfig(fileformat, parts);
result.channels.add(c);
} else if (key.equals("category")) {
result.cattrans.put(parts.get(1), parts.get(2));
return createEPGSource(sourceId, config);
}
- public String getChannelSourceName(int id) {
+ public static String getChannelSourceName(int id) {
+ init();
return names.get(id);
}
- public int getChannelSourceId(String name) {
+ public static int getChannelSourceId(String name) {
+ init();
return ids.get(name);
}
public class Horizon extends AbstractEPGSource implements EPGSource {
+ static class HorizonChannel extends Channel {
+ long horizonId;
+ protected HorizonChannel(int source, String id, long horizonId) {
+ super(source,id);
+ this.horizonId = horizonId;
+ }
+ protected HorizonChannel(int source, long horizonId, String name) {
+ super(source,sanitise(name));
+ this.horizonId = horizonId;
+ }
+ public String getXmltvChannelId() {
+ return sanitise(defaultName()) + "." + getSourceName();
+ }
+ public static String sanitise(String name) {
+ return name.replaceAll("[^a-zA-Z0-9]","");
+ }
+ @Override
+ public String extraConfig() {
+ return Long.toString(horizonId);
+ }
+
+ }
+
static String channels_url = "https://www.horizon.tv/oesp/api/NL/nld/web/channels/";
static String listings_url = "https://www.horizon.tv/oesp/api/NL/nld/web/listings";
- // ?byStationId=28070126&sort=startTime&range=1-100&byStartTime=1362000000000~1362100000000";
public static String NAME = "horizon.tv";
return NAME;
}
- public static URL programmeUrl(Channel channel, int day)
+ public static URL programmeUrl(Channel c, int day)
throws Exception {
+ HorizonChannel channel = (HorizonChannel) c;
StringBuilder s = new StringBuilder(listings_url);
s.append("?byStationId=");
- s.append(channel.id);
+ s.append(channel.horizonId);
s.append("&sort=startTime&range=1-100");
Calendar startTime=Calendar.getInstance();
startTime.set(Calendar.HOUR_OF_DAY, 0);
JSONObject firstSchedule = stationSchedules.getJSONObject(0);
JSONObject station = firstSchedule.getJSONObject("station");
logger.debug("firstschedule: " + firstSchedule.toString());
- long id = station.getLong("id");
+ long horizonId = station.getLong("id");
String name = station.getString("title");
// Use the largest available station logo as icon
JSONArray images = station.getJSONArray("images");
maxSize = image.getInt("width");
}
}
- Channel c = Channel.getChannel(getId(), Long.toString(id), name,
- icon);
+ String id = HorizonChannel.sanitise(name);
+ Channel c = Channel.getChannel(getId(), id, name, Long.toString(horizonId));
+ //Channel c = new HorizonChannel(getId(), horizonId, name);
+ c.addIcon(icon);
result.add(c);
}
String id = genericChannelId(k.toString());\r
String name = (String) j.get(0);\r
String icon = icon_url + id + ".gif";\r
- Channel c = Channel.getChannel(getId(), id, name, icon);\r
+ Channel c = Channel.getChannel(getId(), id, name);\r
+ c.addIcon(icon);\r
result.add(c);\r
}\r
\r
.unescapeHtml(zender.getString("name"));
String icon = "http://tvgidsassets.nl/img/channels/53x27/" + id
+ ".png";
- Channel c = Channel.getChannel(getId(), Integer.toString(id), name,
- icon);
+ Channel c = Channel.getChannel(getId(), Integer.toString(id), name);
+ c.addIcon(icon);
result.add(c);
}