示例#1
0
文件: Bing.cs 项目: rsanch1/YANFOE.v2
        /// <summary>
        /// Searches Bing.com API
        /// </summary>
        /// <param name="query">The QueryString to search against</param>
        /// <param name="urlmatch">Only return URLs containing the following match</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <returns>First successful match.</returns>
        public static BindingList<QueryResult> SearchBing(string query, string urlmatch, int threadID, string regexTitle, string regexYear, string regexID, ScraperList scraperList)
        {
            var logCatagory = "Scrape > Bing Search > " + query;

            try
            {
                var queryResults = new BindingList<QueryResult>();

                query = query.Replace("%20", " ");

                using (var service = new BingService())
                {
                    var searchRequest = new SearchRequest
                                            {
                                                Query = query,
                                                Sources = new[] { SourceType.Web },
                                                AppId = "9A2F2F47CF77629DA4E35E912F4B696217DCFC3C"
                                            };

                    var webRequest = new WebRequest
                                         {
                                             Count = 10,
                                             Offset = 0,
                                             OffsetSpecified = true
                                         };
                    searchRequest.Web = webRequest;

                    var response = service.Search(searchRequest);

                    if (response.Web.Results != null)
                    {
                        foreach (var result in response.Web.Results)
                        {
                            if (string.IsNullOrEmpty(result.Url) || result.Url.Contains(urlmatch))
                            {
                                var queryResult = new QueryResult();

                                if (Regex.IsMatch(result.Title, regexTitle))
                                {
                                    if (Regex.IsMatch(result.Url, regexID))
                                    {
                                        switch (scraperList)
                                        {
                                            case ScraperList.Imdb:
                                                queryResult.ImdbID = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.TheMovieDB:
                                                queryResult.TmdbID = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.Allocine:
                                                queryResult.AllocineId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.FilmAffinity:
                                                queryResult.FilmAffinityId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.FilmDelta:
                                                queryResult.FilmDeltaId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.FilmUp:
                                                queryResult.FilmUpId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.FilmWeb:
                                                queryResult.FilmWebId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.Impawards:
                                                queryResult.ImpawardsId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.Kinopoisk:
                                                queryResult.KinopoiskId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.OFDB:
                                                queryResult.OfdbId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.MovieMeter:
                                                queryResult.MovieMeterId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                            case ScraperList.Sratim:
                                                queryResult.SratimId = Regex.Match(result.Url, regexID).Groups["id"].Value;
                                                break;
                                        }
                                    }

                                    queryResult.Title = Regex.Match(result.Title, regexTitle).Groups["title"].Value;
                                    queryResult.Year = Regex.Match(result.Title, regexYear).Groups["year"].Value.ToInt();
                                }
                                else
                                {
                                    queryResult.Title = result.Title;
                                }

                                queryResult.AdditionalInfo = result.Description;
                                queryResult.URL = result.Url;

                                queryResults.Add(queryResult);
                            }
                        }
                    }

                    Log.WriteToLog(LogSeverity.Info, 0, string.Format("Bing search complete ({0} results)", queryResults.Count), query);

                    return queryResults;
                }
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, LoggerName.GeneralLog, logCatagory, ex.Message);
                return null;
            }
        }
示例#2
0
 /// <summary>
 /// Updates the movie model.
 /// </summary>
 /// <param name="movieModel">The movie model.</param>
 /// <param name="result">The result to gather values from</param>
 private void UpdateMovieModel(MovieModel movieModel, QueryResult result)
 {
     movieModel.YanfoeID = result.YanfoeId;
     movieModel.Title = result.Title;
     movieModel.Year = result.Year;
     movieModel.ImdbId = result.ImdbID;
     movieModel.TmdbId = result.TmdbID;
     movieModel.SmallPoster = result.Poster;
 }
