sqlite.movie_set_rating (title, (int) (rating.to_double () * 10), votes.to_int ());
}
}
+
+class AkaLineParser : LineParser {
+ enum AkaState {
+ HEADER,
+ NONE,
+ TITLE
+ }
+ AkaState state;
+ string title;
+
+ public AkaLineParser (IMDbSqlite _sqlite) {
+ base (_sqlite);
+ state = AkaState.HEADER;
+ title = null;
+ }
+
+ public override void parse_line (string line) {
+ if (state == AkaState.HEADER) {
+ if (line == "AKA TITLES LIST") title = line;
+ if (line == "===============" && title != null)
+ state = AkaState.NONE;
+ return;
+ }
+
+ if (state == AkaState.NONE) {
+ // Skip empty lines
+ if (line == "")
+ return;
+
+ // Skip series episodes
+ if (line[0] == '"')
+ return;
+
+ // Parse error
+ if (line[0] == ' ')
+ return;
+
+ try {
+ title = convert (line, -1, "utf-8", "latin1");
+ } catch (ConvertError e) {
+ title = null;
+ return;
+ }
+
+ if (skip_title (title))
+ return;
+
+ state = AkaState.TITLE;
+ }
+
+ if (state == AkaState.TITLE) {
+ // Empty lines mark end of title
+ if (line == "") {
+ state = AkaState.NONE;
+ return;
+ }
+
+ if (line.has_prefix (" (aka ")) {
+ if (skip_title (title))
+ return;
+
+ char* start = line.offset (8);
+ char* end = ((string) start).str ("))");
+ if (end != null)
+ end[1] = '\0';
+
+ string aka;
+ try {
+ aka = convert ((string) start, -1, "utf-8", "latin1");
+ } catch (ConvertError e) {
+ return;
+ }
+
+ sqlite.add_aka (title, aka);
+ }
+ }
+ }
+}