X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fimdb%2Fimdb-line-parser.vala;h=7963fda139926b6e11dedfbe5694466a90ed2ff5;hb=3f4b39fa556e8274fd7231eb44baaadb3d904dec;hp=1218cbf3eb70621795b86ed8a8b56324e9f7144b;hpb=61f7fd596bea1fbb1c0573e519e7c6d4ffb7c668;p=cinaest diff --git a/src/imdb/imdb-line-parser.vala b/src/imdb/imdb-line-parser.vala index 1218cbf..7963fda 100644 --- a/src/imdb/imdb-line-parser.vala +++ b/src/imdb/imdb-line-parser.vala @@ -226,3 +226,89 @@ class AkaLineParser : LineParser { } } } + +class PlotLineParser : LineParser { + enum PlotState { + HEADER, + NONE, + TITLE + } + string title; + string plot; + PlotState state; + + public PlotLineParser (IMDbSqlite _sqlite) { + base (_sqlite); + state = PlotState.HEADER; + title = null; + } + + public override void parse_line (string line) { + if (state == PlotState.HEADER) { + if (line == "PLOT SUMMARIES LIST") title = line; + if (line == "===================" && title != null) + state = PlotState.NONE; + return; + } + + // Skip empty lines + if (line == "") + return; + + if (state == PlotState.NONE) { + if (line.has_prefix ("MV: ")) { + // Skip series episodes + if (line[4] == '"') + return; + + try { + title = convert (line.offset (4), -1, "utf-8", "latin1"); + } catch (ConvertError e) { + stderr.printf ("Error converting title to UTF-8\n"); + title = null; + return; + } + + if (skip_title (title)) + return; + + state = PlotState.TITLE; + plot = ""; + } + return; + } + + if (state == PlotState.TITLE) { + if (line.has_prefix ("PL: ")) { + if (skip_title (title)) + return; + + try { + if (plot != "") + plot += " "; + plot += convert (line.offset (4), -1, "utf-8", "latin1"); + } catch (ConvertError e) { + stderr.printf ("Error converting plot for \"%s\" to UTF-8\n", title); + plot = ""; + return; + } + } + + // BY: tag marks end of plot + if (line.has_prefix ("BY: ")) { + string author; + try { + author = convert (line.offset (4), -1, "utf-8", "latin1"); + } catch (ConvertError e) { + stderr.printf ("Error converting plot author for \"%s\" to UTF-8\n", title); + author = null; + } + + sqlite.add_plot (title, plot, author); + + state = PlotState.NONE; + return; + } + } + } +}