示例#3
0
文件: IMDB.cs 项目: rsanch1/YANFOE.v2
        /// <summary>
        /// Searches the sites search engine for movies.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>[true/false] if an error occurred.</returns>
        public new bool SearchSite(Query query, int threadID, string logCatagory)
        {
            try
            {
                var url = string.Format("http://www.imdb.com/find?s=tt&q={0} ({1})", query.Title, query.Year);

                var webPage = Downloader.ProcessDownload(url, DownloadType.Html, Section.Movies).RemoveCharacterReturn();

                webPage = webPage
                    .ReplaceWithStringEmpty(new[] { "<b>", "</b>" })
                    .RemoveExtraWhiteSpace()
                    .RemoveCharacterReturn();

                var matches = Regex.Matches(
                    webPage,
                    @"(rc=""(?<imageurl>http://ia.media-imdb.com/images/M/.{46}@@._V1._SY30_SX23_.jpg)?"" width=""23"" height=""32"".*?)?onclick="".{1,100}"">(?<title>.{1,100})</a> \((?<year>\d{4})\) </td></tr>");

                foreach (Match m in matches)
                {
                    var queryResult = new QueryResult
                                          {
                                              URL = string.Format("http://www.imdb.com/title/{0}/combined", m.Groups["id"].Value),
                                              PosterUrl = m.Groups["imageurl"].Value.Replace("SY30_SX23", "SY500_SX500"),
                                              ImdbID = m.Groups["id"].Value,
                                              Title = m.Groups["title"].Value,
                                              Year = m.Groups["year"].Value.ToInt()
                                          };

                    query.Results.Add(queryResult);
                }

                Log.WriteToLog(LogSeverity.Info, 0, string.Format("IMDB site search complete ({0} results)", query.Results.Count), query.Title);

                return query.Results.Count > 0;
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return false;
            }
        }
示例#4
0
        /// <summary>
        /// Searches Bing.com API
        /// </summary>
        /// <param name="query">The QueryString to search against</param>
        /// <param name="urlmatch">Only return URLs containing the following match</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <returns>First successful match.</returns>
        public static BindingList<QueryResult> SearchBing(string query, string urlmatch, int threadID)
        {
            var logCatagory = "Scrape > Bing Search > " + query;

            try
            {
                var queryResults = new BindingList<QueryResult>();

                query = query.Replace("%20", " ");

                using (var service = new LiveSearchService())
                {
                    var searchRequest = new SearchRequest
                                            {
                                                Query = query,
                                                Sources = new[] { SourceType.Web },
                                                AppId = "9A2F2F47CF77629DA4E35E912F4B696217DCFC3C"
                                            };

                    var webRequest = new WebRequest
                                         {
                                             Count = 10,
                                             Offset = 0,
                                             OffsetSpecified = true
                                         };
                    searchRequest.Web = webRequest;

                    var response = service.Search(searchRequest);

                    if (response.Web.Results != null)
                    {
                        foreach (var result in response.Web.Results)
                        {
                            if (string.IsNullOrEmpty(result.Url) || result.Url.Contains(urlmatch))
                            {
                                var queryResult = new QueryResult();

                                if (Regex.IsMatch(result.Title, @"(?<title>.*?)\s\((?<year>\d{4})"))
                                {
                                    if (Regex.IsMatch(result.Url, @"(?<imdbid>tt\d{7})"))
                                    {
                                        queryResult.ImdbID =
                                            Regex.Match(result.Url, @"(?<imdbid>tt\d{7})").Groups["imdbid"].Value;
                                    }

                                    queryResult.Title = Regex.Match(result.Title, @"(?<title>.*?)\s\((?<year>\d{4})").Groups["title"].Value;
                                    queryResult.Year = Regex.Match(result.Title, @"(?<title>.*?)\s\((?<year>\d{4})").Groups["year"].Value.ToInt();
                                }
                                else
                                {
                                    queryResult.Title = result.Title;
                                }

                                queryResult.AdditionalInfo = result.Description;
                                queryResult.URL = result.Url;

                                queryResults.Add(queryResult);
                            }
                        }
                    }

                    return queryResults;
                }
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, LoggerName.GeneralLog, logCatagory, ex.Message);
                return null;
            }
        }
