private void FetchActorsInMovie() { ArrayList actors = new ArrayList(); if (_movieDetails == null) { return; } // Check for IMDBid if (VideoDatabase.CheckMovieImdbId(_movieDetails.IMDBNumber)) { // Returns nm1234567 as actor name (IMDB actorID) IMDBSearch imdbActors = new IMDBSearch(); imdbActors.SearchActors(_movieDetails.IMDBNumber, ref actors); } else { return; } if (actors.Count > 0) { // Clean old actors for movie VideoDatabase.RemoveActorsForMovie(_movieDetails.ID); for (int i = 0; i < actors.Count; ++i) { string actor = (string)actors[i]; string actorImdbId = string.Empty; string actorName = string.Empty; string role = string.Empty; bool director = false; char[] splitter = { '|' }; string[] temp = actor.Split(splitter); actorName = temp[0]; // Check if actor is movie director if (actorName.StartsWith("*d")) { actorName = actorName.Replace("*d", string.Empty); director = true; } actorImdbId = temp[1]; role = temp[2]; // Add actor and link actor to movie int actorId = VideoDatabase.AddActor(actorImdbId, actorName); if (actorId == -1) { continue; } VideoDatabase.AddActorToMovie(_movieDetails.ID, actorId, role); // Update director in movieinfo if (director) { _movieDetails.DirectorID = actorId; _movieDetails.Director = actorName; VideoDatabase.SetMovieInfoById(_movieDetails.ID, ref _movieDetails); } } } }
// Changed actors find & count display on progress bar window private void FetchActorsInMovie() { bool director = false; // Actor is director bool byImdbId = true; // Lookup by movie IMDBid number from which will get actorIMDBid, lookup by name is not so db friendly if (_movieDetails == null) { return; } ArrayList actors = new ArrayList(); // Try first by IMDBMovieId to find IMDBactorID (100% accuracy) IMDBSearch actorlist = new IMDBSearch(); // New actor search method actorlist.SearchActors(_movieDetails.IMDBNumber, ref actors); // If search by IMDBid fails try old fetch method (by name, less accurate) if (actors.Count == 0) { byImdbId = false; string cast = _movieDetails.Cast + "," + _movieDetails.Director; char[] splitter = {'\n', ','}; string[] temp = cast.Split(splitter); foreach (string element in temp) { string el = element.Trim(); if (el != string.Empty) { actors.Add(el); } } } if (actors.Count > 0) { int percent = 0; for (int i = 0; i < actors.Count; ++i) { // Is actor movie director?? switch (byImdbId) // True-new method, false-old method { case true: { // Director if (actors[i].ToString().Length > 1 && actors[i].ToString().Substring(0, 2) == "*d") { director = true; // Remove director prefix (came from IMDBmovieID actor search) actors[i] = actors[0].ToString().Replace("*d", string.Empty); } else { director = false; } break; } case false: { // from old method (just comparing name with dbmoviedetail director name) if (actors[i].ToString().Contains(_movieDetails.Director)) { director = true; } else { director = false; } break; } } string actor = (string)actors[i]; string role = string.Empty; if (byImdbId == false) { int pos = actor.IndexOf(" as "); if (pos >= 0) { role = actor.Substring(pos + 4); actor = actor.Substring(0, pos); } } actor = actor.Trim(); string line1 = GUILocalizeStrings.Get(986) + " " + (i + 1) + "/" + actors.Count; string line2 = actor; string line3 = string.Empty; OnProgress(line1, line2, line3, percent); _imdb.FindActor(actor); IMDBActor imdbActor = new IMDBActor(); if (_imdb.Count > 0) { int index = FuzzyMatch(actor); if (index == -1) { index = 0; } //Log.Info("Getting actor:{0}", _imdb[index].Title); _imdb.GetActorDetails(_imdb[index], director, out imdbActor); //Log.Info("Adding actor:{0}({1}),{2}", imdbActor.Name, actor, percent); int actorId = VideoDatabase.AddActor(imdbActor.Name); if (actorId > 0) { line1 = GUILocalizeStrings.Get(986) + " " + (i + 1) + "/" + actors.Count; line2 = imdbActor.Name; line3 = string.Empty; OnProgress(line1, line2, line3, -1); VideoDatabase.SetActorInfo(actorId, imdbActor); VideoDatabase.AddActorToMovie(_movieDetails.ID, actorId); if (imdbActor.ThumbnailUrl != string.Empty) { string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieActors, imdbActor.Name); string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieActors, imdbActor.Name); Util.Utils.FileDelete(largeCoverArt); Util.Utils.FileDelete(coverArt); line1 = GUILocalizeStrings.Get(986) + " " + (i + 1) + "/" + actors.Count; line2 = GUILocalizeStrings.Get(1009); OnProgress(line1, line2, line3, percent); DownloadCoverArt(Thumbs.MovieActors, imdbActor.ThumbnailUrl, imdbActor.Name); } } } else { line1 = GUILocalizeStrings.Get(986) + " " + (i + 1) + "/" + actors.Count; line2 = actor; line3 = string.Empty; OnProgress(line1, line2, line3, -1); int actorId = VideoDatabase.AddActor(actor); imdbActor.Name = actor; IMDBActor.IMDBActorMovie imdbActorMovie = new IMDBActor.IMDBActorMovie(); imdbActorMovie.MovieTitle = _movieDetails.Title; imdbActorMovie.Year = _movieDetails.Year; imdbActorMovie.Role = role; imdbActor.Add(imdbActorMovie); VideoDatabase.SetActorInfo(actorId, imdbActor); VideoDatabase.AddActorToMovie(_movieDetails.ID, actorId); } percent += 100 / actors.Count; } } }