Google plugin: if location is unset, parse and set it from the Google query
[cinaest] / src / plugins / google-parser.vala
index 5ccdcb9..2bf3ef2 100644 (file)
@@ -32,6 +32,7 @@ public class GoogleParser : Object {
        private MovieSource.ReceiveMovieFunction _get_callback;
        char *current;
        string cinema_name;
+       public string location;
        MovieFilter _filter;
        PatternSpec pattern;
 
@@ -239,13 +240,17 @@ public class GoogleParser : Object {
        public void parse (ref char[] buf) throws Error {
                current = buf;
                next_tag ();
-
-               {
+               while (location == null && current[0] != 0) {
                        int i = 1;
                        while (current[i++] != '>');
                        if (((string) current).has_prefix ("<a href=\"/movies?near=")) {
-                               weak string href = parse_tag_attribute ("a", "href").offset (13); // "/movies?near=" ->"berlin&amp;date=1"
-                               // TODO - extract location and cache it
+                               string href = parse_tag_attribute ("a", "href");
+                               char* p = (char*) href.offset (13); // skip "/movies?near="
+                               int j = -1;
+
+                               while (p[++j] != '&' && p[j] != 0);
+                               p[0] = p[0].toupper ();
+                               location = ((string) p).ndup (j);
                        }
                        current += i;
                        next_tag ();