IMDb downloader: let the RatingLineParser skip the header
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 6 Jan 2010 14:39:08 +0000 (15:39 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 6 Jan 2010 17:37:00 +0000 (18:37 +0100)
src/imdb/imdb-line-parser.vala

index 25d1658..1218cbf 100644 (file)
@@ -93,10 +93,16 @@ class GenreLineParser : LineParser {
 }
 
 class RatingLineParser : LineParser {
+       enum RatingState {
+               HEADER,
+               NONE
+       }
+       RatingState state;
        Regex re_rating;
 
        public RatingLineParser (IMDbSqlite _sqlite) {
                base (_sqlite);
+               state = RatingState.HEADER;
                try {
                        re_rating = new Regex ("^      .+ +([0-9]+) +([0-9.]+) +(.+)$");
                } catch (RegexError e) {
@@ -105,6 +111,15 @@ class RatingLineParser : LineParser {
        }
 
        public override void parse_line (string line) {
+               if (state == RatingState.HEADER) {
+                       if (line == "MOVIE RATINGS REPORT")
+                               state = RatingState.NONE;
+                       return;
+               }
+
+               if (state != RatingState.NONE)
+                       return;
+
                MatchInfo matchinfo;
 
                // Skip series episodes
@@ -117,7 +132,7 @@ class RatingLineParser : LineParser {
                string title;
                string votes = matchinfo.fetch (1);
                string rating = matchinfo.fetch (2);
-               try {
+               try {
                        title = convert(matchinfo.fetch (3), -1, "utf-8", "latin1");
                } catch (ConvertError e) {
                        return;