/*
* Created on Feb 8, 2006
*
*/
package org.gnu.dwarf.sage.netflix.show;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import org.gnu.dwarf.sage.netflix.ConfigUtil;
import org.gnu.dwarf.sage.netflix.HTMLParser;
import org.gnu.dwarf.sage.netflix.IdxDtl;
import org.gnu.dwarf.sage.netflix.Logger;
import org.gnu.dwarf.sage.netflix.show.Episode;
import org.gnu.dwarf.sage.netflix.remote.WatchNowMovieRemote;
import org.gnu.dwarf.sage.netflix.remote.InvalidResponseCodeException;
/**
*/
public class EpisodeHTMLParser extends HTMLParser {
private static final String[] htmlCodeMovieListStart = {"class='inactive'","id=\"wnGalleryPage\""};
private static final String[] htmlCodeMovieItemStart = {"
",""," | "};
private static final String[] htmlCodeMovieIdStart = {"id=\"b0","id=\"ag"};
private static final String[] htmlCodeMovieTitleStart = {"class=\"list-title\">","class=\"title\">"};
private static final String[] htmlCodeMovieNextPgStart = {"class=\"morelink\"","paginationLink-next"};
private int browseTypeIndex;
EpisodeHTMLParser() {
}
public final List getShowEpisodeList(String showId) {
List episodes = new ArrayList();
String detail;
try {
//Logger.debug("EpisodeHTMLParser().getShows("+showId);
WatchNowMovieRemote remote = new WatchNowMovieRemote();
detail = remote.processRequest(showId);
//Logger.log(detail);
} catch (IOException e) {
throw new ShowNotFoundException(e);
} catch (InvalidResponseCodeException e) {
throw new ShowNotFoundException(e);
}
long startTime = System.currentTimeMillis();
int start = detail.indexOf("class=\"epDetailsLink\"");
if (start==-1) {
Logger.debug(" start not found:"+"class=\"epDetailsLink\"");
}
// Locate end of genre list
int end = detail.indexOf("style type=\"text/css",start+"class=\"epDetailsLink\"".length());
//Logger.log("EpisodeHTMLParser start:"+start+" end:"+end);
IdxDtl dtl = new IdxDtl("foo", detail.substring(start, end));
//Logger.log("EpisodeHTMLParser detail:"+dtl.getSource());
while ( true ) {
start = dtl.getSource().indexOf("class=\"movie seriesMember");
if (start==-1) {
Logger.debug(" start not found:"+"class=\"movie seriesMember\"");
break;
}
end = dtl.getSource().indexOf("", start);
//Logger.log("ShowBrowseHTMLParser start:"+start+" end:"+end);
//Logger.log("ShowBrowseHTMLParser detail:"+dtl.getSource().substring(start, end));
dtl = new IdxDtl(dtl.getSource().substring(start,end+6), dtl.getSource().substring(end+6));
//Logger.log("Show Episode HTML detail:"+dtl.getDetail());
if ( dtl.getDetail() == null ) break;
IdxDtl title = parse(dtl.getDetail(), "class=\"title\"", "<", null, ">");
//Logger.debug("--title:" + title.getDetail());
IdxDtl descr = parse(dtl.getDetail(), "class=\"synopsis\"", "<", "", ">");
//Logger.debug("--descr:"+descr.getDetail());
IdxDtl duration = parse(dtl.getDetail(), "Length:", "<", "", null);
//Logger.debug("--duration:" + duration.getDetail());
IdxDtl id = parse(dtl.getDetail(), " watchlk ", "_", "", "id=\"m");
//Logger.debug("--id:" + id.getDetail());
Episode episode = new Episode(title.getDetail(),descr.getDetail(),duration.getDetail(), id.getDetail());
episodes.add(episode);
if ( dtl.getDetail() == null ) break;
}
// Logger.debug("dtl.getSource():"+dtl.getSource());
return episodes;
}
/*
public static final void main(String[] args) throws Exception {
String[] movieIds = new String[] { "70056066" };
//String[] movieIds = new String[] { "22335786", "70018292" };
ConfigUtil.setUserId(args[0]);
ConfigUtil.setUsername(args[1]);
ConfigUtil.setPassword(args[2]);
ConfigUtil.setCacheDirPath("C:\\temp\\netflix");
for (int x = 0; x < movieIds.length; x++) {
ShowHTMLParser parser = new ShowHTMLParser(movieIds[x]);
try {
Show show = parser.getShow();
Logger.log("id:\t"+show.getId());
Logger.log("title:\t"+show.getTitle());
Logger.log("desc:\t"+show.getDescription());
Logger.log("actors:\t"+show.getActors());
Logger.log("director:\t"+show.getDirectors());
Logger.log("mpaa:\t"+show.getMpaa());
Logger.log("mpaaUrl:\t"+show.getMpaaIconUrl());
Logger.log("watchitnow:\t"+show.getHasWatchItNow());
Logger.log("mpaa:\t"+show.getMpaa());
Logger.log("genre:\t"+show.getGenre());
Logger.log("movielength:\t"+show.getMovieLength());
Logger.log("trailerurl:\t"+show.getTrailerUrl());
//parser.cacheBoxShot(movieIds[x]);
//System.out.println("final result:"+
// parser.removeHTML("Bambii is a hippoLink Contentpottomus"));
//System.out.println("final result:"+
// parser.removeHTML(" foo foo&foo"foo""));
} catch (ShowNotFoundException e) {
Logger.log(e);
}
}
}
*/
}