override public void getMovieData(ref Movie movie) { String data = loadMovieData(ref movie); if (data == null) { return; } String pat = "<a href=\"/title/tt([0-9]*)/\">([^<]*)</a>[^<]+<span class=\"year_type\">([^<]+)</span>"; Regex reg = new Regex(pat); MatchCollection mcol = null; mcol = reg.Matches(data); List <movieData> movieNames = new List <movieData>(); if (mcol.Count > 0) { foreach (Match m in mcol) { movieNames.Add(parseMovie(m.Groups[2].Captures[0].Value, m.Groups[3].Captures[0].Value)); } } movieData selectedMovie = this.chooseMovie(movie, movieNames); setMovieTitle(ref movie, selectedMovie); }
internal movieData chooseMovie(Movie m, List<movieData> movies) { movieData md = new movieData(); md.Name = m.title; md.Year = m.year; if (movies.Count == 0) return md; if (movies.Count == 1) return movies[0]; foreach (movieData movie in movies) { if (m.compareTitles(movie)) return movie; } SelectMovie movieDlg = new SelectMovie(); movieDlg.Text = String.Format("Select movie for {0} ({1})", m.title, m.year); movieDlg.setMovieData(m); foreach (movieData movie in movies) { movieDlg.addMovie(movie); } if (movieDlg.ShowDialog() == DialogResult.OK) { md = movieDlg.selectedMovie; } movieDlg.Dispose(); return md; }
public bool compareTitles(movieData founddata) { String fTitle = founddata.Name; String oTitle = _title; if (_year > 0) { oTitle += " (" + _year.ToString() + ")"; } if (founddata.Year > 0) { fTitle += " (" + founddata.Year.ToString() + ")"; } foreach (Char c in badPathChars) { fTitle = fTitle.Replace(c.ToString(), " "); oTitle = oTitle.Replace(c.ToString(), " "); } fTitle = fTitle.Replace('.', ' '); oTitle = oTitle.Replace('.', ' '); while (fTitle.IndexOf(" ") != -1) { fTitle = fTitle.Replace(" ", " "); } while (oTitle.IndexOf(" ") != -1) { oTitle = oTitle.Replace(" ", " "); } oTitle.Trim(); fTitle.Trim(); return(oTitle.Equals(fTitle)); }
override public void getMovieData(ref Movie movie) { movieCache = String.Format(baseCache, MD5.createHash(movie.title), movie.year); WebClient cli = new WebClient(); if (!File.Exists(movieCache)) { cli.DownloadFile(String.Format(searchUrl, movie.title), movieCache); } if (File.Exists(movieCache)) { XmlDocument xml = new XmlDocument(); List <movieData> movies = new List <movieData>(); DateTime dt = File.GetLastWriteTime(movieCache); if (DateTime.Now.Subtract(dt).TotalDays > 3) { // Log.Add( i18n.t( "oparse_older", ep.series) ); File.Delete(movieCache); cli.DownloadFile(String.Format(searchUrl, movie.title), movieCache); } xml.Load(movieCache); XmlNodeList nodes = xml.GetElementsByTagName("movie"); foreach (XmlNode node in nodes) { Int32 year = 0; XmlNode release = node.SelectSingleNode("release"); if (release != null && release.InnerText.Length > 0) { year = Int32.Parse(release.InnerText.Substring(0, 4)); } else { year = movie.year; } movieData md = null; md = new movieData(); md.Year = year; md.Name = node.SelectSingleNode("title").InnerText; movies.Add(md); if (node.SelectSingleNode("alternative_title").InnerText != string.Empty) { md = new movieData(); md.Year = year; md.Name = node.SelectSingleNode("alternative_title").InnerText; movies.Add(md); } } movieData selectedMovie = this.chooseMovie(movie, movies); setMovieTitle(ref movie, selectedMovie); } }
private movieData parseMovie(String movieName, String year) { movieData md = new movieData(); md.Name = movieName; String pat = @"([0-9]{4})"; Regex reg = new Regex(pat); Match m = null; m = reg.Match(year); if (m.Success) { md.Year = Int32.Parse(m.Groups[0].Captures[0].Value); } return md; }
public override void getMovieData(ref Movie movie) { movieCache = String.Format(baseCache, MD5.createHash(movie.title), movie.year); WebClient cli = new WebClient(); if (!File.Exists(movieCache)) { cli.DownloadFile(String.Format(searchUrl, movie.title), movieCache); } if (File.Exists(movieCache)) { XmlDocument xml = new XmlDocument(); List<movieData> movies = new List<movieData>(); DateTime dt = File.GetLastWriteTime(movieCache); if (DateTime.Now.Subtract(dt).TotalDays > 3) { // Log.Add( i18n.t( "oparse_older", ep.series) ); File.Delete(movieCache); cli.DownloadFile(String.Format(searchUrl, movie.title), movieCache); } xml.Load(movieCache); XmlNodeList nodes = xml.GetElementsByTagName("movie"); foreach (XmlNode node in nodes) { Int32 year = 0; XmlNode release = node.SelectSingleNode("release"); if (release != null && release.InnerText.Length > 0) { year = Int32.Parse(release.InnerText.Substring(0, 4)); } else { year = movie.year; } movieData md = null; md = new movieData(); md.Year = year; md.Name = node.SelectSingleNode("title").InnerText; movies.Add(md); if (node.SelectSingleNode("alternative_title").InnerText != string.Empty) { md = new movieData(); md.Year = year; md.Name = node.SelectSingleNode("alternative_title").InnerText; movies.Add(md); } } movieData selectedMovie = this.chooseMovie(movie, movies); setMovieTitle(ref movie, selectedMovie); } }
private movieData parseMovie(String movieName, String year) { movieData md = new movieData(); md.Name = movieName; String pat = @"([0-9]{4})"; Regex reg = new Regex(pat); Match m = null; m = reg.Match(year); if (m.Success) { md.Year = Int32.Parse(m.Groups[0].Captures[0].Value); } return(md); }
internal movieData chooseMovie(Movie m, List <movieData> movies) { movieData md = new movieData(); md.Name = m.title; md.Year = m.year; if (movies.Count == 0) { return(md); } if (movies.Count == 1) { return(movies[0]); } foreach (movieData movie in movies) { if (m.compareTitles(movie)) { return(movie); } } SelectMovie movieDlg = new SelectMovie(); movieDlg.Text = String.Format("Select movie for {0} ({1})", m.title, m.year); movieDlg.setMovieData(m); foreach (movieData movie in movies) { movieDlg.addMovie(movie); } if (movieDlg.ShowDialog() == DialogResult.OK) { md = movieDlg.selectedMovie; } movieDlg.Dispose(); return(md); }
private void showList_SelectedIndexChanged(object sender, System.EventArgs e) { selectedMovie = movieList.SelectedItem as movieData; }
public void addMovie(movieData movie) { movieList.Items.Add(movie); }
internal void setMovieTitle(ref Movie movie, movieData movieData) { movie.title = movieData.Name; movie.year = movieData.Year; }
public bool compareTitles(movieData founddata) { String fTitle = founddata.Name; String oTitle = _title; if (_year > 0) { oTitle += " (" + _year.ToString() + ")"; } if (founddata.Year > 0) { fTitle += " (" + founddata.Year.ToString() + ")"; } foreach (Char c in badPathChars) { fTitle = fTitle.Replace(c.ToString(), " "); oTitle = oTitle.Replace(c.ToString(), " "); } fTitle = fTitle.Replace('.', ' '); oTitle = oTitle.Replace('.', ' '); while (fTitle.IndexOf(" ") != -1) fTitle = fTitle.Replace(" ", " "); while (oTitle.IndexOf(" ") != -1) oTitle = oTitle.Replace(" ", " "); oTitle.Trim(); fTitle.Trim(); return oTitle.Equals(fTitle); }