示例#1
0
        private void ParseXML(string stringDoc)
        {
            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(stringDoc);
            }
            catch
            {
                return;
            }

            List <string> list;

            APIhelper.TryParseXML(xmlDoc, "subsonic-response", "status", out list);

            if (list[0] != "ok")
            {
                return;
            }

            APIhelper.TryParseXML(xmlDoc, "directory", "parent", out _parentId);
            APIhelper.TryParseXML(xmlDoc, "directory", "name", out _dirName);
            APIhelper.TryParseXML(xmlDoc, "child", "title", out _title);
            APIhelper.TryParseXML(xmlDoc, "child", "id", out _id);
            APIhelper.TryParseXML(xmlDoc, "child", "track", out _track);
            APIhelper.TryParseXML(xmlDoc, "child", "artist", out _artist);
            APIhelper.TryParseXML(xmlDoc, "child", "isDir", out _isDir);
            APIhelper.TryParseXML(xmlDoc, "child", "albumId", out _albumId);
        }
示例#2
0
// ReSharper disable once InconsistentNaming
        private void GetXMLbody(string url)
        {
            var wc = new WebClient();

            wc.Headers[HttpRequestHeader.Authorization] = APIhelper.BuildBasicAuthString(Settings.UserName,
                                                                                         Settings.Password);

            _xmlBody = null;
            byte[] data;
            try
            {
                data = wc.DownloadData(url);
            }
            catch
            {
                return;
            }

            if (data != null)
            {
                Encoding enc = Encoding.GetEncoding("UTF-8");
                try
                {
                    _xmlBody = enc.GetString(data);
                }
                catch
                {
                }
            }
        }
示例#3
0
        private void ParseXML(string stringDoc)
        {
            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(stringDoc);
            }
            catch
            {
                return;
            }

            List <string> list;

            APIhelper.TryParseXML(xmlDoc, "subsonic-response", "status", out list);

            if (list[0] != "ok")
            {
                return;
            }

            APIhelper.TryParseXML(xmlDoc, "album", "title", out _albumTitle);
            APIhelper.TryParseXML(xmlDoc, "album", "id", out _albumId);
            APIhelper.TryParseXML(xmlDoc, "album", "track", out _albumTrack);
            APIhelper.TryParseXML(xmlDoc, "album", "artist", out _albumArtist);
            APIhelper.TryParseXML(xmlDoc, "album", "isDir", out _albumIsDir);

            APIhelper.TryParseXML(xmlDoc, "song", "title", out _songTitle);
            APIhelper.TryParseXML(xmlDoc, "song", "id", out _songId);
            APIhelper.TryParseXML(xmlDoc, "song", "track", out _songTrack);
            APIhelper.TryParseXML(xmlDoc, "song", "artist", out _songArtist);
            APIhelper.TryParseXML(xmlDoc, "song", "isDir", out _songIsDir);
        }
示例#4
0
        private void ParseXML(string stringDoc)
        {
            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(stringDoc);
            }
            catch
            {
                return;
            }

            List <string> list;

            APIhelper.TryParseXML(xmlDoc, "subsonic-response", "status", out list);

            if (list[0] != "ok")
            {
                return;
            }

            APIhelper.TryParseXML(xmlDoc, "album", "name", out _title);
            APIhelper.TryParseXML(xmlDoc, "album", "id", out _id);
            APIhelper.TryParseXML(xmlDoc, "album", "artist", out _artist);
            APIhelper.TryParseXML(xmlDoc, "album", "coverArt", out _coverArt);
        }
示例#5
0
// ReSharper disable once InconsistentNaming
        public void CheckServer(string url, bool ignoreSSLcertificateError, string userName, string password,
                                out bool result)
        {
            ServicePointManager.ServerCertificateValidationCallback =
                (sender, cert, chain, errors) => ignoreSSLcertificateError;

            url = url + "rest/ping.view?v=" + APIhelper.ApiVersion + "&c=" + APIhelper.AppName;

            result = false;

            WebRequest wr = WebRequest.Create(url);

            wr.Timeout = 5000;
            wr.Headers[HttpRequestHeader.Authorization] = APIhelper.BuildBasicAuthString(userName, password);

            string str = null;

            try
            {
                using (WebResponse rs = wr.GetResponse())
                    using (System.IO.Stream grs = rs.GetResponseStream())
                    {
                        if (grs != null)
                        {
                            var reader = new StreamReader(grs);
                            str = reader.ReadToEnd();
                        }
                    }
            }
            catch
            {
                return;
            }

            var doc = new XmlDocument();

            try
            {
                if (str != null)
                {
                    doc.LoadXml(str);
                }
            }
            catch
            {
                return;
            }

            List <string> statusList;

            APIhelper.TryParseXML(doc, "subsonic-response", "status", out statusList);

// ReSharper disable once UnusedVariable
            foreach (string status in statusList.Where(status => status == "ok"))
            {
                result = true;
            }
        }
示例#6
0
        private StreamInfoPack ParseXML(string stringDoc)
        {
            var gc     = new GetCoverArt();
            var sip    = new StreamInfoPack();
            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(stringDoc);
            }
            catch
            {
                sip.Status = "error";
                return(sip);
            }

            List <string> list;

            APIhelper.TryParseXML(xmlDoc, "subsonic-response", "status", out list);

            if (list[0] != "ok")
            {
                sip.Status = "error";
                return(sip);
            }
            sip.Status = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "id", out list);
            sip.Id = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "parent", out list);
            sip.Parent = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "title", out list);
            sip.Title = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "album", out list);
            sip.Album = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "artist", out list);
            sip.Artist = list[0];
            APIhelper.TryParseXML(xmlDoc, "song", "coverArt", out list);
            sip.CoverArt = gc.GetCoverArtImageUrl(list[0]);
            APIhelper.TryParseXML(xmlDoc, "song", "duration", out list);
            sip.Duration = list[0];

            return(sip);
        }
示例#7
0
        private void GetBitmap(string url)
        {
            var wc = new WebClient();

            wc.Headers[HttpRequestHeader.Authorization] = APIhelper.BuildBasicAuthString(Settings.UserName,
                                                                                         Settings.Password);

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    byte[] data = wc.DownloadData(url);
                    _ms = new MemoryStream(data);

                    break;
                }
                catch
                {
                }
            }
        }
示例#8
0
 public string GetCoverArtImageUrl(string songId)
 {
     return(APIhelper.Url + APIuri + "?v=" + APIhelper.ApiVersion + "&c=" + APIhelper.AppName + "&u=" +
            Settings.UserName + "&p=enc:" + APIhelper.GenerateHexEncodedPassword(Settings.Password) +
            "&size=500&id=" + songId);
 }