Пример #1
0
        public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string HumbleBundleId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false)
        {
            List <Wishlist> Result = new List <Wishlist>();

            List <Wishlist> ResultLoad = LoadWishlists("HumbleBundle", PluginUserDataPath);

            if (ResultLoad != null && !Force)
            {
                ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi);
                SaveWishlist("HumbleBundle", PluginUserDataPath, ResultLoad);
                return(ResultLoad);
            }

            if (CacheOnly)
            {
                return(Result);
            }

            if (HumbleBundleId.IsNullOrEmpty())
            {
                return(Result);
            }

            string ResultWeb = "";
            string url       = string.Format(@"https://www.humblebundle.com/store/wishlist/{0}", HumbleBundleId);

            try
            {
                ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8);

                if (ResultWeb != "")
                {
                    int startSub = ResultWeb.IndexOf("<script id=\"storefront-webpack-json-data\" type=\"application/json\">");
                    ResultWeb = ResultWeb.Substring(startSub, (ResultWeb.Length - startSub));

                    int endSub = ResultWeb.IndexOf("</script>");
                    ResultWeb = ResultWeb.Substring(0, endSub);

                    ResultWeb = ResultWeb.Replace("<script id=\"storefront-webpack-json-data\" type=\"application/json\">", "");

                    JObject dataObj = JObject.Parse(ResultWeb);

                    IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi();
                    foreach (JObject gameWish in dataObj["products_json"])
                    {
                        int      StoreId     = 0;
                        string   StoreUrl    = "https://www.humblebundle.com/store/" + gameWish["human_url"];
                        string   Name        = (string)gameWish["human_name"];
                        DateTime ReleaseDate = default(DateTime);
                        string   Capsule     = (string)gameWish["standard_carousel_image"];

                        Result.Add(new Wishlist
                        {
                            StoreId     = StoreId,
                            StoreName   = "Humble",
                            StoreUrl    = StoreUrl,
                            Name        = WebUtility.HtmlDecode(Name),
                            SourceId    = SourceId,
                            ReleaseDate = ReleaseDate.ToUniversalTime(),
                            Capsule     = Capsule,
                            Plain       = isThereAnyDealApi.GetPlain(Name)
                        });
                    }
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
                {
                    Common.LogError(ex, "IsThereAnyDeal", "Error in download HumbleBundle wishlist");
                    return(Result);
                }
            }

            Result = SetCurrentPrice(Result, settings, PlayniteApi);
            SaveWishlist("HumbleBundle", PluginUserDataPath, Result);
            return(Result);
        }
        public List <Wishlist> SetCurrentPrice(List <Wishlist> ListWishlist, IsThereAnyDealSettings settings, IPlayniteAPI PlayniteApi)
        {
            IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi();

            return(isThereAnyDealApi.GetCurrentPrice(ListWishlist, settings, PlayniteApi));
        }
        public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false)
        {
            List <Wishlist> Result = new List <Wishlist>();

            List <Wishlist> ResultLoad = LoadWishlists("Gog", PluginUserDataPath);

            if (ResultLoad != null && !Force)
            {
                ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi);
                SaveWishlist("Gog", PluginUserDataPath, ResultLoad);
                return(ResultLoad);
            }

            if (CacheOnly)
            {
                return(Result);
            }

            if (gogAPI != null && gogAPI.GetIsUserLoggedIn())
            {
                string ResultWeb = "";

                try
                {
                    // Get wishlist
                    ResultWeb = gogAPI.GetWishList();

                    // Get game information for wishlist
                    if (ResultWeb != "")
                    {
                        JObject resultObj = JObject.Parse(ResultWeb);
                        try
                        {
                            if (((JObject)resultObj["wishlist"]).Count > 0)
                            {
                                IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi();
                                foreach (var gameWishlist in (JObject)resultObj["wishlist"])
                                {
                                    if (((bool)gameWishlist.Value))
                                    {
                                        int StoreId = int.Parse(gameWishlist.Key);

                                        //Download game information
                                        string url = string.Format(@"https://api.gog.com/products/{0}", StoreId);
                                        ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8);
                                        try
                                        {
                                            JObject  resultObjGame = JObject.Parse(ResultWeb);
                                            DateTime ReleaseDate   = (DateTime)resultObjGame["release_date"];
                                            string   Name          = (string)resultObjGame["title"];
                                            string   Capsule       = "http:" + (string)resultObjGame["images"]["logo2x"];

                                            Result.Add(new Wishlist
                                            {
                                                StoreId     = StoreId,
                                                StoreName   = "GOG",
                                                StoreUrl    = (string)resultObjGame["links"]["product_card"],
                                                Name        = WebUtility.HtmlDecode(Name),
                                                SourceId    = SourceId,
                                                ReleaseDate = ReleaseDate.ToUniversalTime(),
                                                Capsule     = Capsule,
                                                Plain       = isThereAnyDealApi.GetPlain(Name)
                                            });
                                        }
                                        catch (Exception ex)
                                        {
                                            Common.LogError(ex, "IsThereAnyDeal", $"Failed to download game inforamtion for {StoreId}");
                                            return(Result);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "IsThereAnyDeal", $"Error io parse GOG wishlist");
                            return(Result);
                        }
                    }
                }
                catch (WebException ex)
                {
                    Common.LogError(ex, "IsThereAnyDeal", "Error in download GOG wishlist");
                    return(Result);
                }
            }

            Result = SetCurrentPrice(Result, settings, PlayniteApi);
            SaveWishlist("Gog", PluginUserDataPath, Result);
            return(Result);
        }
        public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false)
        {
            List <Wishlist> Result = new List <Wishlist>();

            List <Wishlist> ResultLoad = LoadWishlists("Epic", PluginUserDataPath);

            if (ResultLoad != null && !Force)
            {
                ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi);
                SaveWishlist("Epic", PluginUserDataPath, ResultLoad);
                return(ResultLoad);
            }

            if (CacheOnly)
            {
                return(Result);
            }

            // Get Epic configuration if exist.
            string access_token = "";

            try
            {
                JObject EpicConfig = JObject.Parse(File.ReadAllText(PluginUserDataPath + "\\..\\00000002-DBD1-46C6-B5D0-B1BA559D10E4\\tokens.json"));
                access_token = (string)EpicConfig["access_token"];
            }
            catch
            {
            }

            if (access_token.IsNullOrEmpty())
            {
                logger.Error($"ISThereAnyDeal - No Epic configuration.");
                return(Result);
            }

            // Get wishlist
            string ResultWeb = "";

            ResultWeb = QuerySearchWishList(access_token).GetAwaiter().GetResult();

            if (ResultWeb != "")
            {
                JObject resultObj = new JObject();

                logger.Debug(ResultWeb);

                try
                {
                    resultObj = JObject.Parse(ResultWeb);

                    if (resultObj["data"]["Wishlist"]["wishlistItems"]["elements"] != null)
                    {
                        IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi();
                        foreach (JObject gameWishlist in resultObj["data"]["Wishlist"]["wishlistItems"]["elements"])
                        {
                            int      StoreId     = 0;
                            string   Name        = "";
                            DateTime ReleaseDate = default(DateTime);
                            string   Capsule     = "";

                            Name = (string)gameWishlist["offer"]["title"];
                            foreach (var keyImages in gameWishlist["offer"]["keyImages"])
                            {
                                if ((string)keyImages["type"] == "Thumbnail")
                                {
                                    Capsule = (string)keyImages["url"];
                                }
                            }

                            Result.Add(new Wishlist
                            {
                                StoreId     = StoreId,
                                StoreName   = "Epic",
                                StoreUrl    = "",
                                Name        = WebUtility.HtmlDecode(Name),
                                SourceId    = SourceId,
                                ReleaseDate = ReleaseDate.ToUniversalTime(),
                                Capsule     = Capsule,
                                Plain       = isThereAnyDealApi.GetPlain(Name)
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "IsThereAnyDeal", "Error io parse Epic wishlist");
                    return(Result);
                }
            }

            Result = SetCurrentPrice(Result, settings, PlayniteApi);
            SaveWishlist("Epic", PluginUserDataPath, Result);
            return(Result);
        }
Пример #5
0
        public List <Wishlist> GetWishlist(IPlayniteAPI PlayniteApi, Guid SourceId, string PluginUserDataPath, IsThereAnyDealSettings settings, bool CacheOnly = false, bool Force = false)
        {
            List <Wishlist> Result = new List <Wishlist>();

            List <Wishlist> ResultLoad = LoadWishlists("Steam", PluginUserDataPath);

            if (ResultLoad != null && !Force)
            {
                ResultLoad = SetCurrentPrice(ResultLoad, settings, PlayniteApi);
                SaveWishlist("Steam", PluginUserDataPath, ResultLoad);
                return(ResultLoad);
            }

            if (CacheOnly)
            {
                return(Result);
            }

            // Get Steam configuration if exist.
            string userId = "";
            string apiKey = "";

            try
            {
                JObject SteamConfig = JObject.Parse(File.ReadAllText(PluginUserDataPath + "\\..\\CB91DFC9-B977-43BF-8E70-55F46E410FAB\\config.json"));
                userId = (string)SteamConfig["UserId"];
                apiKey = (string)SteamConfig["ApiKey"];
            }
            catch
            {
            }

            if (userId.IsNullOrEmpty() || apiKey.IsNullOrEmpty())
            {
                logger.Error($"ISThereAnyDeal - No Steam configuration.");
                return(Result);
            }


            string ResultWeb = "";
            string url       = string.Format(@"https://store.steampowered.com/wishlist/profiles/{0}/wishlistdata/", userId);

            ResultWeb = "";
            try
            {
                ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null)
                {
                    Common.LogError(ex, "IsThereAnyDeal", "Error in download Steam wishlist");
                    return(Result);
                }
            }

            if (ResultWeb != "")
            {
                JObject resultObj   = new JObject();
                JArray  resultItems = new JArray();

                try
                {
                    resultObj = JObject.Parse(ResultWeb);

                    IsThereAnyDealApi isThereAnyDealApi = new IsThereAnyDealApi();
                    foreach (var gameWishlist in resultObj)
                    {
                        JObject gameWishlistData = (JObject)gameWishlist.Value;

                        int      StoreId     = int.Parse(gameWishlist.Key);
                        string   Name        = (string)gameWishlistData["name"];
                        DateTime ReleaseDate = ((int)gameWishlistData["release_date"] == 0) ? default(DateTime) : new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds((int)gameWishlistData["release_date"]);
                        string   Capsule     = (string)gameWishlistData["capsule"];

                        Result.Add(new Wishlist
                        {
                            StoreId     = StoreId,
                            StoreName   = "Steam",
                            StoreUrl    = "https://store.steampowered.com/app/" + StoreId,
                            Name        = WebUtility.HtmlDecode(Name),
                            SourceId    = SourceId,
                            ReleaseDate = ReleaseDate.ToUniversalTime(),
                            Capsule     = Capsule,
                            Plain       = isThereAnyDealApi.GetPlain(Name)
                        });
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "IsThereAnyDeal", "Error io parse Steam wishlist");
                    return(Result);
                }
            }

            Result = SetCurrentPrice(Result, settings, PlayniteApi);
            SaveWishlist("Steam", PluginUserDataPath, Result);
            return(Result);
        }