Exemplo n.º 1
0
 public ScraperResultsCache(string searchTerm, ScraperSearchParams searchParams)
 {
     this.searchTerm        = ScraperProvider.RemoveSpecialChars(searchTerm);
     this.searchParams      = searchParams;
     this.searchParams.Term = this.searchTerm; //update search term to matched title
     cachedResults          = new Dictionary <Scraper, ScraperResult>();
 }
Exemplo n.º 2
0
        public ScraperResult GetFirstMatch(ScraperSearchParams searchParams)
        {
            List <ScraperResult> results = getMatches(searchParams);

            if (results.Count > 0)
            {
                results.Sort();
                return(results[0]);
            }
            return(null);
        }
Exemplo n.º 3
0
        //execute scraper search using specified param's, return results
        List <ScraperResult> getMatches(ScraperSearchParams searchParams)
        {
            Dictionary <string, string> paramList = new Dictionary <string, string>();

            if (searchParams.Term != null)
            {
                paramList["search.title"] = searchParams.Term;
            }
            if (searchParams.Platform != null)
            {
                paramList["search.platform"] = searchParams.Platform;
            }
            if (searchParams.PlatformId != null)
            {
                paramList["search.platformid"] = searchParams.PlatformId;
            }

            List <ScraperResult>        results        = new List <ScraperResult>();
            Dictionary <string, string> scraperResults = scraper.Execute("search", paramList);

            if (scraperResults == null)
            {
                return(results);
            }

            int count = 0;

            //loop and build results
            while (scraperResults.ContainsKey("game[" + count + "].site_id"))
            {
                string siteId, title, yearmade, system, prefix = "game[" + count + "].";
                if (!scraperResults.TryGetValue(prefix + "site_id", out siteId))
                {
                    continue;
                }
                if (scraperResults.TryGetValue(prefix + "system", out system))
                {
                    system = system.Trim();
                }
                scraperResults.TryGetValue(prefix + "title", out title);
                scraperResults.TryGetValue(prefix + "yearmade", out yearmade);
                results.Add(new ScraperResult(siteId, title, system, yearmade, this)
                {
                    SearchParams   = searchParams,
                    SearchDistance = FuzzyStringComparer.Score(searchParams.Term, ScraperProvider.RemoveSpecialChars(title))
                });
                count++;
            }

            return(results);
        }
Exemplo n.º 4
0
        public List <ScraperResult> GetMatches(RomMatch romMatch, out ScraperResult bestResult, out bool approved)
        {
            bestResult = null;
            approved   = false;

            List <Scraper> lScrapers = new List <Scraper>(scrapers);

            //get parent title to try and match platform
            string searchPlatform = romMatch.Game.ParentEmulator.PlatformTitle;

            if (searchPlatform == "Unspecified")
            {
                searchPlatform = "";
            }

            ScraperSearchParams searchParams = new ScraperSearchParams()
            {
                Term     = RemoveSpecialChars(romMatch.Title),
                Platform = searchPlatform
            };

            List <ScraperResult> results = new List <ScraperResult>();

            foreach (Scraper scraper in lScrapers)
            {
                if (!doWork())
                {
                    return(null);
                }

                results.AddRange(scraper.GetMatches(searchParams));
            }

            searchPlatform = searchPlatform.ToLower();
            results        = sortResults(results, searchPlatform, out approved);
            if (results.Count > 0)
            {
                bestResult = results[0];
            }

            return(results);
        }
Exemplo n.º 5
0
 public virtual List <ScraperResult> GetMatches(ScraperSearchParams searchParams)
 {
     return(getMatches(searchParams));
 }