ArrayList<Channel> channels = new ArrayList<Channel>();
monitor.setMessage(mLocalizer.msg("loadingChannels", "Loading Radio Times Channel List"));
// Do the parsing...
BufferedReader reader = new BufferedReader(new InputStreamReader(IOUtilities.getStream(new URL(BASEURL + "channels.dat"))));
String line;
while ((line = reader.readLine()) != null) {
String[] channel = line.split("\\|");
// format of a line in this file:
// 92|BBC1
if (channel.length == 2) {
String channelId = channel[0].trim();
String fullChannelId = RADIOTIMES + channelId;
String channelName = channel[1].trim();
int categories = Channel.CATEGORY_NONE;
if (StringUtils.containsIgnoreCase(channelName, "TV") || StringUtils.containsIgnoreCase(channelName, "HD")) {
categories = Channel.CATEGORY_TV;
}
Channel ch = null;
// try to find this channel in the known channels so we can reuse its user settings
for (Channel knownChannel : mChannels) {
if (knownChannel.getId().equals(fullChannelId) && knownChannel.getDefaultName().equalsIgnoreCase(channelName)) {
ch = knownChannel;
break;
}
}
if (ch == null) {
ch = new Channel(this, channelName, fullChannelId, TimeZone.getTimeZone("GMT+0:00"), "gb",
"(c) Radio Times", "http://www.radiotimes.co.uk", mRadioTimesChannelGroup, null, categories);
}
channels.add(ch);
mLog.fine("Channel : " + ch.getName() + "{" + ch.getId() + "}");
}
}
reader.close();
mChannels = channels;
monitor.setMessage(mLocalizer.msg("done", "Done with Radio Times data"));