public GameInfoModel GetDataFromApi(string title) { var qStrKey = "?api_key=" + ApiKey; var qStrTitle = "&title=" + title.Replace(" ", "+"); var qStrLimit = "&limit=1"; var qStrPlatform = "&platform=7"; // id 7 is PS2 var parsed = ScrapeArt.WebClient <MobyGamesJson.GamesEndpoint>(BaseUrl, // http://www.mobygames.com/info/api p => p.DownloadString("games" + qStrKey + qStrTitle + qStrLimit + qStrPlatform) ); var first = parsed.Games.FirstOrDefault(); if (first == null) { return(null); } return(new GameInfoModel { Id = (int)first.GameId, Title = first.Title, OriginalUrl = first.MobyUrl, ScrapeSource = ScrapeSource.MobyGames, ThumbnailUrl = first.SampleCover?.Image, }); }
public GameInfoModel GetDataFromApi(string filename) { var platform = "?platformID[]=11"; var name = "&name=" + filename.Replace(" ", "+"); var response = ScrapeArt.WebClient(BaseUrl, p => p.DownloadString("search.php" + platform + name) ); var html = CQ.CreateDocument(response); if (html["div#display"].Children().Any() == false) { return(null); } var sanitizedSearchFilename = SanitizeSeach(filename); var resultRoot = html["div#display div > a[href]"]; var results = IterateResults(resultRoot).ToArray(); // result is in the wrong order, so i attempt to find the most relevant of the results var orderedByRelevance = ( from item in results let sanitizedSerachTitle = SanitizeSeach(item.Title) let levenshteinDistance = LevenshteinDistance.Compute(sanitizedSearchFilename, sanitizedSerachTitle) let lengthDifference = sanitizedSearchFilename.Length - sanitizedSerachTitle.Length orderby lengthDifference orderby levenshteinDistance select item ).ToArray(); return(orderedByRelevance.FirstOrDefault()); }
private void scrapingWorker_DoWork(object sender, EventArgs e) { ScrapeArt scraper = new ScrapeArt(title); this.Invoke(new Action(() => RefreshBox())); this.Invoke(new Action(() => FadeButton())); this.Invoke(new Action(() => FadeText())); this.Invoke(new Action(() => FadeGrid())); this.Invoke(new Action(() => ProgressBar.Visibility = Visibility.Collapsed)); }
public GameInfoModel GetDataFromApi(string title) { // https://igdb.github.io/api/references/filters/#text-search var search = "?search=" + title.Replace(" ", "+"); //https://igdb.github.io/api/references/fields/ var fields = "&fields=id,name,cover,url,platforms"; // https://igdb.github.io/api/references/filters/ var filter = "&filter[platforms][in]=8"; // id 8 == ps2 // https://igdb.github.io/api/references/pagination/ var limit = "&limit=1"; var parsed = ScrapeArt.WebClient <IGDB.IGDBGame[]>(BaseUrl, p => { // https://igdb.github.io/api/examples/ p.Headers["user-key"] = ApiKey; p.Headers["Accept"] = "application/json"; return(p.DownloadString("games/" + search + fields + filter + limit)); }); var first = parsed.FirstOrDefault(); if (first == null) { return(null); } //https://igdb.github.io/api/references/images/ const string sizeString = "cover_big"; var thumbnail = "https://" + "images.igdb.com/igdb/image/upload/t_" + sizeString + "/" + first.Cover.CloudinaryId + ".jpg"; return(new GameInfoModel { Id = first.Id, Title = first.Name, OriginalUrl = first.Url, ScrapeSource = ScrapeSource.IGDB, ThumbnailUrl = thumbnail }); }