Add temporary get_plot functionality for plugins to provide plot descriptions
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sun, 24 Jan 2010 13:53:29 +0000 (14:53 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 30 Jan 2010 11:20:04 +0000 (12:20 +0100)
The IMDb plugin provides plots if the user chose to download them.

src/imdb/imdb-sqlite.vala
src/movie.vala
src/plugins/imdb-plugin.vala

index 2e13ef2..32ac41c 100644 (file)
@@ -217,6 +217,29 @@ class IMDbSqlite : Object {
                return (count ("Plots") > 0);
        }
 
+       public string get_plot (string title) {
+               string sql = "SELECT Plot FROM Plots WHERE rowid in (SELECT rowid FROM Movies WHERE Title=\"%s\")".printf (title);
+               Statement stmt;
+               int rc;
+               int count = 0;
+
+               rc = db.prepare_v2 (sql, -1, out stmt);
+               if (rc != Sqlite.OK) {
+                       stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
+                       db.progress_handler (0, null);
+                       return "";
+               }
+
+               do {
+                       rc = stmt.step ();
+                       if (rc == Sqlite.ROW) {
+                               return stmt.column_text (0);
+                       }
+               } while (rc == Sqlite.ROW);
+
+               return "";
+       }
+
        public int clear () {
                int rc;
 
index 19f0629..f23059a 100644 (file)
@@ -32,5 +32,10 @@ public class Movie : Object {
        construct {
                rating = -1;
        }
+
+       public virtual string get_plot () {
+               print ("get_plot(%s)", title);
+               return "";
+       }
 }
 
index 2fbf482..a15b05b 100644 (file)
@@ -174,6 +174,15 @@ class IMDbPlugin : Plugin {
        }
 }
 
+class IMDbMovie : Movie {
+       public override string get_plot () {
+               var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (),
+                                            "cinaest", "imdb.db", null));
+               print ("IMDb get_plot(\"%s (%d)\")\n", title, year);
+               return sqlite.get_plot ("%s (%d)".printf (title, year));
+       }
+}
+
 class IMDBSource : MovieSource {
        public override bool active { get; set construct; }
 
@@ -192,7 +201,7 @@ class IMDBSource : MovieSource {
        }
 
        private void receive_movie (string title, string? aka, int year, int rating, int genres) {
-               Movie movie = new Movie ();
+               var movie = new IMDbMovie ();
                movie.title = title;
                movie.year = year;
                movie.rating = rating;