* add special numbering for special episodes

This commit is contained in:
Reinhard Pointner 2010-02-03 21:36:04 +00:00
parent b9027d6abc
commit ee76deccd0
3 changed files with 62 additions and 12 deletions

View File

@ -12,6 +12,7 @@ public class Episode implements Serializable {
private String season; private String season;
private String episode; private String episode;
private String title; private String title;
private String special;
protected Episode() { protected Episode() {
@ -20,15 +21,21 @@ public class Episode implements Serializable {
public Episode(String seriesName, int season, int episode, String title) { public Episode(String seriesName, int season, int episode, String title) {
this(seriesName, String.valueOf(season), String.valueOf(episode), title); this(seriesName, String.valueOf(season), String.valueOf(episode), title, null);
} }
public Episode(String seriesName, String season, String episode, String title) { public Episode(String seriesName, String season, String episode, String title) {
this(seriesName, season, episode, title, null);
}
public Episode(String seriesName, String season, String episode, String title, String special) {
this.seriesName = seriesName; this.seriesName = seriesName;
this.season = season; this.season = season;
this.episode = episode; this.episode = episode;
this.title = title; this.title = title;
this.special = special;
} }
@ -60,6 +67,20 @@ public class Episode implements Serializable {
} }
public String getSpecial() {
return special;
}
public Integer getSpecialNumber() {
try {
return new Integer(special);
} catch (NumberFormatException e) {
return null;
}
}
public String getSeriesName() { public String getSeriesName() {
return seriesName; return seriesName;
} }
@ -74,7 +95,7 @@ public class Episode implements Serializable {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Episode) { if (obj instanceof Episode) {
Episode other = (Episode) obj; Episode other = (Episode) obj;
return equals(season, other.season) && equals(episode, other.episode) && equals(seriesName, other.seriesName) && equals(title, other.title); return equals(season, other.season) && equals(episode, other.episode) && equals(seriesName, other.seriesName) && equals(title, other.title) && equals(special, other.special);
} }
return false; return false;
@ -91,7 +112,7 @@ public class Episode implements Serializable {
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(new Object[] { seriesName, season, episode, title }); return Arrays.hashCode(new Object[] { seriesName, season, episode, title, special });
} }

View File

@ -80,6 +80,7 @@ public class TVRageClient implements EpisodeListProvider {
String seriesName = selectString("Show/name", dom); String seriesName = selectString("Show/name", dom);
List<Episode> episodes = new ArrayList<Episode>(25); List<Episode> episodes = new ArrayList<Episode>(25);
List<Episode> specials = new ArrayList<Episode>(5);
// episodes and specials // episodes and specials
for (Node node : selectNodes("//episode", dom)) { for (Node node : selectNodes("//episode", dom)) {
@ -89,12 +90,18 @@ public class TVRageClient implements EpisodeListProvider {
// check if we have season and episode number, if not it must be a special episode // check if we have season and episode number, if not it must be a special episode
if (episodeNumber == null || seasonNumber == null) { if (episodeNumber == null || seasonNumber == null) {
episodeNumber = "Special"; // handle as special episode
seasonNumber = getTextContent("season", node); seasonNumber = getTextContent("season", node);
} int specialNumber = filterBySeason(specials, Integer.parseInt(seasonNumber)).size() + 1;
specials.add(new Episode(seriesName, seasonNumber, "Special " + specialNumber, title, Integer.toString(specialNumber)));
} else {
// handle as normal episode
episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, title)); episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, title));
} }
}
// add specials at the end
episodes.addAll(specials);
return episodes; return episodes;
} }

View File

@ -127,21 +127,43 @@ public class TheTVDBClient implements EpisodeListProvider {
String seriesName = selectString("Data/Series/SeriesName", seriesRecord); String seriesName = selectString("Data/Series/SeriesName", seriesRecord);
List<Node> nodes = selectNodes("Data/Episode", seriesRecord); List<Node> nodes = selectNodes("Data/Episode", seriesRecord);
episodes = new ArrayList<Episode>(nodes.size()); episodes = new ArrayList<Episode>(nodes.size());
List<Episode> specials = new ArrayList<Episode>(5);
for (Node node : nodes) { for (Node node : nodes) {
String episodeName = getTextContent("EpisodeName", node); String episodeName = getTextContent("EpisodeName", node);
String episodeNumber = getTextContent("Combined_episodenumber", node); String episodeNumber = getTextContent("EpisodeNumber", node);
String seasonNumber = getTextContent("Combined_season", node); String seasonNumber = getTextContent("SeasonNumber", node);
if (seasonNumber.equals("0")) {
// handle as special episode
String airsBefore = getTextContent("airsbefore_season", node);
if (airsBefore != null && airsBefore.matches("\\d+")) {
seasonNumber = airsBefore;
}
int specialNumber = filterBySeason(specials, Integer.parseInt(seasonNumber)).size() + 1;
specials.add(new Episode(seriesName, seasonNumber, "Special " + specialNumber, episodeName, Integer.toString(specialNumber)));
} else {
// handle as normal episode
episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, episodeName)); episodes.add(new Episode(seriesName, seasonNumber, episodeNumber, episodeName));
}
if (episodeNumber.equals("1")) { if (episodeNumber.equals("1")) {
try {
// cache seasonId for each season (always when we are at the first episode) // cache seasonId for each season (always when we are at the first episode)
// because it might be required by getEpisodeListLink // because it might be required by getEpisodeListLink
cache.putSeasonId(searchResult.getSeriesId(), Integer.parseInt(seasonNumber), Integer.parseInt(getTextContent("seasonid", node))); cache.putSeasonId(searchResult.getSeriesId(), Integer.parseInt(seasonNumber), Integer.parseInt(getTextContent("seasonid", node)));
} catch (NumberFormatException e) {
// season/episode is not a number, just ignore
} }
} }
}
// add specials at the end
episodes.addAll(specials);
cache.putEpisodeList(searchResult.getSeriesId(), language, episodes); cache.putEpisodeList(searchResult.getSeriesId(), language, episodes);
return episodes; return episodes;