Google plugin/backend: turn runtime string into an integer (in seconds)
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 10 Feb 2010 17:52:21 +0000 (18:52 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 14 Jul 2010 21:34:08 +0000 (23:34 +0200)
src/backends/google/google-backend.vala
src/backends/google/google-parser.vala
src/plugins/google-plugin.vala

index 6a375b8..1b78685 100644 (file)
@@ -68,7 +68,7 @@ public class MovieSearch : Object {
                var m = new string[results.length ()];
                int i = 0;
                for (unowned GLib.List<GoogleMovie> node = results.first (); node != null; node = node.next) {
-                       m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.showtimes, node.data.cinema.name, node.data.cinema.phone);
+                       m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"runtime\":%d,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.runtime, node.data.showtimes, node.data.cinema.name, node.data.cinema.phone);
                }
                movies_found (m, true);
                service.timeout_quit ();
index 886772d..6254416 100644 (file)
@@ -34,9 +34,8 @@ public class Cinema {
 public class GoogleMovie {
        public string title;
        public int rating;
-       public string secondary;
        public Cinema cinema;
-       public string runtime;
+       public int runtime;
        public string fsk;
        public string showtimes;
 }
@@ -259,18 +258,16 @@ public class GoogleParser : Object {
                movie.rating = (int) (rating * 10);
 
                movie.cinema = last_cinema;
+               movie.runtime = 0;
                if (runtime_and_fsk.length >= 2) {
-                       movie.runtime = runtime_and_fsk[0];
+                       unowned string runtime = runtime_and_fsk[0];
+                       movie.runtime = 3600 * runtime.to_int ();
+                       runtime = runtime.str ("hr ");
+                       if (runtime != null)
+                               movie.runtime += 60 * runtime.offset (3).to_int ();
                        movie.fsk = runtime_and_fsk[1];
                }
                movie.showtimes = showtimes;
-
-               // TODO - could be configurable by settings
-               if (movie.runtime != null)
-                       movie.secondary = "%s - %s - %s".printf (movie.runtime, last_cinema.name, showtimes);
-               else
-                       movie.secondary = "%s - %s".printf (last_cinema.name, showtimes);
-
                _get_callback (movie);
        }
 
index 5491a6d..d02b7a8 100644 (file)
@@ -22,7 +22,7 @@ using Hildon;
 public class GoogleMovie : Movie {
        public string cinema_name;
        public string cinema_phone;
-       public string runtime;
+       public int runtime;
        public string showtimes;
 }
 
@@ -96,7 +96,7 @@ class GooglePlugin : Plugin {
                        timeinfo.hour = hour;
                        showtime = timeinfo.mktime ();
 
-                       int runtime = 3600 * movie.runtime.to_int () + 60 * movie.runtime.str ("hr ").offset (3).to_int ();
+                       int runtime = movie.runtime;
                        if (runtime == 0) {
                                // Default to 120min if we failed to parse the runtime
                                runtime = 7200;
@@ -258,8 +258,12 @@ class GoogleSource : MovieSource {
                        movie.rating = (int) object.get_double_member ("rating");
                        movie.cinema_name = object.get_string_member ("cinema_name");
                        movie.cinema_phone = object.get_string_member ("cinema_phone");
+                       movie.runtime = (int) object.get_int_member ("runtime");
                        movie.showtimes = object.get_string_member ("showtimes");
-                       movie.secondary = movie.cinema_name + " - " + movie.showtimes;
+                       if (movie.runtime > 0)
+                               movie.secondary = "%d min - %s - %s".printf (movie.runtime / 60, movie.cinema_name, movie.showtimes);
+                       else
+                               movie.secondary = movie.cinema_name + " - " + movie.showtimes;
 
                        callback (movie);
                }