From: Philipp Zabel Date: Sun, 24 Jan 2010 13:53:29 +0000 (+0100) Subject: Add temporary get_plot functionality for plugins to provide plot descriptions X-Git-Tag: v0.0.10~8 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=ed74356d503257b871b776b7e46c393fae2045e3;p=cinaest Add temporary get_plot functionality for plugins to provide plot descriptions The IMDb plugin provides plots if the user chose to download them. --- diff --git a/src/imdb/imdb-sqlite.vala b/src/imdb/imdb-sqlite.vala index 2e13ef2..32ac41c 100644 --- a/src/imdb/imdb-sqlite.vala +++ b/src/imdb/imdb-sqlite.vala @@ -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; diff --git a/src/movie.vala b/src/movie.vala index 19f0629..f23059a 100644 --- a/src/movie.vala +++ b/src/movie.vala @@ -32,5 +32,10 @@ public class Movie : Object { construct { rating = -1; } + + public virtual string get_plot () { + print ("get_plot(%s)", title); + return ""; + } } diff --git a/src/plugins/imdb-plugin.vala b/src/plugins/imdb-plugin.vala index 2fbf482..a15b05b 100644 --- a/src/plugins/imdb-plugin.vala +++ b/src/plugins/imdb-plugin.vala @@ -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;