示例#5
0
        /// <summary>
        /// Searches the sites search engine for movies.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>[true/false] if an error occurred.</returns>
        public new bool SearchSite(Query query, int threadID, string logCatagory)
        {
            try
            {
                var url = string.Format(
                    "http://www.filmdelta.se/search.php?string={0}&type=movie", query.Title.Replace(' ', '+'));

                var searchHtml =
                    Downloader.ProcessDownload(url, DownloadType.Html, Section.Movies).RemoveCharacterReturn();

                var matches = Regex.Matches(
                    searchHtml,
                    @"filmer/(?<id>.*?)/.*?"">(?<title>.*?)</a>.*?(?<year>\d{4})");

                foreach (Match m in matches)
                {
                    var queryResult = new QueryResult
                                          {
                                              Title = m.Groups["title"].Value,
                                              URL = string.Format("http://www.filmdelta.se/titles.php?movieId={0}", m.Groups["id"].Value),
                                              Year = m.Groups["title"].Value.ToInt()
                                          };

                    query.Results.Add(queryResult);
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return false;
            }
        }
示例#6
0
        /// <summary>
        /// Searches the sites search engine for movies.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="threadID">The thread MovieUniqueId.</param>
        /// <param name="logCatagory">The log catagory.</param>
        /// <returns>[true/false] if an error occurred.</returns>
        public new bool SearchSite(Query query, int threadID, string logCatagory)
        {
            try
            {
                string xml;

                if (!string.IsNullOrEmpty(query.ImdbId))
                {
                    xml =
                        Downloader.ProcessDownload(
                            string.Format(
                                "http://api.themoviedb.org/2.1/Movie.imdbLookup/en/xml/{0}/{1}",
                                Settings.ConstSettings.Application.TheMovieDBApi,
                                query.ImdbId),
                            DownloadType.Html,
                            Section.Movies);
                }
                else
                {
                    xml =
                        Downloader.ProcessDownload(
                            string.Format(
                                "http://api.themoviedb.org/2.1/Movie.search/en/xml/{0}/{1}",
                                Settings.ConstSettings.Application.TheMovieDBApi,
                                query.Title),
                            DownloadType.Html,
                            Section.Movies);
                }

                if (string.IsNullOrEmpty(xml))
                {
                    return false;
                }

                XDocument xmlDoc = XDocument.Parse(xml);

                var movies = from m in xmlDoc.Descendants("movie") select m;

                foreach (var movie in movies)
                {
                    var title = movie.Element("name").Value;
                    var releaseDate = movie.Element("released").Value;
                    var imdbID = movie.Element("imdb_id").Value;
                    var tmdbId = movie.Element("id").Value;
                    var additionalDetails = movie.Element("overview").Value;

                    XDocument xmlDocImages = XDocument.Parse(movie.ToString());

                    var images = (from i in xmlDocImages.Descendants("image")
                                  where 
                                    i.Attribute("type").Value == "poster" && 
                                    i.Attribute("size").Value == "cover"
                                  select i.Attribute("url").Value).ToList();

                    var queryResult = new QueryResult();
                    DateTime releaseParse;
                    var reseaseParseSuccess = DateTime.TryParse(releaseDate, out releaseParse);

                    queryResult.Title = title;

                    if (reseaseParseSuccess)
                    {
                        queryResult.Year = releaseParse.Year;
                        queryResult.ReleaseDate = releaseParse;
                    }

                    queryResult.AdditionalInfo = additionalDetails;
                    queryResult.ImdbID = imdbID.ToLower().Replace("tt", string.Empty);
                    queryResult.TmdbID = tmdbId;

                    if (images.Count > 0)
                    {
                        queryResult.PosterUrl = images[0];
                    }

                    query.Results.Add(queryResult);
                }

                return query.Results.Count > 0;
            }
            catch (Exception ex)
            {
                Log.WriteToLog(LogSeverity.Error, threadID, logCatagory, ex.Message);
                return false;
            }
        }