IMDb plugin + downloader: parse IMDb plots
[cinaest] / src / imdb / imdb-sqlite.vala
index 44b8a98..7371725 100644 (file)
@@ -143,6 +143,29 @@ class IMDbSqlite : Object {
                return 0;
        }
 
+       public int add_plot (string title, string plot, string? author) {
+               int rowid;
+
+               if (!movie_exists (title, out rowid))
+                       return 1;
+
+               string sql;
+               if (author != null) {
+                       sql = "INSERT INTO Plots(rowid, Plot, Author) VALUES (%d, \"%s\", \"%s\");".printf (rowid, plot.replace ("\"", """), author.replace ("\"", """));
+               } else {
+                       sql = "INSERT INTO Plots(rowid, Plot) VALUES (%d, \"%s\");".printf (rowid, plot.replace ("\"", """));
+               }
+               int rc;
+               rc = db.exec (sql, callback, null);
+               if (rc != Sqlite.OK) {
+                       stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
+                       stderr.printf ("offending SQL: %s\n", sql);
+                       return 1;
+               }
+
+               return 0;
+       }
+
        public bool movie_exists (string title, out int rowid = null) {
                string sql = "SELECT rowid FROM Movies WHERE Title=\"%s\"".printf (title);
                Statement stmt;
@@ -176,7 +199,9 @@ class IMDbSqlite : Object {
                        "DROP TABLE IF EXISTS Genres;" +
                        "CREATE TABLE Genres (Bit INTEGER PRIMARY KEY, Genre TEXT NOT NULL);" +
                        "DROP TABLE IF EXISTS Akas;" +
-                       "CREATE TABLE Akas (Aka TEXT NOT NULL COLLATE NOCASE, TitleID INTEGER NOT NULL);",
+                       "CREATE TABLE Akas (Aka TEXT NOT NULL COLLATE NOCASE, TitleID INTEGER NOT NULL);" +
+                       "DROP TABLE IF EXISTS Plots;" +
+                       "CREATE TABLE Plots (Plot TEXT NOT NULL, Author TEXT)",
                        callback, null);
                if (rc != Sqlite.OK) {
                        stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());