Пример #1
0
    public void ImportNfo(string nfoFile, bool skipExisting, bool refreshdbOnly)
    {
      IMDBMovie movie = new IMDBMovie();
      bool isMovieFolder = Util.Utils.IsFolderDedicatedMovieFolder(Path.GetFullPath(nfoFile));
      bool useInternalNfoScraper = false;
      
      using (Profile.Settings xmlreader = new Profile.MPSettings())
      {
        // Use only nfo scrapper
        useInternalNfoScraper = xmlreader.GetValueAsBool("moviedatabase", "useonlynfoscraper", false);
      }

      try
      {
        XmlDocument doc = new XmlDocument();
        doc.Load(nfoFile);
        Log.Debug("Importing nfo file:{0}", nfoFile);

        if (doc.DocumentElement != null)
        {
          int id = -1;

          XmlNodeList movieList = doc.DocumentElement.SelectNodes("/movie");
          
          if (movieList == null)
          {
            Log.Debug("Movie tag for nfo file:{0} not exist. Nfo skipped.", nfoFile);
            return;
          }

          foreach (XmlNode nodeMovie in movieList)
          {
            string genre = string.Empty;
            string cast = string.Empty;
            string path = string.Empty;
            string nfofileName = string.Empty;
            
            #region nodes

            XmlNode nodeTitle = nodeMovie.SelectSingleNode("title");
            XmlNode nodeSortTitle = nodeMovie.SelectSingleNode("sorttitle");
            XmlNode nodeRating = nodeMovie.SelectSingleNode("rating");
            XmlNode nodeYear = nodeMovie.SelectSingleNode("year");
            XmlNode nodeDuration = nodeMovie.SelectSingleNode("runtime");
            XmlNode nodePlotShort = nodeMovie.SelectSingleNode("outline");
            XmlNode nodePlot = nodeMovie.SelectSingleNode("plot");
            XmlNode nodeTagline = nodeMovie.SelectSingleNode("tagline");
            XmlNode nodeDirector = nodeMovie.SelectSingleNode("director");
            XmlNode nodeDirectorImdb = nodeMovie.SelectSingleNode("directorimdb");
            XmlNode nodeImdbNumber = nodeMovie.SelectSingleNode("imdb");
            XmlNode nodeIdImdbNumber = nodeMovie.SelectSingleNode("id");
            XmlNode nodeMpaa = nodeMovie.SelectSingleNode("mpaa");
            XmlNode nodeTop250 = nodeMovie.SelectSingleNode("top250");
            XmlNode nodeVotes = nodeMovie.SelectSingleNode("votes");
            XmlNode nodeStudio = nodeMovie.SelectSingleNode("studio");
            XmlNode nodePlayCount = nodeMovie.SelectSingleNode("playcount");
            XmlNode nodeWatched = nodeMovie.SelectSingleNode("watched");
            XmlNode nodeFanart = nodeMovie.SelectSingleNode("fanart");
            XmlNode nodePoster = nodeMovie.SelectSingleNode("thumb");
            XmlNode nodeLanguage = nodeMovie.SelectSingleNode("language");
            XmlNode nodeCountry = nodeMovie.SelectSingleNode("country");
            XmlNode nodeReview = nodeMovie.SelectSingleNode("review");
            XmlNode nodeCredits = nodeMovie.SelectSingleNode("credits");
            
            #endregion

            #region Moviefiles

            // Get path from *.nfo file)
            Util.Utils.Split(nfoFile, out path, out nfofileName);
            // Movie filename to search from gathered files from nfo path
            nfofileName = Util.Utils.GetFilename(nfofileName, true);
            // Get all video files from nfo path
            ArrayList files = new ArrayList();
            GetVideoFiles(path, ref files);
            bool isDvdBdFolder = false;

            foreach (String file in files)
            {
              //Log.Debug("Import nfo-processing video file:{0} (Total files: {1})", file, files.Count);
              string logFilename = Path.GetFileName(file);

              if ((file.ToUpperInvariant().Contains("VIDEO_TS.IFO") ||
                  file.ToUpperInvariant().Contains("INDEX.BDMV")) && files.Count == 1)
              {
                var pattern = Util.Utils.StackExpression();
                int stackSequence = -1; // seq 0 = [x-y], seq 1 = CD1, Part1....
                int digit = 0;

                for (int i = 0; i < pattern.Length; i++)
                {
                  if (pattern[i].IsMatch(file))
                  {
                    digit = Convert.ToInt16(pattern[i].Match(file).Groups["digit"].Value);
                    stackSequence = i;
                    break;
                  }
                }
                if (digit > 1)
                {
                  Log.Debug("Import nfo-file: {0} is stack part.", file);
                  string filename;
                  string tmpPath = string.Empty;
                  DatabaseUtility.Split(file, out path, out filename);

                  try
                  {
                    if (stackSequence == 0)
                    {
                      string strReplace = "[" + digit;
                      int stackIndex = path.LastIndexOf(strReplace);
                      tmpPath = path.Remove(stackIndex, 2);
                      tmpPath = tmpPath.Insert(stackIndex, "[1");
                    }
                    else
                    {
                      int stackIndex = path.LastIndexOf(digit.ToString());
                      tmpPath = path.Remove(stackIndex, 1);
                      tmpPath = tmpPath.Insert(stackIndex, "1");
                    }

                    int movieId = VideoDatabase.GetMovieId(tmpPath + filename);
                    int pathId = VideoDatabase.AddPath(path);
                    Log.Debug("Import nfo-Adding file: {0}", logFilename);
                    VideoDatabase.AddFile(movieId, pathId, filename);
                    return;
                  }
                  catch(Exception ex)
                  {
                    Log.Error("Import nfo error-stack check for path {0} Error: {1}", path, ex.Message);
                    return;
                  }
                }

                id = VideoDatabase.AddMovie(file, true);
                movie.ID = id;
                isDvdBdFolder = true;
              }
              else
              {
                string tmpFile = string.Empty;
                string tmpPath = string.Empty;
                
                // Read filename
                Util.Utils.Split(file, out tmpPath, out tmpFile);
                // Remove extension
                tmpFile = Util.Utils.GetFilename(tmpFile, true);
                // Remove stack endings (CD1...)
                Util.Utils.RemoveStackEndings(ref tmpFile);
                Util.Utils.RemoveStackEndings(ref nfofileName);
                
                // Check and add to vdb and get movieId
                if (tmpFile.Equals(nfofileName, StringComparison.InvariantCultureIgnoreCase))
                {
                  Log.Debug("Import nfo-Adding file: {0}", logFilename);
                  id = VideoDatabase.AddMovie(file, true);
                  movie.ID = id;
                }
                else if (isMovieFolder && tmpPath.Length > 0) // Every movie in it's own folder, compare by folder name
                {
                  try
                  {
                    tmpPath = tmpPath.Substring(tmpPath.LastIndexOf(@"\") + 1).Trim();

                    if (tmpPath.Equals(nfofileName, StringComparison.InvariantCultureIgnoreCase) || nfofileName.ToLowerInvariant() == "movie")
                    {
                      Log.Debug("Import nfo-Adding file: {0}", logFilename);
                      id = VideoDatabase.AddMovie(file, true);
                      movie.ID = id;
                    }
                    else
                    {
                      Log.Debug("Import nfo-Skipping file:{0}", logFilename);
                    }
                  }
                  catch (Exception ex)
                  {
                    Log.Error("Import nfo-Error comparing path name. File:{0} Err.:{1}", file, ex.Message);
                  }
                }
                else
                {
                  Log.Debug("Import nfo-Skipping file: {0}", logFilename);
                }
              }
            }

            #endregion

            #region Check for existing movie or refresh database only
            
            GetMovieInfoById(id, ref movie);

            if (skipExisting && !movie.IsEmpty || refreshdbOnly && movie.IsEmpty || id < 1)
            {
              Log.Debug("Import nfo-Skipping import for movieId = {0}).", id);
              return;
            }

            movie = new IMDBMovie();
            movie.ID = id;

            #endregion

            #region Genre

            XmlNodeList genres = nodeMovie.SelectNodes("genre");
            
            foreach (XmlNode nodeGenre in genres)
            {
              if (nodeGenre.InnerText != null)
              {
                if (genre.Length > 0)
                {
                  genre += " / ";
                }
                genre += nodeGenre.InnerText;
              }
            }

            if (string.IsNullOrEmpty(genre))
            {
              genres = nodeMovie.SelectNodes("genres/genre");

              foreach (XmlNode nodeGenre in genres)
              {
                if (nodeGenre.InnerText != null)
                {
                  if (genre.Length > 0)
                  {
                    genre += " / ";
                  }
                  genre += nodeGenre.InnerText;
                }
              }
            }

            movie.Genre = genre;
            
            #endregion

            #region Credits (Writers)

            // Writers
            if (nodeCredits != null)
            {
              movie.WritingCredits = nodeCredits.InnerText;
            }
            #endregion

            #region DateAdded

            movie.DateAdded = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            
            #endregion

            #region Title

            // Title
            if (nodeTitle != null)
            {
              movie.Title = nodeTitle.InnerText;
            }

            #endregion

            #region Sort Title

            // SortTitle
            if (nodeSortTitle != null)
            {
              if (!string.IsNullOrEmpty(nodeTitle.InnerText))
              {
                movie.SortTitle = nodeSortTitle.InnerText;
              }
              else
              {
                movie.SortTitle = movie.Title;
              }
            }

            #endregion

            #region Language

            // Title
            if (nodeLanguage != null)
            {
              movie.Language = nodeLanguage.InnerText;
            }

            #endregion

            #region Country

            // Title
            if (nodeCountry != null)
            {
              movie.Country = nodeCountry.InnerText;
            }

            #endregion

            #region IMDB number

            // IMDB number
            if (nodeImdbNumber != null)
            {
              if (CheckMovieImdbId(nodeImdbNumber.InnerText))
              {
                movie.IMDBNumber = nodeImdbNumber.InnerText;
              }
            }

            if (string.IsNullOrEmpty(movie.IMDBNumber) && nodeIdImdbNumber != null)
            {
              if (CheckMovieImdbId(nodeIdImdbNumber.InnerText))
              {
                movie.IMDBNumber = nodeIdImdbNumber.InnerText;
              }
            }

            #endregion

            #region CD/DVD labels

            // CD label
            movie.CDLabel = string.Empty;

            // DVD label
            movie.DVDLabel = string.Empty;

            #endregion

            #region Director

            // Director
            string dirImdb = string.Empty;
            if (nodeDirectorImdb != null)
            {
              dirImdb = nodeDirectorImdb.InnerText;
              
              if (!CheckActorImdbId(dirImdb))
              {
                dirImdb = string.Empty;
              }
            }
            if (nodeDirector != null)
            {
              movie.Director = nodeDirector.InnerText;
              movie.DirectorID = VideoDatabase.AddActor(dirImdb, movie.Director);
            }
            #endregion

            #region Studio

            // Studio
            if (nodeStudio != null)
            {
              movie.Studios = nodeStudio.InnerText;
            }

            #endregion

            #region MPAA

            // MPAA
            if (nodeMpaa != null)
            {
              movie.MPARating = nodeMpaa.InnerText;
            }
            else
            {
              movie.MPARating = "NR";
            }
            
            #endregion
            
            #region Plot/Short plot

            // Plot
            if (nodePlot != null)
            {
              movie.Plot = nodePlot.InnerText;
            }
            else
            {
              movie.Plot = string.Empty;
            }
            // Short plot
            if (nodePlotShort != null)
            {
              movie.PlotOutline = nodePlotShort.InnerText;
            }
            else
            {
              movie.PlotOutline = string.Empty;
            }

            #endregion

            #region Review

            // Title
            if (nodeReview != null)
            {
              movie.UserReview = nodeReview.InnerText;
            }

            #endregion

            #region Rating (n.n/10)

            // Rating
            if (nodeRating != null)
            {
              double rating = 0;
              if (Double.TryParse(nodeRating.InnerText.Replace(".", ","), out rating))
              {
                movie.Rating = (float) rating;
                
                if (movie.Rating > 10.0f)
                {
                  movie.Rating /= 10.0f;
                }
              }
            }

            #endregion

            #region Duration

            // Duration
            if (nodeDuration != null)
            {
              int runtime = 0;
              if (Int32.TryParse(nodeDuration.InnerText, out runtime))
              {
                movie.RunTime = runtime;
              }
              else
              {
                string regex = "(?<h>[0-9]*)h.(?<m>[0-9]*)";
                MatchCollection mc = Regex.Matches(nodeDuration.InnerText, regex, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (mc.Count > 0)
                {
                  foreach (Match m in mc)
                  {
                    int hours = 0;
                    Int32.TryParse(m.Groups["h"].Value, out hours);
                    int minutes = 0;
                    Int32.TryParse(m.Groups["m"].Value, out minutes);
                    hours = hours*60;
                    minutes = hours + minutes;
                    movie.RunTime = minutes;
                  }
                }
                else
                {
                  regex = @"\d*\s*min.";
                  if (Regex.Match(nodeDuration.InnerText, regex, RegexOptions.IgnoreCase).Success)
                  {
                    regex = @"\d*";
                    int minutes = 0;
                    Int32.TryParse(Regex.Match(nodeDuration.InnerText, regex).Value, out minutes);
                    movie.RunTime = minutes;
                  }
                }
              }
            }
            else
            {
              movie.RunTime = 0;
            }

            #endregion
            
            #region Tagline

            // Tagline
            if (nodeTagline != null)
            {
              movie.TagLine = nodeTagline.InnerText;
            }

            #endregion

            #region TOP250

            // Top250
            if (nodeTop250 != null)
            {
              int top250 = 0;
              Int32.TryParse(nodeTop250.InnerText, out top250);
              movie.Top250 = top250;
            }
            else
            {
              movie.Top250 = 0;
            }


            #endregion

            #region votes

            // Votes
            if (nodeVotes != null)
            {
              movie.Votes = nodeVotes.InnerText;
            }

            #endregion

            #region Watched/watched count

            // Watched
            int percent = 0;
            int watchedCount = 0;
            GetMovieWatchedStatus(movie.ID, out percent, out watchedCount);

            if (watchedCount < 1)
            {
              if (nodeWatched != null)
              {
                if (nodeWatched.InnerText.ToLowerInvariant() == "true" || nodeWatched.InnerText == "1")
                {
                  movie.Watched = 1;
                  VideoDatabase.SetMovieWatchedStatus(movie.ID, true, 100);
                }
                else
                {
                  movie.Watched = 0;
                  VideoDatabase.SetMovieWatchedStatus(movie.ID, false, 0);
                }
              }
              // Watched count
              if (nodePlayCount != null)
              {
                watchedCount = 0;
                Int32.TryParse(nodePlayCount.InnerText, out watchedCount);
                SetMovieWatchedCount(movie.ID, watchedCount);
                
                if (watchedCount > 0 && movie.Watched == 0)
                {
                  movie.Watched = 1;
                  VideoDatabase.SetMovieWatchedStatus(movie.ID, true, 100);
                }
                else if (watchedCount == 0 && movie.Watched > 0)
                {
                  SetMovieWatchedCount(movie.ID, 1);
                }
              }
            }
            else
            {
              movie.Watched = 1;
            }

            #endregion

            #region Year

            // Year
            if (nodeYear != null)
            {
              int year = 0;
              Int32.TryParse(nodeYear.InnerText, out year);
              movie.Year = year;
            }

            #endregion

            #region poster

            // Poster
            string thumbJpgFile = string.Empty;
            string thumbTbnFile = string.Empty;
            string thumbFolderJpgFile = string.Empty;
            string thumbFolderTbnFile = string.Empty;
            string titleExt = movie.Title + "{" + id + "}";
            string jpgExt = @".jpg";
            string tbnExt = @".tbn";
            string folderJpg = @"\folder.jpg";
            string folderTbn = @"\folder.tbn";

            if (isDvdBdFolder)
            {
              thumbJpgFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + jpgExt;
              thumbTbnFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + tbnExt;
              thumbFolderJpgFile = path + @"\" + folderJpg;
              thumbFolderTbnFile = path + @"\" + folderTbn;
            }
            else
            {
              thumbJpgFile = path + @"\" + nfofileName + jpgExt;
              thumbTbnFile = path + @"\" + nfofileName + tbnExt;

              if (isMovieFolder)
              {
                thumbFolderJpgFile = path + @"\" + folderJpg;
                thumbFolderTbnFile = path + @"\" + folderTbn;
              }
            }

            if (nodePoster != null)
            {
              // Local source cover
              if (File.Exists(thumbJpgFile))
              {
                CreateCovers(titleExt, thumbJpgFile, movie);
              }
              else if (File.Exists(thumbTbnFile))
              {
                CreateCovers(titleExt, thumbTbnFile, movie);
              }
              else if (!string.IsNullOrEmpty(thumbFolderJpgFile) && File.Exists(thumbFolderJpgFile))
              {
                CreateCovers(titleExt, thumbFolderJpgFile, movie);
              }
              else if (!string.IsNullOrEmpty(thumbFolderTbnFile) && File.Exists(thumbFolderTbnFile))
              {
                CreateCovers(titleExt, thumbFolderTbnFile, movie);
              }
              else if (!nodePoster.InnerText.StartsWith("http:") && File.Exists(nodePoster.InnerText))
              {
                CreateCovers(titleExt, nodePoster.InnerText, movie);
              }
              else if (!nodePoster.InnerText.StartsWith("http:") && File.Exists(path + @"\" + nodePoster.InnerText))
              {
                CreateCovers(titleExt, path + @"\" + nodePoster.InnerText, movie);
              }
              // web source cover
              else if (nodePoster.InnerText.StartsWith("http:"))
              {
                try
                {
                  string imageUrl = nodePoster.InnerText;
                  if (imageUrl.Length > 0)
                  {
                    string largeCoverArtImage = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                    string coverArtImage = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);
                    if (!File.Exists(coverArtImage))
                    {
                      string imageExtension = Path.GetExtension(imageUrl);
                      if (imageExtension == string.Empty)
                      {
                        imageExtension = jpgExt;
                      }
                      string temporaryFilename = "MPTempImage";
                      temporaryFilename += imageExtension;
                      temporaryFilename = Path.Combine(Path.GetTempPath(), temporaryFilename);
                      Util.Utils.FileDelete(temporaryFilename);
                      Util.Utils.DownLoadAndOverwriteCachedImage(imageUrl, temporaryFilename);
                        
                      if (File.Exists(temporaryFilename))
                      {
                        if (Util.Picture.CreateThumbnail(temporaryFilename, largeCoverArtImage, (int)Thumbs.ThumbLargeResolution,
                                                          (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                        {
                          Util.Picture.CreateThumbnail(temporaryFilename, coverArtImage, (int)Thumbs.ThumbResolution,
                                                        (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                        }
                      }

                      Util.Utils.FileDelete(temporaryFilename);
                    }
                  }
                }
                catch (Exception ex)
                {
                  Log.Error("Import nfo - Poster node: {0}", ex.Message);
                }
                movie.ThumbURL = nodePoster.InnerText;
              }
              // MP scrapers cover
              else
              {
                if (movie.ThumbURL == string.Empty && !useInternalNfoScraper)
                {
                  // IMPAwards
                  IMPAwardsSearch impSearch = new IMPAwardsSearch();
                  impSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                  if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = impSearch[0];
                  }

                  // If no IMPAwards lets try TMDB 
                  TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();

                  if (impSearch.Count == 0)
                  {
                    tmdbSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                    if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
                    {
                      movie.ThumbURL = tmdbSearch[0];
                    }
                  }
                  // All fail, last try IMDB
                  if (impSearch.Count == 0 && tmdbSearch.Count == 0)
                  {
                    IMDBSearch imdbSearch = new IMDBSearch();
                    imdbSearch.SearchCovers(movie.IMDBNumber, true);

                    if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
                    {
                      movie.ThumbURL = imdbSearch[0];
                    }
                  }
                }

                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (movie.ID >= 0)
                {
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    Util.Utils.FileDelete(largeCoverArt);
                    Util.Utils.FileDelete(coverArt);
                  }
                  
                  // Save cover thumbs
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    IMDBFetcher.DownloadCoverArt(Thumbs.MovieTitle, movie.ThumbURL, titleExt);
                  }
                }
              }
            }
            else // Node thumb not exist
            {
              if (File.Exists(thumbJpgFile))
              {
                CreateCovers(titleExt, thumbJpgFile, movie);
              }
              else if (File.Exists(thumbTbnFile))
              {
                CreateCovers(titleExt, thumbTbnFile, movie);
              }
              else if (!string.IsNullOrEmpty(thumbFolderJpgFile) && File.Exists(thumbFolderJpgFile))
              {
                CreateCovers(titleExt, thumbFolderJpgFile, movie);
              }
              else if (!string.IsNullOrEmpty(thumbFolderTbnFile) && File.Exists(thumbFolderTbnFile))
              {
                CreateCovers(titleExt, thumbFolderTbnFile, movie);
              }
              else if (movie.ThumbURL == string.Empty && !useInternalNfoScraper)
              {
                // IMPAwards
                IMPAwardsSearch impSearch = new IMPAwardsSearch();
                impSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
                {
                  movie.ThumbURL = impSearch[0];
                }

                // If no IMPAwards lets try TMDB 
                TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();

                if (impSearch.Count == 0)
                {
                  tmdbSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                  if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = tmdbSearch[0];
                  }
                }
                // All fail, last try IMDB
                if (impSearch.Count == 0 && tmdbSearch.Count == 0)
                {
                  IMDBSearch imdbSearch = new IMDBSearch();
                  imdbSearch.SearchCovers(movie.IMDBNumber, true);

                  if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = imdbSearch[0];
                  }
                }
                
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (movie.ID >= 0)
                {
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    Util.Utils.FileDelete(largeCoverArt);
                    Util.Utils.FileDelete(coverArt);
                  }

                  // Save cover thumbs
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    IMDBFetcher.DownloadCoverArt(Thumbs.MovieTitle, movie.ThumbURL, titleExt);
                  }
                }
              }
            }

            #endregion

            #region Fanart

            // Fanart
            XmlNodeList fanartNodeList = nodeMovie.SelectNodes("fanart/thumb");

            int faIndex = 0;
            bool faFound = false;
            string faFile = string.Empty;
            FanArt fa = new FanArt();

            foreach (XmlNode fanartNode in fanartNodeList)
            {
              if (fanartNode != null)
              {
                faFile = path + @"\" + fanartNode.InnerText;
                
                if (File.Exists(faFile))
                {
                  fa.GetLocalFanart(id, "file://" + faFile, faIndex);
                  movie.FanartURL = faFile;
                  faFound = true;
                }
              }
              faIndex ++;

              if (faIndex == 5)
              {
                break;
              }
            }

            if (!faFound)
            {
              List<string> localFanart = new List<string>(); 
              faIndex = 0;
              faFile = path + @"\" + nfofileName + "-fanart.jpg";
              localFanart.Add(faFile);
              faFile = path + @"\" + nfofileName + "-backdrop.jpg";
              localFanart.Add(faFile);
              faFile= path + @"\" + "backdrop.jpg";
              localFanart.Add(faFile);
              faFile = path + @"\" + "fanart.jpg";
              localFanart.Add(faFile);

              foreach (string fanart in localFanart)
              {
                if (File.Exists(fanart))
                {
                  fa.GetLocalFanart(id, "file://" + fanart, faIndex);
                  movie.FanartURL = fanart;
                  faFound = true;
                  break;
                }
              }
              
              if (!faFound && !useInternalNfoScraper)
              {
                fa.GetTmdbFanartByApi(movie.ID, movie.IMDBNumber, string.Empty, false, 1, string.Empty);
              }
            }

            #endregion

            #region Cast

            // Cast parse
            XmlNodeList actorsList = nodeMovie.SelectNodes("actor");
            
            foreach (XmlNode nodeActor in actorsList)
            {
              string name = string.Empty;
              string role = string.Empty;
              string actorImdbId = string.Empty;
              string line = string.Empty;
              XmlNode nodeActorName = nodeActor.SelectSingleNode("name");
              XmlNode nodeActorRole = nodeActor.SelectSingleNode("role");
              XmlNode nodeActorImdbId = nodeActor.SelectSingleNode("imdb");

              XmlNode nodeActorBirthDate = nodeActor.SelectSingleNode("birthdate");
              XmlNode nodeActorBirthPlace = nodeActor.SelectSingleNode("birthplace");
              XmlNode nodeActorDeathDate = nodeActor.SelectSingleNode("deathdate");
              XmlNode nodeActorDeathPlace = nodeActor.SelectSingleNode("deathplace");
              XmlNode nodeActorMiniBio = nodeActor.SelectSingleNode("minibiography");
              XmlNode nodeActorBiography= nodeActor.SelectSingleNode("biography");
              XmlNode nodeActorThumbnail = nodeActor.SelectSingleNode("thumb");

              if (nodeActorName != null && nodeActorName.InnerText != null)
              {
                name = nodeActorName.InnerText;
              }
              if (nodeActorRole != null && nodeActorRole.InnerText != null)
              {
                role = nodeActorRole.InnerText;
              }
              if (nodeActorImdbId != null)
              {
                if (CheckActorImdbId(nodeActorImdbId.InnerText))
                {
                  actorImdbId = nodeActorImdbId.InnerText;
                }
              }
              if (!string.IsNullOrEmpty(name))
              {
                if (!string.IsNullOrEmpty(role))
                {
                  line = String.Format("{0} as {1}\n", name, role);
                }
                else
                {
                  line = String.Format("{0}\n", name);
                }
                cast += line;

                int actId = VideoDatabase.AddActor(actorImdbId, name);
                
                VideoDatabase.AddActorToMovie(id, actId, role);

                if (CheckActorImdbId(actorImdbId))
                {
                  IMDBActor info = new IMDBActor();
                  info.IMDBActorID = actorImdbId;
                  
                  if (nodeActorBirthDate != null)
                  {
                    info.DateOfBirth = nodeActorBirthDate.InnerText;
                  }
                  if (nodeActorBirthPlace != null)
                  {
                    info.PlaceOfBirth = nodeActorBirthPlace.InnerText;
                  }
                  if (nodeActorDeathDate != null)
                  {
                    info.DateOfDeath = nodeActorDeathDate.InnerText;
                  }
                  if (nodeActorDeathPlace != null)
                  {
                    info.PlaceOfDeath = nodeActorDeathPlace.InnerText;
                  }
                  if (nodeActorMiniBio != null)
                  {
                    info.MiniBiography = nodeActorMiniBio.InnerText;
                  }
                  if (nodeActorBiography != null)
                  {
                    info.Biography = nodeActorBiography.InnerText;
                  }
                  
                  if (info.DateOfBirth != string.Empty || 
                      info.PlaceOfBirth != string.Empty||
                      info.DateOfDeath != string.Empty ||
                      info.PlaceOfBirth != string.Empty ||
                      info.MiniBiography != string.Empty ||
                      info.Biography != string.Empty)
                  {
                    SetActorInfo(actId, info);
                  }
                }
              }
            }
            // Cast
            movie.Cast = cast;

            #endregion

            #region UserGroups

            XmlNodeList userGroups = nodeMovie.SelectNodes("set");
            
            foreach (XmlNode nodeUserGroup in userGroups)
            {
              string strUserGroup = string.Empty;
              
              if (nodeUserGroup != null && nodeUserGroup.InnerText != null)
              {
                strUserGroup = nodeUserGroup.InnerText;

                if (!string.IsNullOrEmpty(strUserGroup))
                {
                  int iUserGroup = AddUserGroup(strUserGroup);
                  AddUserGroupToMovie(movie.ID, iUserGroup);
                }
              }
            }

            #endregion

            VideoDatabase.SetMovieInfoById(id, ref movie, true);
          }
        }
      }
      catch (Exception ex)
      {
        Log.Error("videodatabase exception error importing nfo file {0}:{1} ", nfoFile, ex.Message);
      }
    }
    public void ImportNfo(string nfoFile)
    {
      IMDBMovie movie = new IMDBMovie();
      try
      {
        XmlDocument doc = new XmlDocument();
        doc.Load(nfoFile);
        
        if (doc.DocumentElement != null)
        {
          int id = 0;

          XmlNodeList movieList = doc.DocumentElement.SelectNodes("/movie");
          
          if (movieList == null)
          {
            return;
          }

          foreach (XmlNode nodeMovie in movieList)
          {
            string genre = string.Empty;
            string cast = string.Empty;
            string path = string.Empty;
            string fileName = string.Empty;
            
            #region nodes

            XmlNode nodeTitle = nodeMovie.SelectSingleNode("title");
            XmlNode nodeRating = nodeMovie.SelectSingleNode("rating");
            XmlNode nodeYear = nodeMovie.SelectSingleNode("year");
            XmlNode nodeDuration = nodeMovie.SelectSingleNode("runtime");
            XmlNode nodePlotShort = nodeMovie.SelectSingleNode("outline");
            XmlNode nodePlot = nodeMovie.SelectSingleNode("plot");
            XmlNode nodeTagline = nodeMovie.SelectSingleNode("tagline");
            XmlNode nodeDirector = nodeMovie.SelectSingleNode("director");
            XmlNode nodeDirectorImdb = nodeMovie.SelectSingleNode("directorimdb");
            XmlNode nodeImdbNumber = nodeMovie.SelectSingleNode("imdb");
            XmlNode nodeMpaa = nodeMovie.SelectSingleNode("mpaa");
            XmlNode nodeTop250 = nodeMovie.SelectSingleNode("top250");
            XmlNode nodeVotes = nodeMovie.SelectSingleNode("votes");
            XmlNode nodeStudio = nodeMovie.SelectSingleNode("studio");
            XmlNode nodePlayCount = nodeMovie.SelectSingleNode("playcount");
            XmlNode nodeWatched = nodeMovie.SelectSingleNode("watched");
            XmlNode nodeFanart = nodeMovie.SelectSingleNode("fanart");
            XmlNode nodePoster = nodeMovie.SelectSingleNode("thumb");
            XmlNode nodeLanguage = nodeMovie.SelectSingleNode("language");
            XmlNode nodeCountry = nodeMovie.SelectSingleNode("country");
            XmlNode nodeReview = nodeMovie.SelectSingleNode("review");
            XmlNode nodeCredits = nodeMovie.SelectSingleNode("credits");
            
            
            #endregion

            #region Genre

            XmlNodeList genres = nodeMovie.SelectNodes("genres/genre");
            
            foreach (XmlNode nodeGenre in genres)
            {
              if (nodeGenre.InnerText != null)
              {
                if (genre.Length > 0)
                {
                  genre += " / ";
                }
                genre += nodeGenre.InnerText;
              }
            }

            if (string.IsNullOrEmpty(genre))
            {
              XmlNode nodeGenre = nodeMovie.SelectSingleNode("genre");
              
              if (nodeGenre != null)
              {
                genre = nodeGenre.InnerText;
              }
            }

            // Genre
            movie.Genre = genre;
            
            #endregion

            #region Credits (Writers)

            // Writers
            if (nodeCredits != null)
            {
              movie.WritingCredits = nodeCredits.InnerText;
            }
            #endregion

            #region Moviefiles
            
            // Get path from *.nfo file)
            Util.Utils.Split(nfoFile, out path, out fileName);
            // Movie filename to search from gathered files from nfo path
            fileName = Util.Utils.GetFilename(fileName, true);
            // Get all video files from nfo path
            ArrayList files = new ArrayList();
            GetVideoFiles(path, ref files);
            bool isDvdBdFolder = false;

            foreach (String file in files)
            {
              if ((file.ToUpperInvariant().Contains("VIDEO_TS.IFO") ||
                  file.ToUpperInvariant().Contains("INDEX.BDMV")) && files.Count == 1)
              {
                id = VideoDatabase.AddMovie(file, true);
                movie.ID = id;
                isDvdBdFolder = true;
              }
              else
              {
                string tmpFile = string.Empty;
                string tmpPath = string.Empty;
                // Read filename
                Util.Utils.Split(file, out tmpPath, out tmpFile);
                // Remove extension
                tmpFile = Util.Utils.GetFilename(tmpFile, true);
                // Remove stack endings (CD1...)
                Util.Utils.RemoveStackEndings(ref tmpFile);
                // Check and add to vdb and get movieId
                if (tmpFile.Equals(fileName, StringComparison.InvariantCultureIgnoreCase))
                {
                  id = VideoDatabase.AddMovie(file, true);
                  movie.ID = id;
                }
              }
            }

            #endregion

            #region DateAdded

            movie.DateAdded = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            
            #endregion

            #region Title

            // Title
            if (nodeTitle != null)
            {
              movie.Title = nodeTitle.InnerText;
            }

            #endregion

            #region Language

            // Title
            if (nodeLanguage != null)
            {
              movie.Language = nodeLanguage.InnerText;
            }

            #endregion

            #region Country

            // Title
            if (nodeCountry != null)
            {
              movie.Country = nodeCountry.InnerText;
            }

            #endregion

            #region IMDB number

            // IMDB number
            if (nodeImdbNumber != null)
            {
              if (CheckMovieImdbId(nodeImdbNumber.InnerText))
              {
                movie.IMDBNumber = nodeImdbNumber.InnerText;
              }
            }

            #endregion

            #region CD/DVD labels

            // CD label
            movie.CDLabel = string.Empty;

            // DVD label
            movie.DVDLabel = string.Empty;

            #endregion

            #region Director

            // Director
            string dirImdb = string.Empty;
            if (nodeDirectorImdb != null)
            {
              dirImdb = nodeDirector.InnerText;
              
              if (!CheckActorImdbId(dirImdb))
              {
                dirImdb = string.Empty;
              }
            }
            if (nodeDirector != null)
            {
              movie.Director = nodeDirector.InnerText;
              movie.DirectorID = VideoDatabase.AddActor(dirImdb, movie.Director);
            }
            #endregion

            #region Studio

            // Studio
            if (nodeStudio != null)
            {
              movie.Studios = nodeStudio.InnerText;
            }

            #endregion

            #region MPAA

            // MPAA
            if (nodeMpaa != null)
            {
              movie.MPARating = nodeMpaa.InnerText;
            }
            else
            {
              movie.MPARating = "NR";
            }
            
            #endregion
            
            #region Plot/Short plot

            // Plot
            if (nodePlot != null)
            {
              movie.Plot = nodePlot.InnerText;
            }
            else
            {
              movie.Plot = string.Empty;
            }
            // Short plot
            if (nodePlotShort != null)
            {
              movie.PlotOutline = nodePlotShort.InnerText;
            }
            else
            {
              movie.PlotOutline = string.Empty;
            }

            #endregion

            #region Review

            // Title
            if (nodeReview != null)
            {
              movie.UserReview = nodeReview.InnerText;
            }

            #endregion

            #region Rating (n.n/10)

            // Rating
            if (nodeRating != null)
            {
              double rating = 0;
              if (Double.TryParse(nodeRating.InnerText.Replace(".", ","), out rating))
              {
                movie.Rating = (float) rating;
                
                if (movie.Rating > 10.0f)
                {
                  movie.Rating /= 10.0f;
                }
              }
            }

            #endregion

            #region Duration

            // Duration
            if (nodeDuration != null)
            {
              int runtime = 0;
              if (Int32.TryParse(nodeDuration.InnerText, out runtime))
              {
                movie.RunTime = runtime;
              }
              else
              {
                string regex = "(?<h>[0-9]*)h.(?<m>[0-9]*)";
                MatchCollection mc = Regex.Matches(nodeDuration.InnerText, regex, RegexOptions.Singleline);
                if (mc.Count > 0)
                {
                  foreach (Match m in mc)
                  {
                    int hours = 0;
                    Int32.TryParse(m.Groups["h"].Value, out hours);
                    int minutes = 0;
                    Int32.TryParse(m.Groups["m"].Value, out minutes);
                    hours = hours*60;
                    minutes = hours + minutes;
                    movie.RunTime = minutes;
                  }
                }
              }
            }
            else
            {
              movie.RunTime = 0;
            }

            #endregion
            
            #region Tagline

            // Tagline
            if (nodeTagline != null)
            {
              movie.TagLine = nodeTagline.InnerText;
            }

            #endregion

            #region TOP250

            // Top250
            if (nodeTop250 != null)
            {
              int top250 = 0;
              Int32.TryParse(nodeTop250.InnerText, out top250);
              movie.Top250 = top250;
            }
            else
            {
              movie.Top250 = 0;
            }


            #endregion

            #region votes

            // Votes
            if (nodeVotes != null)
            {
              movie.Votes = nodeVotes.InnerText;
            }

            #endregion

            #region Watched/watched count

            // Watched
            int percent = 0;
            int watchedCount = 0;
            GetMovieWatchedStatus(movie.ID, out percent, out watchedCount);

            if (watchedCount < 1)
            {
              if (nodeWatched != null)
              {
                if (nodeWatched.InnerText == "true" || nodeWatched.InnerText == "1")
                {
                  movie.Watched = 1;
                  VideoDatabase.SetMovieWatchedStatus(movie.ID, true, 100);
                }
                else
                {
                  movie.Watched = 0;
                  VideoDatabase.SetMovieWatchedStatus(movie.ID, false, 0);
                }
              }
              // Watched count
              if (nodePlayCount != null)
              {
                watchedCount = 0;
                Int32.TryParse(nodePlayCount.InnerText, out watchedCount);
                SetMovieWatchedCount(movie.ID, watchedCount);
              }
            }
            else
            {
              movie.Watched = 1;
            }

            #endregion

            #region Year

            // Year
            if (nodeYear != null)
            {
              int year = 0;
              Int32.TryParse(nodeYear.InnerText, out year);
              movie.Year = year;
            }

            #endregion

            #region poster

            // Poster
            if (nodePoster != null)
            {
              string thumbJpgFile = string.Empty;
              string thumbTbnFile = string.Empty;
              
              if (nodePoster.InnerText == string.Empty)
              {
                if (isDvdBdFolder)
                {
                  thumbJpgFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + ".jpg";
                  thumbTbnFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + ".tbn";
                }
                else
                {
                  thumbJpgFile = path + @"\" + fileName + ".jpg";
                  thumbTbnFile = path + @"\" + fileName + ".tbn";
                }
                
              }
              else
              {
                thumbJpgFile = path + @"\" + nodePoster.InnerText;
                thumbTbnFile = path + @"\" + nodePoster.InnerText;
              }
              
              string titleExt = movie.Title + "{" + id + "}";
              
              if (File.Exists(thumbJpgFile))
              {
                movie.ThumbURL = thumbJpgFile;
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (Util.Picture.CreateThumbnail(thumbJpgFile, largeCoverArt, (int)Thumbs.ThumbLargeResolution,
                                                 (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                {
                  Util.Picture.CreateThumbnail(thumbJpgFile, coverArt, (int)Thumbs.ThumbResolution,
                                                (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                }
              }
              else if (File.Exists(thumbTbnFile))
              {
                movie.ThumbURL = thumbTbnFile;
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);
                
                if (Util.Picture.CreateThumbnail(thumbTbnFile, largeCoverArt, (int)Thumbs.ThumbLargeResolution,
                                                 (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                {
                  Util.Picture.CreateThumbnail(thumbTbnFile, coverArt, (int)Thumbs.ThumbResolution,
                                                (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                }
              }
              else if (nodePoster.InnerText.StartsWith("http:"))
              {
                try
                {
                  string imageUrl = nodePoster.InnerText;
                  if (imageUrl.Length > 0)
                  {
                    string largeCoverArtImage = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                    string coverArtImage = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);
                    if (!File.Exists(coverArtImage))
                    {
                      string imageExtension = Path.GetExtension(imageUrl);
                      if (imageExtension == string.Empty)
                      {
                        imageExtension = ".jpg";
                      }
                      string temporaryFilename = "temp";
                      temporaryFilename += imageExtension;
                      Util.Utils.FileDelete(temporaryFilename);

                      Util.Utils.DownLoadAndCacheImage(imageUrl, temporaryFilename);
                        
                      if (File.Exists(temporaryFilename))
                      {
                        if (Util.Picture.CreateThumbnail(temporaryFilename, largeCoverArtImage, (int)Thumbs.ThumbLargeResolution,
                                                          (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                        {
                          Util.Picture.CreateThumbnail(temporaryFilename, coverArtImage, (int)Thumbs.ThumbResolution,
                                                        (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                        }
                      }

                      Util.Utils.FileDelete(temporaryFilename);
                    }
                  }
                }
                catch (Exception) { }
                movie.ThumbURL = nodePoster.InnerText;
              }
              else
              {
                if (movie.ThumbURL == string.Empty)
                {
                  // IMPAwards
                  IMPAwardsSearch impSearch = new IMPAwardsSearch();
                  impSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                  if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = impSearch[0];
                  }

                  // If no IMPAwards lets try TMDB 
                  TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();

                  if (impSearch.Count == 0)
                  {
                    tmdbSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                    if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
                    {
                      movie.ThumbURL = tmdbSearch[0];
                    }
                  }
                  // All fail, last try IMDB
                  if (impSearch.Count == 0 && tmdbSearch.Count == 0)
                  {
                    IMDBSearch imdbSearch = new IMDBSearch();
                    imdbSearch.SearchCovers(movie.IMDBNumber, true);

                    if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
                    {
                      movie.ThumbURL = imdbSearch[0];
                    }
                  }
                }

                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (movie.ID >= 0)
                {
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    Util.Utils.FileDelete(largeCoverArt);
                    Util.Utils.FileDelete(coverArt);
                  }
                  
                  // Save cover thumbs
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    IMDBFetcher.DownloadCoverArt(Thumbs.MovieTitle, movie.ThumbURL, titleExt);
                  }
                }
              }
            }
            else
            {
              string thumbJpgFile = string.Empty;
              string thumbTbnFile = string.Empty;

              if (isDvdBdFolder)
              {
                thumbJpgFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + ".jpg";
                thumbTbnFile = path + @"\" + Path.GetFileNameWithoutExtension(path) + ".tbn";
              }
              else
              {
                thumbJpgFile = path + @"\" + fileName + ".jpg";
                thumbTbnFile = path + @"\" + fileName + ".tbn";
              }
              
              string titleExt = movie.Title + "{" + id + "}";

              if (File.Exists(thumbJpgFile))
              {
                movie.ThumbURL = thumbJpgFile;
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (Util.Picture.CreateThumbnail(thumbJpgFile, largeCoverArt, (int)Thumbs.ThumbLargeResolution,
                                                 (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                {
                  Util.Picture.CreateThumbnail(thumbJpgFile, coverArt, (int)Thumbs.ThumbResolution,
                                                (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                }
              }
              else if (File.Exists(thumbTbnFile))
              {
                movie.ThumbURL = thumbTbnFile;
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (Util.Picture.CreateThumbnail(thumbTbnFile, largeCoverArt, (int)Thumbs.ThumbLargeResolution,
                                                 (int)Thumbs.ThumbLargeResolution, 0, Thumbs.SpeedThumbsSmall))
                {
                  Util.Picture.CreateThumbnail(thumbTbnFile, coverArt, (int)Thumbs.ThumbResolution,
                                                (int)Thumbs.ThumbResolution, 0, Thumbs.SpeedThumbsLarge);
                }
              }
              else if (movie.ThumbURL == string.Empty)
              {
                // IMPAwards
                IMPAwardsSearch impSearch = new IMPAwardsSearch();
                impSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
                {
                  movie.ThumbURL = impSearch[0];
                }

                // If no IMPAwards lets try TMDB 
                TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();

                if (impSearch.Count == 0)
                {
                  tmdbSearch.SearchCovers(movie.Title, movie.IMDBNumber);

                  if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = tmdbSearch[0];
                  }
                }
                // All fail, last try IMDB
                if (impSearch.Count == 0 && tmdbSearch.Count == 0)
                {
                  IMDBSearch imdbSearch = new IMDBSearch();
                  imdbSearch.SearchCovers(movie.IMDBNumber, true);

                  if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
                  {
                    movie.ThumbURL = imdbSearch[0];
                  }
                }
                
                string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
                string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

                if (movie.ID >= 0)
                {
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    Util.Utils.FileDelete(largeCoverArt);
                    Util.Utils.FileDelete(coverArt);
                  }

                  // Save cover thumbs
                  if (!string.IsNullOrEmpty(movie.ThumbURL))
                  {
                    IMDBFetcher.DownloadCoverArt(Thumbs.MovieTitle, movie.ThumbURL, titleExt);
                  }
                }
              }
            }

            #endregion

            #region Fanart

            // Fanart
            XmlNodeList fanartNodeList = nodeMovie.SelectNodes("fanart/thumb");

            int faIndex = 0;
            bool faFound = false;
            string faFile = string.Empty;
            FanArt fa = new FanArt();

            foreach (XmlNode fanartNode in fanartNodeList)
            {
              if (fanartNode != null)
              {
                faFile = path + @"\" + fanartNode.InnerText;
                
                if (File.Exists(faFile))
                {
                  fa.GetLocalFanart(id, "file://" + faFile, faIndex);
                  movie.FanartURL = faFile;
                  faFound = true;
                }
              }
              faIndex ++;
            }

            if (!faFound)
            {
              faFile = path + @"\" + Path.GetFileNameWithoutExtension(fileName) + "-fanart.jpg";
              
              if (File.Exists(faFile))
              {
                fa.GetLocalFanart(id, "file://" + faFile, faIndex);
                movie.FanartURL = faFile;
              }
              else
              {
                fa.GetTmdbFanartByApi(movie.ID, movie.IMDBNumber, string.Empty, false, 1, string.Empty);
              }
            }

            #endregion

            #region Cast

            // Cast parse
            XmlNodeList actorsList = nodeMovie.SelectNodes("actor");
            foreach (XmlNode nodeActor in actorsList)
            {
              string name = string.Empty;
              string role = string.Empty;
              string actorImdbId = string.Empty;
              string line = string.Empty;
              XmlNode nodeActorName = nodeActor.SelectSingleNode("name");
              XmlNode nodeActorRole = nodeActor.SelectSingleNode("role");
              XmlNode nodeActorImdbId = nodeActor.SelectSingleNode("imdb");

              XmlNode nodeActorBirthDate = nodeActor.SelectSingleNode("birthdate");
              XmlNode nodeActorBirthPlace = nodeActor.SelectSingleNode("birthplace");
              XmlNode nodeActorDeathDate = nodeActor.SelectSingleNode("deathdate");
              XmlNode nodeActorDeathPlace = nodeActor.SelectSingleNode("deathplace");
              XmlNode nodeActorMiniBio = nodeActor.SelectSingleNode("minibiography");
              XmlNode nodeActorBiography= nodeActor.SelectSingleNode("biography");
              XmlNode nodeActorThumbnail = nodeActor.SelectSingleNode("thumb");

              if (nodeActorName != null && nodeActorName.InnerText != null)
              {
                name = nodeActorName.InnerText;
              }
              if (nodeActorRole != null && nodeActorRole.InnerText != null)
              {
                role = nodeActorRole.InnerText;
              }
              if (nodeActorImdbId != null)
              {
                if (CheckActorImdbId(nodeActorImdbId.InnerText))
                {
                  actorImdbId = nodeActorImdbId.InnerText;
                }
              }
              if (!string.IsNullOrEmpty(name))
              {
                if (!string.IsNullOrEmpty(role))
                {
                  line = String.Format("{0} as {1}\n", name, role);
                }
                else
                {
                  line = String.Format("{0}\n", name);
                }
                cast += line;

                int actId = VideoDatabase.AddActor(actorImdbId, name);
                
                VideoDatabase.AddActorToMovie(id, actId, role);

                if (CheckActorImdbId(actorImdbId))
                {
                  IMDBActor info = new IMDBActor();
                  info.IMDBActorID = actorImdbId;
                  
                  if (nodeActorBirthDate != null)
                  {
                    info.DateOfBirth = nodeActorBirthDate.InnerText;
                  }
                  if (nodeActorBirthPlace != null)
                  {
                    info.PlaceOfBirth = nodeActorBirthPlace.InnerText;
                  }
                  if (nodeActorDeathDate != null)
                  {
                    info.DateOfDeath = nodeActorDeathDate.InnerText;
                  }
                  if (nodeActorDeathPlace != null)
                  {
                    info.PlaceOfDeath = nodeActorDeathPlace.InnerText;
                  }
                  if (nodeActorMiniBio != null)
                  {
                    info.MiniBiography = nodeActorMiniBio.InnerText;
                  }
                  if (nodeActorBiography != null)
                  {
                    info.Biography = nodeActorBiography.InnerText;
                  }
                  
                  if (info.DateOfBirth != string.Empty || 
                      info.PlaceOfBirth != string.Empty||
                      info.DateOfDeath != string.Empty ||
                      info.PlaceOfBirth != string.Empty ||
                      info.MiniBiography != string.Empty ||
                      info.Biography != string.Empty)
                  {
                    SetActorInfo(actId, info);
                  }
                }
              }
            }
            // Cast
            movie.Cast = cast;

            #endregion

            VideoDatabase.SetMovieInfoById(id, ref movie, true);
          }
        }
      }
      catch (Exception ex)
      {
        Log.Error("Error importing nfo file {0}:{1} ", nfoFile, ex);
      }
    }
Пример #3
0
    private void FetchDetailsThread()
    {
      try
      {
        _disableCancel = false;
        
        if (_movieDetails == null)
        {
          _movieDetails = new IMDBMovie();
        }
        
        if (_url == null)
        {
          return;
        }
        
        // Progress bar visualization (GUI and Config), not neccessary as we see text but it looks better then text only
        // Action steps in code for which we want to see progress increase
        // Action 0-1 - Movie details fetch (20%)
        // Action 1-2 - IMPAw or TMDB search (40%)
        // Action 2-3 - FanArt download & actors fetch (60%)
        // Action 3-4 - Actor fetch (80%)
        // Action 3-4 - End (100%)
        
        string line1 = GUILocalizeStrings.Get(198);
        OnProgress(line1, _url.Title, string.Empty, 0);
        
        if (_imdb.GetDetails(_url, ref _movieDetails))
        {
          //percent = percent + step; // **Progress bar downloading details end
          OnProgress(line1, _url.Title, string.Empty, 20);
          
          // Get special settings for grabbing
          bool folderTitle = _foldercheck;
          int faCount;
          bool stripPrefix;
          bool useFanArt;
          
          using (Settings xmlreader = new MPSettings())
          {
            // Number of downloaded fanart per movie
            faCount = xmlreader.GetValueAsInt("moviedatabase", "fanartnumber", 1);
            stripPrefix = xmlreader.GetValueAsBool("moviedatabase", "striptitleprefixes", false);
            useFanArt = xmlreader.GetValueAsBool("moviedatabase", "usefanart", false);
          }
          
          if (stripPrefix)
          {
            string tmpTitle = _movieDetails.Title;
            Util.Utils.StripMovieNamePrefix(ref tmpTitle, true);
            _movieDetails.Title = tmpTitle;
          }

          #region Covers

          //
          // Covers - If cover is not empty don't change it, else download new
          //
          // Local cover check (every movie is in it's own folder), lookin' for folder.jpg
          // or look for local cover named as movie file
          string localCover = string.Empty; // local cover named as movie filename
          string movieFile = string.Empty;
          string moviePath = _movieDetails.Path;
          string titleExt = string.Empty;
          string largeCoverArt = string.Empty;
          string coverArt = string.Empty;

          if (_addToDatabase)
          {
            // Find movie file(s)
            ArrayList files = new ArrayList();
            VideoDatabase.GetFilesForMovie(_movieDetails.ID, ref files);

            // Remove stack endings for video file(CD, Part...)
            if (files.Count > 0)
            {
              movieFile = (string) files[0];
              Util.Utils.RemoveStackEndings(ref movieFile);
            }

            localCover = moviePath + @"\" + Util.Utils.GetFilename(movieFile, true) + ".jpg";

            // Every movie in it's own folder?
            if (folderTitle)
            {
              string folderCover = moviePath + @"\folder.jpg";

              if (File.Exists(folderCover))
              {
                _movieDetails.ThumbURL = "file://" + folderCover;
              }
              else if (File.Exists(localCover))
              {
                _movieDetails.ThumbURL = "file://" + localCover;
              }
            }
              // Try local movefilename.jpg
            else if (File.Exists(localCover))
            {
              _movieDetails.ThumbURL = "file://" + localCover;
            }

            // No local or scraper thumb
            if (_movieDetails.ThumbURL == string.Empty)
            {
              // **Progress bar message cover search IMPAw start
              line1 = GUILocalizeStrings.Get(928) + ": IMP Awards";
              OnProgress(line1, _url.Title, string.Empty, 20);

              // Added IMDBNumber parameter for movie cover check
              // This number is checked on HTML cover source page, if it's equal then this is the cover for our movie

              // IMPAwards
              IMPAwardsSearch impSearch = new IMPAwardsSearch();
              impSearch.SearchCovers(_movieDetails.Title, _movieDetails.IMDBNumber);

              if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
              {
                _movieDetails.ThumbURL = impSearch[0];

                // **Progress bar message for IMPAw end
                OnProgress(line1, _url.Title, string.Empty, 40);
              }

              // If no IMPAwards lets try TMDB 
              TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();

              if (impSearch.Count == 0)
              {
                line1 = GUILocalizeStrings.Get(928) + ": TMDB"; // **Progress bar message for TMDB start
                OnProgress(line1, _url.Title, string.Empty, 20);

                tmdbSearch.SearchCovers(_movieDetails.Title, _movieDetails.IMDBNumber);

                if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
                {
                  _movieDetails.ThumbURL = tmdbSearch[0];
                  // **Progress bar message for TMDB end
                  OnProgress(line1, _url.Title, string.Empty, 40);
                }
              }
              // All fail, last try IMDB
              if (impSearch.Count == 0 && tmdbSearch.Count == 0)
              {
                // **Progress bar message for IMDB start
                line1 = GUILocalizeStrings.Get(928) + ": IMDB";
                OnProgress(line1, _url.Title, string.Empty, 20);

                IMDBSearch imdbSearch = new IMDBSearch();
                imdbSearch.SearchCovers(_movieDetails.IMDBNumber, true);

                if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
                {
                  _movieDetails.ThumbURL = imdbSearch[0];
                  // **Progress bar message for IMDB end
                  OnProgress(line1, _url.Title, string.Empty, 40);
                }
              }
            }

            titleExt = _movieDetails.Title + "{" + _movieDetails.ID + "}";
            largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
            coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

            if (_movieDetails.ID >= 0)
            {
              if (!string.IsNullOrEmpty(_movieDetails.ThumbURL))
              {
                Util.Utils.FileDelete(largeCoverArt);
                Util.Utils.FileDelete(coverArt);
                line1 = GUILocalizeStrings.Get(1009);
              }
              OnProgress(line1, _url.Title, string.Empty, 40); // **Too fast so leave percent
            }
          }

          #endregion

          #region Fanart

          // FanArt grab
          if (useFanArt && _addToDatabase)
          {
            // **Progress bar message fanart start
            line1 = GUILocalizeStrings.Get(921) + ": Fanart";
            OnProgress(line1, _url.Title, string.Empty, 40);
            
            string localFanart = string.Empty;
            FanArt fanartSearch = new FanArt();
            
            // Check local fanart (only if every movie is in it's own folder), lookin for fanart.jpg
            // Looking for fanart.jpg or videofilename-fanart.jpg
            if (folderTitle)
            {
              localFanart = moviePath + @"\fanart.jpg";
              
              if (File.Exists(localFanart))
              {
                _movieDetails.FanartURL = "file://" + localFanart;
              }
              else
              {
                localFanart = moviePath + @"\" + Util.Utils.GetFilename(movieFile, true) + @"-fanart.jpg";
                
                if (File.Exists(localFanart))
                {
                  _movieDetails.FanartURL = "file://" + localFanart;
                }
              }
            }
            else
            {
              localFanart = moviePath + @"\" + Util.Utils.GetFilename(movieFile, true) + @"-fanart.jpg";
              
              if (File.Exists(localFanart))
              {
                _movieDetails.FanartURL = "file://" + localFanart;
              }
            }
            
            if (_movieDetails.FanartURL == string.Empty || _movieDetails.FanartURL == Strings.Unknown)
            {
              fanartSearch.GetTmdbFanartByApi
                (_movieDetails.ID, _movieDetails.IMDBNumber, _movieDetails.Title, true, faCount, string.Empty);
              // Set fanart url to db
              _movieDetails.FanartURL = fanartSearch.DefaultFanartUrl;
            }
            else // Local file or user url
            {
              fanartSearch.GetLocalFanart(_movieDetails.ID, _movieDetails.FanartURL, 0);
            }
            
            // **Progress bar message fanart End
            OnProgress(line1, _url.Title, string.Empty, 60);
          }

          #endregion

          #region Actors

          if (VideoDatabase.CheckMovieImdbId(_movieDetails.IMDBNumber) && _addToDatabase)
          {
            line1 = GUILocalizeStrings.Get(344); // **Progress bar actors start sets actual value to 0
            OnProgress(line1, _url.Title, string.Empty, 60);
            FetchActorsInMovie();
          }

          #endregion

          OnDisableCancel(this);

          #region Download & save covers, save movie info

          if (_movieDetails.ID >= 0 && _addToDatabase)
          {
            // **Progress bar downloading cover art, final step
            line1 = GUILocalizeStrings.Get(1009); 
            OnProgress(line1, _url.Title, string.Empty, 80);
            
            // Save cover thumbs
            if (!string.IsNullOrEmpty(_movieDetails.ThumbURL))
            {
              DownloadCoverArt(Thumbs.MovieTitle, _movieDetails.ThumbURL, titleExt);
            }
            
            // Set folder.jpg for ripped DVDs
            try
            {
              string path = _movieDetails.Path;
              string filename = _movieDetails.File;

              if (filename.ToUpper() == "VIDEO_TS.IFO" || filename.ToUpper() == "INDEX.BDMV")
              {
                // Remove \VIDEO_TS from directory structure
                string directoryDVD = path.Substring(0, path.LastIndexOf(@"\"));
                
                if (Directory.Exists(directoryDVD))
                {
                  // Copy large cover file as folder.jpg
                  File.Copy(largeCoverArt, directoryDVD + @"\folder.jpg", true);
                }
              }
            }
            catch (Exception) {}
            
            // Check movie table if there is an entry that new movie is already played as share
            int percentage = 0;
            int timesWatched = 0;

            if (VideoDatabase.GetmovieWatchedStatus(_movieDetails.ID, out percentage, out timesWatched))
            {
              _movieDetails.Watched = 1;
            }

            // Save movie info
            VideoDatabase.SetMovieInfoById(_movieDetails.ID, ref _movieDetails, true);

            // Add groups with rules
            ArrayList groups = new ArrayList();
            VideoDatabase.GetUserGroups(groups);

            foreach (string group in groups)
            {
              string rule = VideoDatabase.GetUserGroupRule(group);

              if (!string.IsNullOrEmpty(rule))
              {
                try
                {
                  ArrayList values = new ArrayList();
                  bool error = false;
                  values = VideoDatabase.ExecuteRuleSql(rule, "movieinfo.idMovie", out error);

                  if (error)
                  {
                    continue;
                  }

                  if (values.Count > 0 && values.Contains(_movieDetails.ID.ToString()))
                  {
                    VideoDatabase.AddUserGroupToMovie(_movieDetails.ID, VideoDatabase.AddUserGroup(group));
                  }
                }
                catch (Exception)
                {
                }
              }
            }
            OnProgress(line1, _url.Title, string.Empty, 100); // **Progress bar end details
          }

          #endregion

        }
        else
        {
          line1 = GUILocalizeStrings.Get(416);
          OnProgress(line1, _url.Title, string.Empty, 100); // **Progress bar end (no details)
          _movieDetails = null;
        }
      }
      catch (ThreadAbortException) {}
      finally
      {
        OnDetailsEnd(this);
        _disableCancel = false;
         _detailsThread = null;
      }
    }
Пример #4
0
    // Changed Cover and fanart grabbing
    private void FetchDetailsThread()
    {
      try
      {
        _disableCancel = false;
        if (_movieDetails == null)
        {
          _movieDetails = new IMDBMovie();
        }
        if (_url == null)
        {
          return;
        }
        // Progress bar visualization (GUI and Config), not neccessary as we see text but it looks better then text only
        // Action steps in code for which we want to see progress increase
        // Action 0-1 - Movie details fetch (25%)
        // Action 1-2 - IMPAw or TMDB search (50%)
        // Action 2-3 - FanArt download (75%)
        // Action 3-4 - End (100%)
        int stepsInCode = 4; // Total actions (no need for more as some of them are too fast to see)
        int step = 100 / stepsInCode; // step value for increment
        int percent = 0; // actual pbar value

        string line1 = GUILocalizeStrings.Get(198);
        OnProgress(line1, _url.Title, string.Empty, percent);
        
        if (_imdb.GetDetails(_url, ref _movieDetails))
        {
          percent = percent + step; // **Progress bar downloading details end
          // Get special settings for grabbing
          Settings xmlreader = new MPSettings();
          // Folder name for title (Change scraped title with folder name)
          bool folderTitle = xmlreader.GetValueAsBool("moviedatabase", "usefolderastitle", false);
          // Number of downloaded fanart per movie
          int faCount = xmlreader.GetValueAsInt("moviedatabase", "fanartnumber", 1);
          // Also add fanart for share view
          bool faShare = xmlreader.GetValueAsBool("moviedatabase", "usefanartshare", true);
          
          OnProgress(line1, _url.Title, string.Empty, percent);
          
          bool stripPrefix = xmlreader.GetValueAsBool("moviedatabase", "striptitleprefixes", false);
          
          if (stripPrefix)
          {
            string tmpTitle = _movieDetails.Title;
            Util.Utils.StripMovieNamePrefix(ref tmpTitle, true);
            _movieDetails.Title = tmpTitle;
          }
          
          //
          // Covers - If cover is not empty don't change it, else download new
          //
          // Local cover check (every movie is in it's own folder), lookin' for folder.jpg
          // or look for local cover named as movie file
          string localCover = string.Empty; // local cover named as movie filename
          string movieFile = string.Empty;
          string moviePath = _movieDetails.Path;
          // Find movie file(s)
          ArrayList files = new ArrayList();
          VideoDatabase.GetFiles(_movieDetails.ID, ref files);
          
          // Remove stack endings for video file(CD, Part...)
          if (files.Count > 0)
          {
            movieFile = (string)files[0];
            Util.Utils.RemoveStackEndings(ref movieFile);
          }
          
          localCover = moviePath + @"\" + Util.Utils.GetFilename(movieFile, true) + ".jpg";
          
          // Every movie in it's own folder?
          if (folderTitle)
          {
            localCover = moviePath + @"\folder.jpg";
            if (File.Exists(localCover))
            {
              _movieDetails.ThumbURL = "file://" + localCover;
            }
          }
          // Try local movefilename.jpg
          else if (File.Exists(localCover))
          {
            _movieDetails.ThumbURL = "file://" + localCover;
          }
          //
          // No local or scraper thumb
          //
          if (_movieDetails.ThumbURL == string.Empty)
          {
            line1 = GUILocalizeStrings.Get(928) + ": IMP Awards"; // **Progress bar message cover search IMPAw start
            OnProgress(line1, _url.Title, string.Empty, percent);

            // Added IMDBNumber parameter for movie cover check
            // This number is checked on HTML cover source page, if it's equal then this is the cover for our movie

            // IMPAwards
            IMPAwardsSearch impSearch = new IMPAwardsSearch();
            impSearch.SearchCovers(_movieDetails.Title, _movieDetails.IMDBNumber);

            if ((impSearch.Count > 0) && (impSearch[0] != string.Empty))
            {
              _movieDetails.ThumbURL = impSearch[0];

              percent = percent + step; // **Progress bar message for IMPAw end
              OnProgress(line1, _url.Title, string.Empty, percent);
            }
            // If no IMPAwards lets try TMDB 
            TMDBCoverSearch tmdbSearch = new TMDBCoverSearch();
            if (impSearch.Count == 0)
            {
              line1 = GUILocalizeStrings.Get(928) + ": TMDB"; // **Progress bar message for TMDB start
              OnProgress(line1, _url.Title, string.Empty, percent);
              tmdbSearch.SearchCovers(_movieDetails.Title, _movieDetails.IMDBNumber);

              if ((tmdbSearch.Count > 0) && (tmdbSearch[0] != string.Empty))
              {
                _movieDetails.ThumbURL = tmdbSearch[0];
                percent = percent + step; // **Progress bar message for TMDB end
                OnProgress(line1, _url.Title, string.Empty, percent);
              }
            }
            // All fail, last try IMDB
            if (impSearch.Count == 0 && tmdbSearch.Count == 0)
            {
              IMDBSearch imdbSearch = new IMDBSearch();
              line1 = GUILocalizeStrings.Get(928) + ": IMDB"; // **Progress bar message for IMDB start
              OnProgress(line1, _url.Title, string.Empty, percent);
              imdbSearch.SearchCovers(_movieDetails.IMDBNumber, true);

              if ((imdbSearch.Count > 0) && (imdbSearch[0] != string.Empty))
              {
                _movieDetails.ThumbURL = imdbSearch[0];
                percent = percent + step; // **Progress bar message for IMDB end
                OnProgress(line1, _url.Title, string.Empty, percent);
              }
            }
          }
          // Title suffix for problem with cover and movies with the same name
          string titleExt = _movieDetails.Title + "{" + _movieDetails.ID + "}";
          string largeCoverArt = Util.Utils.GetLargeCoverArtName(Thumbs.MovieTitle, titleExt);
          string coverArt = Util.Utils.GetCoverArtName(Thumbs.MovieTitle, titleExt);

          if (_movieDetails.ID >= 0)
          {
            Util.Utils.FileDelete(largeCoverArt);
            Util.Utils.FileDelete(coverArt);
            line1 = GUILocalizeStrings.Get(1009);
            OnProgress(line1, _url.Title, string.Empty, percent); // **Too fast so leave percent
          }
          //
          // FanArt grab
          //
          _isFanArt = xmlreader.GetValueAsBool("moviedatabase", "usefanart", false);

          if (_isFanArt)
          {
            FanArt fanartSearch = new FanArt();
            string strFile = _movieDetails.File;
            // Check local fanart (only if every movie is in it's own folder), lookin for fanart.jpg
            if (folderTitle)
            {
              string localFanart = moviePath + @"\fanart.jpg";
              if (File.Exists(localFanart))
              {
                _movieDetails.FanartURL = "file://" + localFanart;
              }
            }
            line1 = GUILocalizeStrings.Get(921) + ": Fanart"; // **Progress bar message fanart start
            OnProgress(line1, _url.Title, string.Empty, percent);

            if (_movieDetails.FanartURL == string.Empty || _movieDetails.FanartURL == Strings.Unknown)
            {
              fanartSearch.GetTmdbFanartByApi
                (_movieDetails.Path, strFile, _movieDetails.IMDBNumber, _movieDetails.Title, true, faCount, faShare, string.Empty);
              // Set fanart url to db
              _movieDetails.FanartURL = fanartSearch.DefaultFanartUrl;
            }
            else // Local file or user url
            {
              fanartSearch.GetLocalFanart
                (_movieDetails.Path, strFile, _movieDetails.Title, _movieDetails.FanartURL, 0, faShare);
            }
            percent = percent + step; // **Progress bar message fanart End
            OnProgress(line1, _url.Title, string.Empty, percent);
          }
          //
          // Actors - Only get actors if we really want to.
          //
          if (_getActors)
          {
            line1 = GUILocalizeStrings.Get(344); // **Progress bar actors start sets actual value to 0
            OnProgress(line1, _url.Title, string.Empty, 0);
            FetchActorsInMovie();
          }
          OnDisableCancel(this);
          if (_movieDetails.ID >= 0)
          {
            line1 = GUILocalizeStrings.Get(1009); // **Progress bar downloading cover art, final step
            OnProgress(line1, _url.Title, string.Empty, percent);
            //
            // Save cover thumbs
            //
            DownloadCoverArt(Thumbs.MovieTitle, _movieDetails.ThumbURL, titleExt);
            //
            // Set folder.jpg for ripped DVDs
            //
            try
            {
              string path = _movieDetails.Path;
              string filename = _movieDetails.File;

              if (filename.ToUpper() == "VIDEO_TS.IFO")
              {
                // Remove \VIDEO_TS from directory structure
                string directoryDVD = path.Substring(0, path.LastIndexOf("\\"));
                if (Directory.Exists(directoryDVD))
                {
                  // Copy large cover file as folder.jpg
                  File.Copy(largeCoverArt, directoryDVD + "\\folder.jpg", true);
                }
              }
            }
            catch (Exception) {}
            //
            // Save details to database
            //
            // Check movie table if there is an entry that new movie is already played as share
            if (VideoDatabase.GetmovieWatchedStatus(_movieDetails.ID))
            {
              _movieDetails.Watched = 1;
            }

            VideoDatabase.SetMovieInfoById(_movieDetails.ID, ref _movieDetails);
            OnProgress(line1, _url.Title, string.Empty, 100); // **Progress bar end details
          }
        }
        else
        {
          line1 = GUILocalizeStrings.Get(416);
          OnProgress(line1, _url.Title, string.Empty, 100); // **Progress bar end (no details)
          _movieDetails = null;
        }
      }
      catch (ThreadAbortException) {}
      finally
      {
        OnDetailsEnd(this);
        _disableCancel = false;
        //Log.Info("Ending Thread for Fetching movie details:{0}", detailsThread.ManagedThreadId);
        _detailsThread = null;
      }
    }