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>();
 }
Beispiel #2
0
 public virtual ScraperResult GetFirstMatch(ScraperSearchParams searchParams)
 {
     List<ScraperResult> results = GetMatches(searchParams);
     if (results != null && results.Count > 0)
     {
         results.Sort();
         return results[0];
     }
     return null;
 }
        public List<ScraperResult> GetMatches(RomMatch romMatch, out ScraperResult bestResult, out bool approved)
        {
            bestResult = null;
            approved = false;
            List<Scraper> lScrapers;

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

            //get parent title to try and match platform
            string searchPlatform = romMatch.Game.ParentEmulator.Platform;
            if (searchPlatform == "Unspecified")
                searchPlatform = "";

            string searchTerm = RemoveSpecialChars(romMatch.SearchTitle);
            string filename = romMatch.IsDefaultSearchTerm ? romMatch.Filename : null;
            ScraperSearchParams searchParams = new ScraperSearchParams()
            {
                Term = searchTerm,
                Platform = searchPlatform,
                Filename = filename
            };

            List<ScraperResult> results = new List<ScraperResult>();
            int priority = 0;
            foreach (Scraper scraper in lScrapers)
            {
                if (!doWork())
                    return null;
                foreach (ScraperResult result in scraper.GetMatches(searchParams))
                {
                    result.Priority = priority;
                    results.Add(result);
                }
                priority++;
            }

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

            return results;
        }
        public override 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;
            if (searchParams.Filename != null)
                paramList["search.filename"] = searchParams.Filename;

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

            int count = 0; 
            string siteId;
            //loop and build results
            while (scraperResults.TryGetValue("game[" + count + "].site_id", out siteId))
            {
                string prefix = "game[" + count + "].";

                string system;
                if (scraperResults.TryGetValue(prefix + "system", out system))
                    system = cleanString(system);

                string title;
                if (scraperResults.TryGetValue(prefix + "title", out title))
                    title = cleanString(title);

                string year;
                if (scraperResults.TryGetValue(prefix + "yearmade", out year))
                    year = cleanString(year);

                string scoreStr;
                int score;
                if (!scraperResults.TryGetValue(prefix + "score", out scoreStr) || !int.TryParse(scoreStr, out score))
                    score = FuzzyStringComparer.Score(searchParams.Term, ScraperProvider.RemoveSpecialChars(title));

                results.Add(new ScraperResult(siteId, title, system, year, this, searchParams) { SearchDistance = score });
                count++;
            }

            return results;
        }
Beispiel #5
0
 public virtual List<ScraperResult> GetMatches(ScraperSearchParams searchParams)
 {
     return new List<ScraperResult>();
 }
        public override List<ScraperResult> GetMatches(ScraperSearchParams searchParams)
        {
            if (!string.IsNullOrEmpty(searchParams.Platform) && searchParams.Platform != "Arcade")
                return base.GetMatches(searchParams);

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

            if (searchParams.Filename != null)
            {
                MameInfo fileMatch;
                if (filenameLookup.TryGetValue(searchParams.Filename, out fileMatch))
                    results.Add(createResult(fileMatch, searchParams));
            }

            List<MameInfo> titleMatches;
            if (titleLookup.TryGetValue(searchParams.Term, out titleMatches))
                foreach (MameInfo titleMatch in titleMatches)
                    results.Add(createResult(titleMatch, searchParams));

            return results;
        }
 ScraperResult createResult(MameInfo mameInfo, ScraperSearchParams searchParams)
 {
     return new ScraperResult(mameInfo.Filename, mameInfo.Title, "Arcade", mameInfo.Year, this, searchParams);
 }