IMDb plugin + downloader: parse IMDb alternative titles and use to match
[cinaest] / src / imdb / imdb-plaintext-downloader.vala
index 821c9a2..a978527 100644 (file)
@@ -72,6 +72,7 @@ class IMDbDownloadServer : Object, IMDbDownloader {
                        var movie_parser = new MovieLineParser (sqlite);
                        var genre_parser = new GenreLineParser (sqlite);
                        var rating_parser = new RatingLineParser (sqlite);
+                       var aka_parser = new AkaLineParser (sqlite);
 
                        var downloader = new IMDbFtpDownloader (cancellable);
                        downloader.progress_changed.connect (on_progress_changed);
@@ -80,16 +81,21 @@ class IMDbDownloadServer : Object, IMDbDownloader {
                                description_changed ("Downloading movie list ...");
                                downloader.download (url + "movies.list.gz", movie_parser);
                        }
-                       percent_finished = 33;
+                       percent_finished = 25;
                        if (GENRES in flags) {
                                description_changed ("Downloading genre data ...");
                                downloader.download (url + "genres.list.gz", genre_parser);
                        }
-                       percent_finished = 66;
+                       percent_finished = 50;
                        if (RATINGS in flags) {
                                description_changed ("Downloading rating data ...");
                                downloader.download (url + "ratings.list.gz", rating_parser);
                        }
+                       percent_finished = 75;
+                       if (AKAS in flags) {
+                               description_changed ("Downloading alternative titles ...");
+                               downloader.download (url + "aka-titles.list.gz", aka_parser);
+                       }
                } catch (Error e2) {
                        if (e2 is IOError.CANCELLED)
                                stdout.printf ("Download cancelled.\n");
@@ -98,6 +104,8 @@ class IMDbDownloadServer : Object, IMDbDownloader {
                }
 
                description_changed ("Creating indices ...");
+               if (AKAS in flags)
+                       sqlite.create_aka_index ();
                if (MOVIES in flags)
                        sqlite.create_votes_index ();
 
@@ -115,7 +123,7 @@ class IMDbDownloadServer : Object, IMDbDownloader {
        }
 
        private void on_progress_changed (int percent) {
-               progress (percent_finished + percent / 3);
+               progress (percent_finished + percent / 4);
        }
 
        private void timeout_quit () {