")) {
- parse_movie ();
- movies++;
- } else if (((string) current).has_prefix("
")) {
- parse_cinema ();
- } else {
- current += i;
+ Xml.Node* search_tag_by_property (Xml.Node* node, string tag, string prop, string val) requires (node != null) {
+ for (var n = node; n != null; n = n->next) {
+ if (n->name == tag && n->get_prop (prop) == val)
+ return n;
+ if (n->children != null) {
+ var found = search_tag_by_property (n->children, tag, prop, val);
+ if (found != null)
+ return found;
}
- next_tag ();
}
+ return null;
+ }
- return movies;
+ Xml.Node* search_tag_by_class (Xml.Node* node, string tag, string @class) requires (node != null) {
+ return search_tag_by_property (node, tag, "class", @class);
}
public async int query (string title, string? location, ReceiveMovie callback, Cancellable? cancellable = null) {
@@ -365,22 +251,8 @@ public class GoogleParser : Object {
stdout.printf ("GET: %s\n", uri);
- File file = File.new_for_uri (uri);
- InputStream stream = yield file.read_async (Priority.DEFAULT_IDLE, null);
-
- char[] buf = new char[256*1024];
- size_t nread;
- size_t total = 0;
- while (total < 256*1024) {
- nread = yield stream.read_async ((char *)buf + total, 256*1024 - total, Priority.DEFAULT_IDLE, cancellable);
- total += nread;
- if (cancellable.is_cancelled ())
- return 0;
- if (nread == 0)
- break;
- }
- buf[total] = 0;
- return parse (ref buf);
+ string buf = yield curlwrapper.http_get (uri);
+ return parse (buf);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}