1 abstract class LineParser {
2 internal unowned IMDbSqlite sqlite;
4 public LineParser (IMDbSqlite _sqlite) {
8 public abstract void parse_line (string line);
10 internal bool skip_title (string title) {
11 if (title.has_suffix ("(TV)")) {
14 if (title.has_suffix ("(V)")) {
17 if (title.has_suffix ("(VG)")) {
24 class MovieLineParser : LineParser {
27 public MovieLineParser (IMDbSqlite _sqlite) {
30 re_movie = new Regex ("^([^\t]+)\t+([0-9]+)$");
31 } catch (RegexError e) {
32 critical ("Failed to initialize regex: %s\n", e.message);
36 public override void parse_line (string line) {
39 // Skip series episodes
43 if (!re_movie.match(line, 0, out matchinfo))
47 string year = matchinfo.fetch (2);
49 title = convert(matchinfo.fetch (1), -1, "utf-8", "latin1");
50 } catch (ConvertError e) {
54 if (skip_title (title))
57 sqlite.add_movie (title, year.to_int ());
61 class GenreLineParser : LineParser {
64 public GenreLineParser (IMDbSqlite _sqlite) {
67 re_genre = new Regex ("^([^\t]+)\t+([A-Za-z-]+)$");
68 } catch (RegexError e) {
69 critical ("Failed to initialize regex: %s\n", e.message);
73 public override void parse_line (string line) {
76 // Skip series episodes
80 if (!re_genre.match(line, 0, out matchinfo))
84 string genre = matchinfo.fetch (2);
86 title = convert(matchinfo.fetch (1), -1, "utf-8", "latin1");
87 } catch (ConvertError e) {
91 sqlite.movie_add_genre (title, genre);
95 class RatingLineParser : LineParser {
98 public RatingLineParser (IMDbSqlite _sqlite) {
101 re_rating = new Regex ("^ .+ +([0-9]+) +([0-9.]+) +(.+)$");
102 } catch (RegexError e) {
103 critical ("Failed to initialize regex: %s\n", e.message);
107 public override void parse_line (string line) {
110 // Skip series episodes
114 if (!re_rating.match(line, 0, out matchinfo))
118 string votes = matchinfo.fetch (1);
119 string rating = matchinfo.fetch (2);
121 title = convert(matchinfo.fetch (3), -1, "utf-8", "latin1");
122 } catch (ConvertError e) {
126 // Skip series episodes
130 if (skip_title (title))
133 sqlite.movie_set_rating (title, (int) (rating.to_double () * 10), votes.to_int ());