コード例 #1
0
        private SteamApp GetSteamApp(string steamAppId, string[] steamAppTypes = null)
        {
            // rate limiter, 200 requests/5 min
            System.Threading.Thread.Sleep(5000);

            var steamDbUrl = $"http://store.steampowered.com/api/appdetails?appids={ steamAppId }";

            var response = WebUtils.SilentWebRequest(steamDbUrl);

            dynamic deserializedResponse = JsonConvert.DeserializeObject(response);

            if (deserializedResponse == null || deserializedResponse[steamAppId].success == false)
            {
                return(null);
            }

            string appType = deserializedResponse[steamAppId].data.type.ToString();

            if (steamAppTypes != null && !steamAppTypes.Contains(appType))
            {
                return(null);
            }

            return(SteamApp.Create(
                       steamAppId,
                       appType,
                       deserializedResponse[steamAppId].data.name.ToString()
                       ));
        }
コード例 #2
0
        /// <summary>
        /// query https://steamdb.info/search/?q=... for new SteamAppId-s
        /// also adds result to cache
        /// </summary>
        /// <param name="gameTitle"></param>
        /// <returns></returns>
        private SteamApp[] QuerySteamDb(string gameTitle)
        {
            var result = new List <SteamApp>();

            var url      = $"https://steamdb.info/search/?q={ WebUtility.UrlEncode(gameTitle) }";
            var response = WebUtils.WebRequest(url);

            if (response == null)
            {
                return(result.ToArray());
            }

            var tableElementStart = response.IndexOf("<tbody hidden>");

            if (tableElementStart < 0)
            {
                return(result.ToArray());
            }

            var tableBodyElement = response.Substring(tableElementStart, response.IndexOf("</tbody>", tableElementStart) - tableElementStart + "</tbody>".Length);

            tableBodyElement = tableBodyElement.Replace("<tbody hidden>", "<tbody>");

            var decodedAndCleaned = WebUtility.HtmlDecode(tableBodyElement).Replace("&", string.Empty);

            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(decodedAndCleaned);

            foreach (XmlNode steamAppNode in xmlDocument.DocumentElement.ChildNodes)
            {
                var type = steamAppNode.ChildNodes[1].InnerText.ToLower();

                if (!ValidTypes.Contains(type))
                {
                    continue;
                }

                var steamAppId = steamAppNode.Attributes["data-appid"].Value;

                var title = steamAppNode.ChildNodes[2].InnerText;

                // remove muted part of title
                title = Strings.RemoveFromTo(title, "<i class=\"muted\">", "</i>").Trim();
                title = title.Trim('\n');

                result.Add(SteamApp.Create(steamAppId, type, title));
            }

            // add new steam apps to cache
            foreach (var newSteamApp in result)
            {
                AddOrUpdateSteamApp(newSteamApp);
            }

            return(result.ToArray());
        }