Пример #1
0
        internal string Query(string request, bool oauth, bool cfid, int wait)
        {
            string parameters = "?&ref=&cors=&_=" + GetTimestamp();

            if (request.Contains("?"))
            {
                parameters = parameters.Substring(1);
            }

            if (oauth)
            {
                parameters += "&oauth=" + OauthKey;
            }
            if (cfid)
            {
                parameters += "&csrf=" + CfidKey;
            }

            if (wait != -1)
            {
                parameters += "&returnafter=" + wait;
                parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
            }

            string address  = $"{_config.HostUrl}:{_config.Port}/{request}{parameters}";
            string response = "";

            try
            {
                using (var wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                    {
                        response = "[ " + wc.DownloadString(address) + " ]";
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(response);
        }
Пример #2
0
        internal string Query(string baseUrl, bool oauth, bool cfid, int wait, NameValueCollection @params = null)
        {
            string parameters = BuildQueryString(oauth, cfid, wait, @params);
            string address    = $"{_config.HostUrl}:{_config.Port}/{baseUrl}?{parameters}";
            string response   = string.Empty;

            try
            {
                using (ExtendedWebClient wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                    {
                        response = "[ " + wc.DownloadString(address) + " ]";
                    }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(response);
        }
Пример #3
0
        internal string Query(string request, bool oauth, bool cfid, int wait)
        {
            string parameters = "?&ref=&cors=&_=" + GetTimestamp();
            if (request.Contains("?"))
            {
                parameters = parameters.Substring(1);
            }

            if (oauth)
            {
                parameters += "&oauth=" + OauthKey;
            }
            if (cfid)
            {
                parameters += "&csrf=" + CfidKey;
            }

            if (wait != -1)
            {
                parameters += "&returnafter=" + wait;
                parameters += "&returnon=login%2Clogout%2Cplay%2Cpause%2Cerror%2Cap";
            }

            string address = "http://" + Host + ":4380/" + request + parameters;
            string response = "";
            try
            {
                using (var wc = new ExtendedWebClient())
                {
                    if (SpotifyLocalAPI.IsSpotifyRunning())
                        response = "[ " + wc.DownloadString(address) + " ]";
                }
            }
            catch
            {
                return String.Empty;
            }

            return response;
        }