public IMDBActor GetActorInfo(int idActor)
    {
      try
      {
        if (null == m_db)
        {
          return null;
        }
        string strSql = String.Format(
            "SELECT actorinfo.biography, actorinfo.dateofbirth, actorinfo.dateofdeath, actorinfo.minibio, actors.strActor, actorinfo.placeofbirth, actorinfo.placeofdeath, actorinfo.thumbURL, actorinfo.lastupdate, actors.IMDBActorID, actorinfo.idActor FROM actors,actorinfo WHERE actors.idActor=actorinfo.idActor AND actors.idActor ={0}", idActor);
        SQLiteResultSet results = m_db.Execute(strSql);
        
        if (results.Rows.Count != 0)
        {
          IMDBActor actor = new IMDBActor();
          actor.Biography = DatabaseUtility.Get(results, 0, "actorinfo.biography".Replace("''", "'"));
          actor.DateOfBirth = DatabaseUtility.Get(results, 0, "actorinfo.dateofbirth".Replace("''", "'"));
          actor.DateOfDeath = DatabaseUtility.Get(results, 0, "actorinfo.dateofdeath".Replace("''", "'"));
          actor.MiniBiography = DatabaseUtility.Get(results, 0, "actorinfo.minibio".Replace("''", "'"));
          actor.Name = DatabaseUtility.Get(results, 0, "actors.strActor".Replace("''", "'"));
          actor.PlaceOfBirth = DatabaseUtility.Get(results, 0, "actorinfo.placeofbirth".Replace("''", "'"));
          actor.PlaceOfDeath = DatabaseUtility.Get(results, 0, "actorinfo.placeofdeath".Replace("''", "'"));
          actor.ThumbnailUrl = DatabaseUtility.Get(results, 0, "actorinfo.thumbURL");
          actor.LastUpdate = DatabaseUtility.Get(results, 0, "actorinfo.lastupdate");
          actor.IMDBActorID = DatabaseUtility.Get(results, 0, "actors.IMDBActorID");
          actor.ID = Convert.ToInt32(DatabaseUtility.Get(results, 0, "actorinfo.idActor"));

          strSql = String.Format("SELECT * FROM actorinfomovies WHERE idActor ={0}", idActor);
          results = m_db.Execute(strSql);
          
          for (int i = 0; i < results.Rows.Count; ++i)
          {
            string imdbId = DatabaseUtility.Get(results, i, "IMDBID");
            strSql = String.Format("SELECT * FROM IMDBMovies WHERE idIMDB='{0}'", imdbId);
            SQLiteResultSet resultsImdb = m_db.Execute(strSql);

            IMDBActor.IMDBActorMovie movie = new IMDBActor.IMDBActorMovie();
            movie.ActorID = Convert.ToInt32(DatabaseUtility.Get(results, i, "idActor"));
            movie.Role = DatabaseUtility.Get(results, i, "role");
            
            if (resultsImdb.Rows.Count != 0)
            {
              // Added IMDBid
              movie.MovieTitle = DatabaseUtility.Get(resultsImdb, 0, "strTitle");
              movie.Year = Int32.Parse(DatabaseUtility.Get(resultsImdb, 0, "iYear"));
              movie.MovieImdbID = DatabaseUtility.Get(resultsImdb, 0, "idIMDB");
              movie.MoviePlot = DatabaseUtility.Get(resultsImdb, 0, "strPlot");
              movie.MovieCover = DatabaseUtility.Get(resultsImdb, 0, "strPictureURL");
              movie.MovieGenre = DatabaseUtility.Get(resultsImdb, 0, "strGenre");
              movie.MovieCast = DatabaseUtility.Get(resultsImdb, 0, "strCast");
              movie.MovieCredits = DatabaseUtility.Get(resultsImdb, 0, "strCredits");
              movie.MovieRuntime = Int32.Parse(DatabaseUtility.Get(results, i, "runtime")); // Not used
              movie.MovieMpaaRating = DatabaseUtility.Get(resultsImdb, 0, "mpaa");
            }
            actor.Add(movie);
          }
          return actor;
        }
      }
      catch (Exception ex)
      {
        Log.Error("videodatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }
      return null;
    }
Esempio n. 2
0
    private void GetActorMovies(IMDBActor actor, HTMLParser parser, bool director, bool writer)
    {
      string[] vdbParserStr = VdbParserStringActorMovies();

      if (vdbParserStr == null || vdbParserStr.Length != 19)
      {
        return;
      }

      string movies = string.Empty;
      
      // Get films and roles block
      if (parser.extractTo(vdbParserStr[0], ref movies)) // <div id
      {
        parser.Content = movies;
      }
      
      // Parse block for evey film and get year, title and it's imdbID and role
      while (parser.skipToStartOf(vdbParserStr[1])) // <span class="year_column"
      {
        string movie = string.Empty;

        if (parser.extractTo(vdbParserStr[2], ref movie)) // <div class
        {
          movie += vdbParserStr[3]; // </li>

          HTMLParser movieParser = new HTMLParser(movie);
          string title = string.Empty;
          string strYear = string.Empty;
          string role = string.Empty;
          string imdbID = string.Empty;

          // IMDBid
          movieParser.skipToEndOf(vdbParserStr[4]);           // title/
          movieParser.extractTo(vdbParserStr[5], ref imdbID); // /

          // Title
          movieParser.resetPosition();
          movieParser.skipToEndOf(vdbParserStr[6]);           // <a
          movieParser.skipToEndOf(vdbParserStr[7]);           // >
          movieParser.extractTo(vdbParserStr[8], ref title);  // <br/>
          title = CleanCrlf(title);

          if (!SkipNoMovies(title))
          {
            // Year
            movieParser.resetPosition();

            if (movieParser.skipToStartOf(vdbParserStr[9]) &&       // year_column">20
                movieParser.skipToEndOf(vdbParserStr[10]))          // >
            {
              movieParser.extractTo(vdbParserStr[11], ref strYear); // <
            }
            else
            {
              movieParser.resetPosition();
              
              if (movieParser.skipToStartOf(vdbParserStr[12]) &&      // year_column">19
                  movieParser.skipToEndOf(vdbParserStr[13]))          // >
              {
                movieParser.extractTo(vdbParserStr[14], ref strYear); // <
              }
            }

            strYear = strYear.Trim();

            if (strYear.Length > 4)
            {
              strYear = strYear.Substring(0, 4);
            }

            // Roles actor
            if (!director && !writer)
            {
              // Role case 1, no character link
              if (movieParser.skipToEndOf(vdbParserStr[15]))       // <br/>
              {
                movieParser.extractTo(vdbParserStr[16], ref role); // <
                role = CleanCrlf(role);

                // Role case 2, with character link
                if (role == string.Empty)
                {
                  movieParser.resetPosition();
                  movieParser.skipToEndOf(vdbParserStr[17]);          // <br/>
                  movieParser.extractTo(vdbParserStr[18], ref role);  // </a>
                  role = CleanCrlf(role);
                }
              }
            }
            else if (director)
            {
              role = GUILocalizeStrings.Get(199).Replace(":", string.Empty);
            }
            else // Writer
            {
              string wRole = string.Empty;

              if (title != null)
              {
                // Check for cases like "(movie type)(role)" and use "(role)" only
                MatchCollection mc = Regex.Matches(title, @"\([^)]+\)");

                if (mc.Count > 0)
                {
                  if (mc.Count > 1)
                  {
                    wRole = mc[mc.Count - 1].Value;
                  }
                  else
                  {
                    wRole = mc[0].Value;
                  }
                }
                else
                {
                  continue;
                }

                if (!string.IsNullOrEmpty(wRole))
                {
                  // Remove parentheses (leave text inside)
                  wRole = Regex.Replace(wRole, "([(]|[)])", string.Empty);
                  role = GUILocalizeStrings.Get(200) + " " + wRole;
                }
                else
                {
                  role = GUILocalizeStrings.Get(200).Replace(":", string.Empty);
                }
              }
            }

            int year = 0;
            // Set near future for movies without year (99% it's a future project)
            if (!Int32.TryParse(strYear, out year))
            {
             year = DateTime.Today.Year + 3;
            }
            
            IMDBActor.IMDBActorMovie actorMovie = new IMDBActor.IMDBActorMovie();
            title = Util.Utils.RemoveParenthesis(title).Trim();
            role = Util.Utils.RemoveParenthesis(role).Trim();
            actorMovie.MovieTitle = title;
            actorMovie.Role = role;
            actorMovie.Year = year;
            actorMovie.MovieImdbID = imdbID;
            // Check if director/writer movie exists in actors movies, concatenate role
            // to already fetched actor movie (no duplicate movie entries)
            bool skipAdd = false;

            if (writer)
            {
              for (int i = 0; i < actor.Count; i++)
              {
                if (actor[i].MovieImdbID == imdbID)
                {
                  if (actor[i].Role != string.Empty)
                  {
                    actor[i].Role = role + ", " + actor[i].Role;
                  }
                  else
                  {
                    actor[i].Role = role;
                  }

                  skipAdd = true;
                  break;
                }
              }
            }

            if (director)
            {
              for (int i = 0; i < actor.Count; i++)
              {
                if (actor[i].MovieImdbID == imdbID)
                {
                  if (actor[i].Role != string.Empty)
                  {
                    actor[i].Role = role + ", " + actor[i].Role;
                  }
                  else
                  {
                    actor[i].Role = role;
                  }
                  skipAdd = true;
                  break;
                }
              }
            }

            if (!skipAdd)
            {
              actor.Add(actorMovie);
            }
          }
        }
      }
    }
Esempio n. 3
0
    // Changed - parsing all actor DB fields through HTML (IMDB changed HTML code)
    public bool GetActorDetails(IMDBUrl url, bool director, out IMDBActor actor)
    {
      actor = new IMDBActor();
      try
      {
        string absoluteUri;
        string strBody = GetPage(url.URL, "utf-8", out absoluteUri);
        if (strBody == null)
        {
          return false;
        }
        if (strBody.Length == 0)
        {
          return false;
        }
        // IMDBActorID
        try
        {
          int pos = url.URL.LastIndexOf("nm");
          string id = url.URL.Substring(pos, 9).Replace("/", string.Empty);
          actor.IMDBActorID = id;
        }
        catch (Exception) {}

        HTMLParser parser = new HTMLParser(strBody);
        string strThumb = string.Empty;
        string value = string.Empty;
        string value2 = string.Empty;
        // Actor name
        if ((parser.skipToEndOf("<title>")) &&
            (parser.extractTo("- IMDb</title>", ref value)))
        {
          value = new HTMLUtil().ConvertHTMLToAnsi(value);
          value = Util.Utils.RemoveParenthesis(value).Trim();
          actor.Name = HttpUtility.HtmlDecode(value.Trim());
        }
        if (actor.Name == string.Empty)
        {
          actor.Name = url.Title;
        }
        // Photo
        string parserTxt = parser.Content;
        string photoBlock = string.Empty;
        if (parser.skipToStartOf("<td id=\"img_primary\"") &&
            (parser.extractTo("</td>", ref photoBlock)))
        {
          parser.Content = photoBlock;
          if ((parser.skipToEndOf("<img src=\"")) &&
              (parser.extractTo("\"", ref strThumb)))
          {
            actor.ThumbnailUrl = strThumb;
          }
          parser.Content = parserTxt;
        }
        // Birth date
        if ((parser.skipToEndOf("Born:")) &&
            (parser.skipToEndOf("birth_monthday=")) &&
            (parser.skipToEndOf(">")) &&
            (parser.extractTo("<", ref value)) &&
            (parser.skipToEndOf("year=")) &&
            (parser.extractTo("\"", ref value2)))
          
        {
          actor.DateOfBirth = value + " " + value2;
        }
        // Death date
        if ((parser.skipToEndOf(">Died:</h4>")) &&
            (parser.skipToEndOf("deaths\">")) &&
            (parser.extractTo("<", ref value)) &&
            (parser.skipToEndOf("death_date=")) &&
            (parser.extractTo("\"", ref value2)))
        {
          if (actor.DateOfBirth == string.Empty)
            actor.DateOfBirth = "?";
          actor.DateOfBirth += " ~ " + value + " " + value2;
        }

        parser.resetPosition();
        // Birth place
        if ((parser.skipToEndOf("birth_place=")) &&
            (parser.skipToEndOf(">")) &&
            (parser.extractTo("<", ref value)))
        {
          actor.PlaceOfBirth = HttpUtility.HtmlDecode(value);
        }
        //Mini Biography
        parser.resetPosition();
        if ((parser.skipToEndOf("<td id=\"overview-top\">")) &&
            (parser.skipToEndOf("<p>")) &&
            (parser.extractTo("See full bio</a>", ref value)))
        {
          value = new HTMLUtil().ConvertHTMLToAnsi(value);
          actor.MiniBiography = Util.Utils.stripHTMLtags(value);
          actor.MiniBiography = actor.MiniBiography.Replace("See full bio »", string.Empty).Trim();
          actor.MiniBiography = HttpUtility.HtmlDecode(actor.MiniBiography); // Remove HTML entities like &#189;
          if (actor.MiniBiography != string.Empty)
          {
            // get complete biography
            string bioURL = absoluteUri;
            if (!bioURL.EndsWith("/"))
            {
              bioURL += "/bio";
            }
            else
              bioURL += "bio";
            string strBioBody = GetPage(bioURL, "utf-8", out absoluteUri);
            if (!string.IsNullOrEmpty(strBioBody))
            {
              HTMLParser parser1 = new HTMLParser(strBioBody);
              if (parser1.skipToEndOf("<h5>Mini Biography</h5>") &&
                  parser1.extractTo("</p>", ref value))
              {
                value = new HTMLUtil().ConvertHTMLToAnsi(value);
                actor.Biography = Util.Utils.stripHTMLtags(value).Trim();
                actor.Biography = HttpUtility.HtmlDecode(actor.Biography); // Remove HTML entities like &#189;
              }
            }
          }
        }
        // Person is movie director or an actor/actress
        bool isActorPass = false;
        bool isDirectorPass = false;
        parser.resetPosition();

        if (director)
        {
          if ((parser.skipToEndOf("name=\"Director\">Director</a>")) &&
              (parser.skipToEndOf("</div>")))
          {
            isDirectorPass = true;
          }
        }
        else
        {
          if (parser.skipToEndOf("name=\"Actress\">Actress</a>") || parser.skipToEndOf("name=\"Actor\">Actor</a>"))
          {
            isActorPass = true;
          }
        }
        // Get filmography
        if (isDirectorPass | isActorPass)
        {
          string movies = string.Empty;
          // Get films and roles block
          if (parser.extractTo("<div id", ref movies))
          {
            parser.Content = movies;
          }
          // Parse block for evey film and get year, title and it's imdbID and role
          while (parser.skipToStartOf("<span class=\"year_column\""))
          {
            string movie = string.Empty;
            if (parser.extractTo("<div class", ref movie))
            {
              movie += "</li>";
              HTMLParser movieParser = new HTMLParser(movie);
              string title = string.Empty;
              string strYear = string.Empty;
              string role = string.Empty;
              string imdbID = string.Empty;
              // IMDBid
              movieParser.skipToEndOf("title/");
              movieParser.extractTo("/", ref imdbID);
              // Title
              movieParser.resetPosition();
              movieParser.skipToEndOf("<a");
              movieParser.skipToEndOf(">");
              movieParser.extractTo("<br/>", ref title);
              title = Util.Utils.stripHTMLtags(title);
              title = title.Replace("\n", " ").Replace("\r", string.Empty);
              title = HttpUtility.HtmlDecode(title.Trim()); // Remove HTML entities like &#189;
              // Year
              movieParser.resetPosition();
              if (movieParser.skipToStartOf(">20") &&
                  movieParser.skipToEndOf(">"))
              {
                movieParser.extractTo("<", ref strYear);
              }
              else if (movieParser.skipToStartOf(">19") &&
                       movieParser.skipToEndOf(">"))
              {
                movieParser.extractTo("<", ref strYear);
              }
              // Roles
              if ((director == false) && (movieParser.skipToEndOf("<br/>"))) // Role case 1, no character link
              {
                movieParser.extractTo("<", ref role);
                role = Util.Utils.stripHTMLtags(role).Trim();
                role = HttpUtility.HtmlDecode(role.Replace("\n", " ")
                                                .Replace("\r", string.Empty).Trim());
                if (role == string.Empty) // Role case 2, with character link
                {
                  movieParser.resetPosition();
                  movieParser.skipToEndOf("<br/>");
                  movieParser.extractTo("</a>", ref role);
                  role = Util.Utils.stripHTMLtags(role).Trim();
                  role = HttpUtility.HtmlDecode(role.Replace("\n", " ")
                                                  .Replace("\r", string.Empty).Trim());
                }
              }
              else
              {
                // Just director
                if (director)
                  role = "Director";
              }

              int year = 0;
              try
              {
                year = Int32.Parse(strYear.Substring(0, 4));
              }
              catch (Exception)
              {
                year = 1900;
              }
              IMDBActor.IMDBActorMovie actorMovie = new IMDBActor.IMDBActorMovie();
              actorMovie.MovieTitle = title;
              actorMovie.Role = role;
              actorMovie.Year = year;
              actorMovie.imdbID = imdbID;
              actor.Add(actorMovie);
            }
          }
        }
        return true;
      }
      catch (Exception ex)
      {
        Log.Error("IMDB.GetActorDetails({0} exception:{1} {2} {3}", url.URL, ex.Message, ex.Source, ex.StackTrace);
      }
      return false;
    }
Esempio n. 4
0
    // 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;
        }
      }
    }
    // Changed get thumbnailURL - IMDBActorID - IMDBID for movies
    public IMDBActor GetActorInfo(int idActor)
    {
      //"CREATE TABLE actorinfo ( idActor integer, dateofbirth text, placeofbirth text, minibio text, biography text
      try
      {
        if (null == m_db)
        {
          return null;
        }
        string strSQL =
          String.Format(
            "select * from actors,actorinfo where actors.idActor=actorinfo.idActor and actors.idActor ={0}", idActor);
        SQLiteResultSet results = m_db.Execute(strSQL);
        if (results.Rows.Count != 0)
        {
          IMDBActor actor = new IMDBActor();
          actor.Biography = DatabaseUtility.Get(results, 0, "actorinfo.biography".Replace("''", "'"));
          actor.DateOfBirth = DatabaseUtility.Get(results, 0, "actorinfo.dateofbirth");
          actor.MiniBiography = DatabaseUtility.Get(results, 0, "actorinfo.minibio".Replace("''", "'"));
          actor.Name = DatabaseUtility.Get(results, 0, "actors.strActor".Replace("''", "'"));
          actor.PlaceOfBirth = DatabaseUtility.Get(results, 0, "actorinfo.placeofbirth".Replace("''", "'"));
          actor.ThumbnailUrl = DatabaseUtility.Get(results, 0, "actorinfo.thumbURL");
          actor.IMDBActorID = DatabaseUtility.Get(results, 0, "actorinfo.IMDBActorID");

          strSQL = String.Format("select * from actorinfomovies where idActor ={0}", idActor);
          results = m_db.Execute(strSQL);
          for (int i = 0; i < results.Rows.Count; ++i)
          {
            IMDBActor.IMDBActorMovie movie = new IMDBActor.IMDBActorMovie();
            movie.MovieTitle = DatabaseUtility.Get(results, i, "strTitle");
            movie.Role = DatabaseUtility.Get(results, i, "role");
            movie.Year = Int32.Parse(DatabaseUtility.Get(results, i, "iYear"));
            // Added IMDBid
            movie.imdbID = DatabaseUtility.Get(results, i, "IMDBID");
            actor.Add(movie);
          }
          return actor;
        }
      }
      catch (Exception ex)
      {
        Log.Error("videodatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
        Open();
      }
      return null;
    }
Esempio n. 6
0
        private void GetActorMovies(IMDBActor actor, HTMLParser parser, bool director, bool writer)
        {
            string[] vdbParserStr = VdbParserStringActorMovies();

            if (vdbParserStr == null || vdbParserStr.Length != 19)
            {
                return;
            }

            string movies = string.Empty;

            // Get films and roles block
            if (parser.extractTo(vdbParserStr[0], ref movies)) // <div id
            {
                parser.Content = movies;
            }

            // Parse block for evey film and get year, title and it's imdbID and role
            while (parser.skipToStartOf(vdbParserStr[1])) // <span class="year_column"
            {
                string movie = string.Empty;

                if (parser.extractTo(vdbParserStr[2], ref movie)) // <div class
                {
                    movie += vdbParserStr[3];                     // </li>

                    HTMLParser movieParser = new HTMLParser(movie);
                    string     title       = string.Empty;
                    string     strYear     = string.Empty;
                    string     role        = string.Empty;
                    string     imdbID      = string.Empty;

                    // IMDBid
                    movieParser.skipToEndOf(vdbParserStr[4]);           // title/
                    movieParser.extractTo(vdbParserStr[5], ref imdbID); // /

                    // Title
                    movieParser.resetPosition();
                    movieParser.skipToEndOf(vdbParserStr[6]);          // <a
                    movieParser.skipToEndOf(vdbParserStr[7]);          // >
                    movieParser.extractTo(vdbParserStr[8], ref title); // <br/>
                    title = CleanCrlf(title);

                    if (!SkipNoMovies(title))
                    {
                        // Year
                        movieParser.resetPosition();

                        if (movieParser.skipToStartOf(vdbParserStr[9]) &&         // year_column">20
                            movieParser.skipToEndOf(vdbParserStr[10]))            // >
                        {
                            movieParser.extractTo(vdbParserStr[11], ref strYear); // <
                        }
                        else
                        {
                            movieParser.resetPosition();

                            if (movieParser.skipToStartOf(vdbParserStr[12]) &&        // year_column">19
                                movieParser.skipToEndOf(vdbParserStr[13]))            // >
                            {
                                movieParser.extractTo(vdbParserStr[14], ref strYear); // <
                            }
                        }

                        strYear = strYear.Trim();

                        if (strYear.Length > 4)
                        {
                            strYear = strYear.Substring(0, 4);
                        }

                        // Roles actor
                        if (!director && !writer)
                        {
                            // Role case 1, no character link
                            if (movieParser.skipToEndOf(vdbParserStr[15]))         // <br/>
                            {
                                movieParser.extractTo(vdbParserStr[16], ref role); // <
                                role = CleanCrlf(role);

                                // Role case 2, with character link
                                if (role == string.Empty)
                                {
                                    movieParser.resetPosition();
                                    movieParser.skipToEndOf(vdbParserStr[17]);         // <br/>
                                    movieParser.extractTo(vdbParserStr[18], ref role); // </a>
                                    role = CleanCrlf(role);
                                }
                            }
                        }
                        else if (director)
                        {
                            role = GUILocalizeStrings.Get(199).Replace(":", string.Empty);
                        }
                        else // Writer
                        {
                            string wRole = string.Empty;

                            if (title != null)
                            {
                                // Check for cases like "(movie type)(role)" and use "(role)" only
                                MatchCollection mc = Regex.Matches(title, @"\([^)]+\)");

                                if (mc.Count > 0)
                                {
                                    if (mc.Count > 1)
                                    {
                                        wRole = mc[mc.Count - 1].Value;
                                    }
                                    else
                                    {
                                        wRole = mc[0].Value;
                                    }
                                }
                                else
                                {
                                    continue;
                                }

                                if (!string.IsNullOrEmpty(wRole))
                                {
                                    // Remove parentheses (leave text inside)
                                    wRole = Regex.Replace(wRole, "([(]|[)])", string.Empty);
                                    role  = GUILocalizeStrings.Get(200) + " " + wRole;
                                }
                                else
                                {
                                    role = GUILocalizeStrings.Get(200).Replace(":", string.Empty);
                                }
                            }
                        }

                        int year = 0;
                        // Set near future for movies without year (99% it's a future project)
                        if (!Int32.TryParse(strYear, out year))
                        {
                            year = DateTime.Today.Year + 3;
                        }

                        IMDBActor.IMDBActorMovie actorMovie = new IMDBActor.IMDBActorMovie();
                        title = Util.Utils.RemoveParenthesis(title).Trim();
                        role  = Util.Utils.RemoveParenthesis(role).Trim();
                        actorMovie.MovieTitle  = title;
                        actorMovie.Role        = role;
                        actorMovie.Year        = year;
                        actorMovie.MovieImdbID = imdbID;
                        // Check if director/writer movie exists in actors movies, concatenate role
                        // to already fetched actor movie (no duplicate movie entries)
                        bool skipAdd = false;

                        if (writer)
                        {
                            for (int i = 0; i < actor.Count; i++)
                            {
                                if (actor[i].MovieImdbID == imdbID)
                                {
                                    if (actor[i].Role != string.Empty)
                                    {
                                        actor[i].Role = role + ", " + actor[i].Role;
                                    }
                                    else
                                    {
                                        actor[i].Role = role;
                                    }

                                    skipAdd = true;
                                    break;
                                }
                            }
                        }

                        if (director)
                        {
                            for (int i = 0; i < actor.Count; i++)
                            {
                                if (actor[i].MovieImdbID == imdbID)
                                {
                                    if (actor[i].Role != string.Empty)
                                    {
                                        actor[i].Role = role + ", " + actor[i].Role;
                                    }
                                    else
                                    {
                                        actor[i].Role = role;
                                    }
                                    skipAdd = true;
                                    break;
                                }
                            }
                        }

                        if (!skipAdd)
                        {
                            actor.Add(actorMovie);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        // Changed - parsing all actor DB fields through HTML (IMDB changed HTML code)
        public bool GetActorDetails(IMDBUrl url, bool director, out IMDBActor actor)
        {
            actor = new IMDBActor();
            try
            {
                string absoluteUri;
                string strBody = GetPage(url.URL, "utf-8", out absoluteUri);
                if (strBody == null)
                {
                    return(false);
                }
                if (strBody.Length == 0)
                {
                    return(false);
                }
                // IMDBActorID
                try
                {
                    int    pos = url.URL.LastIndexOf("nm");
                    string id  = url.URL.Substring(pos, 9).Replace("/", string.Empty);
                    actor.IMDBActorID = id;
                }
                catch (Exception) {}

                HTMLParser parser   = new HTMLParser(strBody);
                string     strThumb = string.Empty;
                string     value    = string.Empty;
                string     value2   = string.Empty;
                // Actor name
                if ((parser.skipToEndOf("<title>")) &&
                    (parser.extractTo("- IMDb</title>", ref value)))
                {
                    value      = new HTMLUtil().ConvertHTMLToAnsi(value);
                    value      = Util.Utils.RemoveParenthesis(value).Trim();
                    actor.Name = HttpUtility.HtmlDecode(value.Trim());
                }
                if (actor.Name == string.Empty)
                {
                    actor.Name = url.Title;
                }
                // Photo
                string parserTxt  = parser.Content;
                string photoBlock = string.Empty;
                if (parser.skipToStartOf("<td id=\"img_primary\"") &&
                    (parser.extractTo("</td>", ref photoBlock)))
                {
                    parser.Content = photoBlock;
                    if ((parser.skipToEndOf("<img src=\"")) &&
                        (parser.extractTo("\"", ref strThumb)))
                    {
                        actor.ThumbnailUrl = strThumb;
                    }
                    parser.Content = parserTxt;
                }
                // Birth date
                if ((parser.skipToEndOf("Born:")) &&
                    (parser.skipToEndOf("birth_monthday=")) &&
                    (parser.skipToEndOf(">")) &&
                    (parser.extractTo("<", ref value)) &&
                    (parser.skipToEndOf("year=")) &&
                    (parser.extractTo("\"", ref value2)))

                {
                    actor.DateOfBirth = value + " " + value2;
                }
                // Death date
                if ((parser.skipToEndOf(">Died:</h4>")) &&
                    (parser.skipToEndOf("deaths\">")) &&
                    (parser.extractTo("<", ref value)) &&
                    (parser.skipToEndOf("death_date=")) &&
                    (parser.extractTo("\"", ref value2)))
                {
                    if (actor.DateOfBirth == string.Empty)
                    {
                        actor.DateOfBirth = "?";
                    }
                    actor.DateOfBirth += " ~ " + value + " " + value2;
                }

                parser.resetPosition();
                // Birth place
                if ((parser.skipToEndOf("birth_place=")) &&
                    (parser.skipToEndOf(">")) &&
                    (parser.extractTo("<", ref value)))
                {
                    actor.PlaceOfBirth = HttpUtility.HtmlDecode(value);
                }
                //Mini Biography
                parser.resetPosition();
                if ((parser.skipToEndOf("<td id=\"overview-top\">")) &&
                    (parser.skipToEndOf("<p>")) &&
                    (parser.extractTo("See full bio</a>", ref value)))
                {
                    value = new HTMLUtil().ConvertHTMLToAnsi(value);
                    actor.MiniBiography = Util.Utils.stripHTMLtags(value);
                    actor.MiniBiography = actor.MiniBiography.Replace("See full bio »", string.Empty).Trim();
                    actor.MiniBiography = HttpUtility.HtmlDecode(actor.MiniBiography); // Remove HTML entities like &#189;
                    if (actor.MiniBiography != string.Empty)
                    {
                        // get complete biography
                        string bioURL = absoluteUri;
                        if (!bioURL.EndsWith("/"))
                        {
                            bioURL += "/bio";
                        }
                        else
                        {
                            bioURL += "bio";
                        }
                        string strBioBody = GetPage(bioURL, "utf-8", out absoluteUri);
                        if (!string.IsNullOrEmpty(strBioBody))
                        {
                            HTMLParser parser1 = new HTMLParser(strBioBody);
                            if (parser1.skipToEndOf("<h5>Mini Biography</h5>") &&
                                parser1.extractTo("</p>", ref value))
                            {
                                value           = new HTMLUtil().ConvertHTMLToAnsi(value);
                                actor.Biography = Util.Utils.stripHTMLtags(value).Trim();
                                actor.Biography = HttpUtility.HtmlDecode(actor.Biography); // Remove HTML entities like &#189;
                            }
                        }
                    }
                }
                // Person is movie director or an actor/actress
                bool isActorPass    = false;
                bool isDirectorPass = false;
                parser.resetPosition();

                if (director)
                {
                    if ((parser.skipToEndOf("name=\"Director\">Director</a>")) &&
                        (parser.skipToEndOf("</div>")))
                    {
                        isDirectorPass = true;
                    }
                }
                else
                {
                    if (parser.skipToEndOf("name=\"Actress\">Actress</a>") || parser.skipToEndOf("name=\"Actor\">Actor</a>"))
                    {
                        isActorPass = true;
                    }
                }
                // Get filmography
                if (isDirectorPass | isActorPass)
                {
                    string movies = string.Empty;
                    // Get films and roles block
                    if (parser.extractTo("<div id", ref movies))
                    {
                        parser.Content = movies;
                    }
                    // Parse block for evey film and get year, title and it's imdbID and role
                    while (parser.skipToStartOf("<span class=\"year_column\""))
                    {
                        string movie = string.Empty;
                        if (parser.extractTo("<div class", ref movie))
                        {
                            movie += "</li>";
                            HTMLParser movieParser = new HTMLParser(movie);
                            string     title       = string.Empty;
                            string     strYear     = string.Empty;
                            string     role        = string.Empty;
                            string     imdbID      = string.Empty;
                            // IMDBid
                            movieParser.skipToEndOf("title/");
                            movieParser.extractTo("/", ref imdbID);
                            // Title
                            movieParser.resetPosition();
                            movieParser.skipToEndOf("<a");
                            movieParser.skipToEndOf(">");
                            movieParser.extractTo("<br/>", ref title);
                            title = Util.Utils.stripHTMLtags(title);
                            title = title.Replace("\n", " ").Replace("\r", string.Empty);
                            title = HttpUtility.HtmlDecode(title.Trim()); // Remove HTML entities like &#189;
                            // Year
                            movieParser.resetPosition();
                            if (movieParser.skipToStartOf(">20") &&
                                movieParser.skipToEndOf(">"))
                            {
                                movieParser.extractTo("<", ref strYear);
                            }
                            else if (movieParser.skipToStartOf(">19") &&
                                     movieParser.skipToEndOf(">"))
                            {
                                movieParser.extractTo("<", ref strYear);
                            }
                            // Roles
                            if ((director == false) && (movieParser.skipToEndOf("<br/>"))) // Role case 1, no character link
                            {
                                movieParser.extractTo("<", ref role);
                                role = Util.Utils.stripHTMLtags(role).Trim();
                                role = HttpUtility.HtmlDecode(role.Replace("\n", " ")
                                                              .Replace("\r", string.Empty).Trim());
                                if (role == string.Empty) // Role case 2, with character link
                                {
                                    movieParser.resetPosition();
                                    movieParser.skipToEndOf("<br/>");
                                    movieParser.extractTo("</a>", ref role);
                                    role = Util.Utils.stripHTMLtags(role).Trim();
                                    role = HttpUtility.HtmlDecode(role.Replace("\n", " ")
                                                                  .Replace("\r", string.Empty).Trim());
                                }
                            }
                            else
                            {
                                // Just director
                                if (director)
                                {
                                    role = "Director";
                                }
                            }

                            int year = 0;
                            try
                            {
                                year = Int32.Parse(strYear.Substring(0, 4));
                            }
                            catch (Exception)
                            {
                                year = 1900;
                            }
                            IMDBActor.IMDBActorMovie actorMovie = new IMDBActor.IMDBActorMovie();
                            actorMovie.MovieTitle = title;
                            actorMovie.Role       = role;
                            actorMovie.Year       = year;
                            actorMovie.imdbID     = imdbID;
                            actor.Add(actorMovie);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("IMDB.GetActorDetails({0} exception:{1} {2} {3}", url.URL, ex.Message, ex.Source, ex.StackTrace);
            }
            return(false);
        }