Google plugin/backend: turn runtime string into an integer (in seconds)
[cinaest] / src / plugins / google-plugin.vala
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);
                }