public void SetWriterString(string writers) { int num1 = 0, num2 = 0; if (writers.IndexOf("|") < 0) { IMDbPerson person = GetPerson(writers); if (person != null) person.IsWriter = true; else { IMDbPerson newWriter = new IMDbPerson(); newWriter.Name = writers; newWriter.IsWriter = true; _people.Add(newWriter); } } else while (num1 > -1 && num1 < writers.Length) { num1 = writers.IndexOf("|", num1); if (num1 > -1) { num1++; num2 = writers.IndexOf("|", num1); if (num2 > -1) { string name = writers.Substring(num1, (num2 - num1)).Trim(); IMDbPerson person = GetPerson(name); if (person != null) person.IsWriter = true; else { IMDbPerson newWriter = new IMDbPerson(); newWriter.Name = name; newWriter.IsWriter = true; _people.Add(newWriter); } } } } }
public void SetDirectorString(string directors) { int num1 = 0, num2 = 0; if (directors.IndexOf("|") < 0) { IMDbPerson person = GetPerson(directors); if (person != null) person.IsDirector = true; else { IMDbPerson newDirector = new IMDbPerson(); newDirector.Name = directors; newDirector.IsDirector = true; _people.Add(newDirector); } } else while (num1 > -1 && num1 < directors.Length) { num1 = directors.IndexOf("|", num1); if (num1 > -1) { num1++; num2 = directors.IndexOf("|", num1); if (num2 > -1) { string name = directors.Substring(num1, (num2 - num1)).Trim(); IMDbPerson person = GetPerson(name); if (person != null) person.IsDirector = true; else { IMDbPerson newDirector = new IMDbPerson(); newDirector.Name = name; newDirector.IsDirector = true; _people.Add(newDirector); } } } } }
public IMDbMovie GetMovieInfo1(string IMDbID) { IMDbMovie movie = new IMDbMovie(); string text1 = "", text2 = "", text3 = "", personURL = ""; int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0; bool flag1 = false; try { #region Get HTML retry_download_html: try { text1 = ToolBox.WebUtils.GetSiteContents("http://www.imdb.com/title/" + IMDbID.Trim()); if (text1 == null || text1.Trim() == "") if (num1 <= _retries) { num1++; System.Threading.Thread.Sleep(2000); goto retry_download_html; } } catch { if (num2 <= _retries) { System.Threading.Thread.Sleep(2000); num2++; goto retry_download_html; } else { return null; } } #endregion #region Clear garbage num2 = text1.ToLower().IndexOf("<a href=\"/\">imdb</a>"); if (num2 > -1) { num2 += 20; num3 = text1.ToLower().IndexOf("show more recommendations</a>", num2); if (num3 > -1) { text1 = text1.Substring(num2, (num3 - num2)).Trim(); flag1 = true; } } #endregion if (flag1) { movie.IMDb_ID = IMDbID; #region Get Title //Get Title text2 = ""; num2 = text1.ToLower().IndexOf(">"); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); num1 = text2.IndexOf("("); if (num1 > -1) { text2 = text2.Substring(0, num1).Trim(); } movie.Title = text2.Trim(); } } #endregion #region Get Production Year //Get Production Year text2 = ""; num2 = text1.ToLower().IndexOf("/years/"); if (num2 > -1) { num2 += 7; num3 = text1.ToLower().IndexOf("\"", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); movie.Year = text2.Trim(); } } #endregion #region Get Director(s) //Get Director(s) personURL = ""; text2 = ""; num2 = text1.ToLower().IndexOf("<h5>director"); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<h5>writer", num2); if (num3 < 0) { num3 = text1.ToLower().IndexOf("<h5>genre", num2); } if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); num2 = 0; do { num2 = text2.ToLower().IndexOf("/name/", num2); if (num2 > -1) { num3 = text2.ToLower().IndexOf("\"", num2); if (num3 > -1) { personURL = text2.Substring(num2, (num3 - num2)).Trim(); } num2++; num2 = text2.ToLower().IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text2.ToLower().IndexOf("<", num2); if (num3 > -1) { text3 = text2.Substring(num2, (num3 - num2)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); IIMDbPerson person = movie.People.GetPersonByURL(personURL); if (person == null) { person = new IMDbPerson(); movie.People.Add(person); person.Name = text3.Trim(); person.URL = personURL; } person.IsDirector = true; personURL = ""; } } } } while (num2 > -1); } } #endregion #region Get Writer(s) //Get Writer(s) personURL = ""; text2 = ""; num2 = text1.ToLower().IndexOf("<h5>writer"); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<h5>genre", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); num2 = 0; do { num2 = text2.ToLower().IndexOf("/name/", num2); if (num2 > -1) { num3 = text2.ToLower().IndexOf("\"", num2); if (num3 > -1) { personURL = text2.Substring(num2, (num3 - num2)).Trim(); } num2++; num2 = text2.ToLower().IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text2.ToLower().IndexOf("<", num2); if (num3 > -1) { text3 = text2.Substring(num2, (num3 - num2)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); IIMDbPerson person = movie.People.GetPersonByURL(personURL); if (person == null) { person = new IMDbPerson(); movie.People.Add(person); person.Name = text3.Trim(); person.URL = personURL; } person.IsWriter = true; personURL = ""; } } } } while (num2 > -1); } } #endregion #region Get Genre(s) //Get Genre(s) text2 = ""; num2 = text1.ToLower().IndexOf("<h5>genre"); if (num2 > -1) { do { num2 = text1.ToLower().IndexOf("/genres/", num2); if (num2 > -1) { num2++; num2 = text1.ToLower().IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); movie.Genres.Add(text2.Trim()); } } } } while (num2 > -1); } #endregion #region Get Tagline //Get Tagline text2 = ""; num2 = text1.ToLower().IndexOf("tagline:"); if (num2 > -1) { num2 = text1.IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); if (text2.ToLower().EndsWith("(more)")) { text2 = text2.Substring(0, text2.Length - 6).Trim(); } else { text2 = text2.Trim(); } num2 = text2.IndexOf("["); if (num2 > -1) { text2 = text2.Substring(0, num2); } movie.Tagline = text2.Trim(); } } } #endregion #region Get Overview //Get Overview text2 = ""; num2 = text1.ToLower().IndexOf("plot outline:"); if (num2 < 0) { num2 = text1.ToLower().IndexOf("plot summary:"); } if (num2 > -1) { num2 = text1.IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); if (text2.ToLower().EndsWith("(more)")) { movie.OverviewShort = text2.Substring(0, text2.Length - 6).Trim() + "..."; } else { movie.OverviewShort = text2.Trim(); } } } } text2 = ""; num2 = text1.ToLower().IndexOf("/" + IMDbID + "/plotsummary"); if (num2 > -1) { string plothtml = ""; string plottext = ""; try { plothtml = ToolBox.WebUtils.GetSiteContents("http://www.imdb.com/title/" + IMDbID + "/plotsummary"); } catch { // do nothing } num2 = plothtml.ToLower().IndexOf("plotpar"); if (num2 > -1) { num2 = plothtml.IndexOf(">", num2); if (num2 > -1) { num2++; num3 = plothtml.ToLower().IndexOf("</p>", num2); num4 = plothtml.ToLower().IndexOf("<i>", num2); if (num3 > -1) { if (num4 > -1 && num4 < num3) { plottext = plothtml.Substring(num2, (num4 - num2)).Trim(); plottext = ToolBox.WebUtils.CleanUpHTML(plottext, true).Trim(); plottext = ToolBox.WebUtils.FixString(plottext).Trim(); } else if (num3 > -1) { plottext = plothtml.Substring(num2, (num3 - num2)).Trim(); plottext = ToolBox.WebUtils.CleanUpHTML(plottext, true).Trim(); plottext = ToolBox.WebUtils.FixString(plottext).Trim(); } } } } if (plottext.Trim() != "") movie.OverviewLong = plottext.Trim(); } #endregion #region Get Review //Get Review text2 = ""; num2 = text1.ToLower().IndexOf("user rating:"); if (num2 > -1) { num2 = text1.IndexOf("<b>", num2); if (num2 > -1) { num2 += 3; num3 = text1.ToLower().IndexOf("/", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); movie.Review = text2.Trim(); } } } #endregion #region Get Actors //Get Actors string actorText = ToolBox.WebUtils.GetSiteContents("http://www.imdb.com/title/" + IMDbID.Trim() + "/fullcredits#cast"); personURL = ""; text2 = ""; num2 = actorText.ToLower().IndexOf("cast</a>"); if (num2 > -1) { num2++; num3 = actorText.ToLower().IndexOf("produced by<", num2); if (num3 > -1) { text2 = actorText.Substring(num2, (num3 - num2)).Trim(); num1 = 0; num2 = 0; do { if (num1 < _actorCount) { num2 = text2.ToLower().IndexOf("/name/", num2); if (num2 > -1) { num5 = num2; num3 = text2.ToLower().IndexOf("\"", num2); if (num3 > -1) personURL = text2.ToLower().Substring(num2, (num3 - num2)).Trim(); num2 = text2.ToLower().IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text2.ToLower().IndexOf("<img", num2); if (num3 > -1) { if (num3 != num2) { num3 = text2.IndexOf("<", num2); if (num3 > -1 && num3 != num2) { text3 = text2.Substring(num2, (num3 - num2)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); IIMDbPerson person = movie.People.GetPersonByURL(personURL); if (person == null) { person = new IMDbPerson(); movie.People.Add(person); person.Name = text3.Trim(); person.URL = personURL; } person.IsActor = true; // get character roles string sPersonID = personURL; if (sPersonID.EndsWith("/")) sPersonID = sPersonID.Substring(0, (sPersonID.Length - 1)); sPersonID = sPersonID.Substring((sPersonID.LastIndexOf("/") + 1)); num4 = text2.ToLower().IndexOf(" ... ", num3); if (num4 > -1) { bool bCharacter = false; num5 = text2.ToLower().IndexOf("/character/", num4); if (num5 > -1) { if ((num5 - num4) < 50) { bCharacter = true; num3 = text2.IndexOf(">", num5); if (num3 > -1) { num3++; num4 = text2.IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } } } } if (bCharacter == false) { num3 = num4 + 10; num3 = text2.IndexOf(">", num3); if (num3 > -1) { num3++; num4 = text2.ToLower().IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } else person.AddRole("Unknown"); } else person.AddRole("Unknown"); } } else person.AddRole("Unknown"); num1++; } } else { num3++; num3 = text2.ToLower().IndexOf("/name/", num3); if (num3 > -1) { num2 = text2.IndexOf(">", num3); if (num2 > -1) { num2++; num3 = text2.IndexOf("<", num2); if (num3 > -1 && num3 != num2) { text3 = text2.Substring(num2, (num3 - num2)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); IIMDbPerson person = movie.People.GetPersonByURL(personURL); if (person == null) { person = new IMDbPerson(); movie.People.Add(person); person.Name = text3.Trim(); person.URL = personURL; } person.IsActor = true; // get character roles string sPersonID = personURL; if (sPersonID.EndsWith("/")) sPersonID = sPersonID.Substring(0, (sPersonID.Length - 1)); sPersonID = sPersonID.Substring((sPersonID.LastIndexOf("/") + 1)); num4 = text2.ToLower().IndexOf(" ... ", num3); if (num4 > -1) { bool bCharacter = false; num5 = text2.ToLower().IndexOf("/character/", num4); if (num5 > -1) { if ((num5 - num4) < 50) { bCharacter = true; num3 = text2.IndexOf(">", num5); if (num3 > -1) { num3++; num4 = text2.IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } } } } if (bCharacter == false) { num3 = num4 + 10; num3 = text2.IndexOf(">", num3); if (num3 > -1) { num3++; num4 = text2.ToLower().IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } else person.AddRole("Unknown"); } else person.AddRole("Unknown"); } } else person.AddRole("Unknown"); num1++; } } } } } else { num2 = text2.IndexOf(">", num5); if (num2 > -1) { num2++; num3 = text2.IndexOf("<", num2); if (num3 > -1) { text3 = text2.Substring(num2, (num3 - num2)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); IIMDbPerson person = movie.People.GetPersonByURL(personURL); if (person == null) { person = new IMDbPerson(); movie.People.Add(person); person.Name = text3.Trim(); person.URL = personURL; } person.IsActor = true; num4 = text2.ToLower().IndexOf(" ... ", num3); if (num4 > -1) { bool bCharacter = false; num5 = text2.ToLower().IndexOf("/character/", num4); if (num5 > -1) { if ((num5 - num4) < 50) { bCharacter = true; num3 = text2.IndexOf(">", num5); if (num3 > -1) { num3++; num4 = text2.IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } } } } if (bCharacter == false) { num3 = num4 + 10; num3 = text2.IndexOf(">", num3); if (num4 > -1) { num3++; num4 = text2.ToLower().IndexOf("<", num3); if (num4 > -1) { text3 = text2.Substring(num3, (num4 - num3)).Trim(); text3 = ToolBox.WebUtils.CleanUpHTML(text3, true).Trim(); text3 = ToolBox.WebUtils.FixString(text3).Trim(); person.AddRole(text3.Trim()); } else person.AddRole("Unknown"); } else person.AddRole("Unknown"); } } else person.AddRole("Unknown"); num1++; } } } } } } else { break; } } while (num2 > -1); } } #endregion #region Get Runtime //Get Runtime text2 = ""; num2 = text1.ToLower().IndexOf("runtime:"); if (num2 > -1) { num2 = text1.IndexOf(">", num2); if (num2 > -1) { num2++; num3 = text1.ToLower().IndexOf("<", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); text2 = FixRuntime(text2).Trim(); movie.Runtime = text2.Trim(); } } } #endregion #region Get Rating //Get Rating text2 = ""; num2 = text1.ToLower().IndexOf("certification:"); if (num2 > -1) { num2++; num2 = text1.ToLower().IndexOf(System.Web.HttpUtility.UrlEncode(_country).ToLower() + ":", num2); if (num2 > -1) { num2++; num2 = text1.ToLower().IndexOf(">", num2); if (num2 > -1) { num2 += _country.Length; num2 += 2; num3 = text1.ToLower().IndexOf("</a>", num2); if (num3 > -1) { text2 = text1.Substring(num2, (num3 - num2)).Trim(); text2 = ToolBox.WebUtils.CleanUpHTML(text2, true).Trim(); text2 = ToolBox.WebUtils.FixString(text2).Trim(); if (text2.Trim() == "" | text2.ToLower().Trim() == "not rated") { text2 = "Unrated"; } if (text2.ToLower().Trim() == "approved") { text2 = "G"; } movie.Rating = text2.Trim(); } } } } else { num2 = text1.ToLower().IndexOf("mpaa</a>:</h5>"); if (num2 > -1) { num2 = text1.ToLower().IndexOf("rated", num2); if (num2 > -1) { num2 += 5; num3 = text1.ToLower().IndexOf("for ", num2); if (num3 > -1) { movie.Rating = text1.Substring(num2, (num3 - num2)).Trim(); } } } } #endregion } return movie; } catch (Exception ex) { throw ex; } }
private void GetWriters(ref IMDbMovie movie, string html) { // Grab Writers string writerHTML = GetRegExString(html, _writerPattern); if (writerHTML.Trim() != "") { Match match = GetRegExMatch(writerHTML, _personPattern); while (match != null && match.Length > 0) { string personID = GetMatchValue(match, "PersonURL", true); if (personID.Trim() != "") { IIMDbPerson writer = movie.People.GetPersonByID(personID); if (writer == null) { writer = new IMDbPerson(); movie.People.Add(writer); } writer.URL = personID; writer.Name = GetMatchValue(match, "PersonName", true); writer.IsWriter = true; match = match.NextMatch(); } } } }
private void GetDirectors(ref IMDbMovie movie, string html) { // Grab Directors string directorHTML = GetRegExString(html, _directorPattern); if (directorHTML.Trim() != "") { Match match = GetRegExMatch(directorHTML, _personPattern); while (match != null && match.Length > 0) { string personID = GetMatchValue(match, "PersonURL", true); if (personID.Trim() != "") { IIMDbPerson director = movie.People.GetPersonByID(personID); if (director == null) { director = new IMDbPerson(); movie.People.Add(director); } director.URL = personID; director.Name = GetMatchValue(match, "PersonName", true); director.IsDirector = true; match = match.NextMatch(); } } } }
private void GetActors(ref IMDbMovie movie, string creditsURL) { // get cast html string html = ToolBox.WebUtils.GetSiteContents(creditsURL); //Old Code: JCUtils.WebUtils.GET(creditsURL); // Grab Actors string trimmedHTML = GetRegExString(html, _castPattern); if (trimmedHTML.Trim() != "") { Match match1 = GetRegExMatch(trimmedHTML, _castPersonPatternWithCharacterURLs); while (match1 != null && match1.Length > 0) { string personID = GetMatchValue(match1, "PersonURL", true); if (personID.Trim() != "") { IIMDbPerson actor = movie.People.GetPersonByID(personID); if (actor == null) { actor = new IMDbPerson(); movie.People.Add(actor); } actor.URL = personID; actor.Name = GetMatchValue(match1, "PersonName", true); actor.IsActor = true; string characterString = GetMatchValue(match1, "CharacterName", true); ParseCharacters(ref actor, characterString); match1 = match1.NextMatch(); } } Match match2 = GetRegExMatch(trimmedHTML, _castPersonPatternWithNOCharacterURLs); while (match2 != null && match2.Length > 0) { string personID = GetMatchValue(match2, "PersonURL", true); if (personID.Trim() != "") { IIMDbPerson actor = movie.People.GetPersonByID(personID); if (actor == null) { actor = new IMDbPerson(); movie.People.Add(actor); } actor.URL = personID; actor.Name = GetMatchValue(match2, "PersonName", true); actor.IsActor = true; string characterString = GetMatchValue(match2, "CharacterName", true); ParseCharacters(ref actor, characterString); match2 = match2.NextMatch(); } } } }