private void RefreshCurrent() { _currentInfo.Clear(); if (!_parent.IsConnected()) { return; } var infos = _parent.Command("GetCurrentlyPlaying"); if (infos == null) { return; } foreach (var info in infos) { var splitIndex = info.IndexOf(':') + 1; if (splitIndex <= 2) { continue; } var key = info.Substring(0, splitIndex - 1).Replace(" ", "").ToLower(CultureInfo.InvariantCulture); var value = info.Substring(splitIndex, info.Length - splitIndex); _currentInfo.Add(key, value); } if (GetInfo("thumb") != null) { var thumbparts = GetInfo("thumb").Split('/'); var hash = thumbparts[thumbparts.Length - 1].Trim().Replace(".tbn", ""); //var hash = ApiHelper.GetHashFromFileName(GetInfo("thumb"), "Xbmc HTTP"); _currentInfo.Add("fanart", GetInfo("thumb").Replace("/" + hash[0] + "/", "/Fanart/")); } }
public void PlayFiles(Collection <ApiAudioSong> songs) { if (songs == null) { return; } if (!_parent.IsConnected()) { return; } _parent.Command("ClearPlayList(0)"); _parent.Command("SetCurrentPlaylist(0)"); var pos = 0; foreach (var apiAudioSong in songs) { if (pos == 0) { _parent.Command("PlayFile(" + apiAudioSong.Path + apiAudioSong.FileName + ";0)"); pos++; } else { _parent.AsyncCommand("AddToPlayList", apiAudioSong.Path + apiAudioSong.FileName + ";0"); } } }
public byte[] Download(string fileName) { var fileExist = _parent.Command("FileExists", fileName); if (fileExist == null) { return(null); } if (fileExist[0] != "True") { return(null); } HttpWebRequest request; byte[] fileContent = null; var credentials = _parent.GetCredentials(); var uri = _parent.GetApiPath() + @"?command=FileDownload(" + fileName + @")"; try { request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.Timeout = DownloadTimeout; if (credentials != null) { request.Credentials = credentials; } using (var response = (HttpWebResponse)request.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { try { fileContent = Convert.FromBase64String( reader.ReadToEnd().Replace("<html>\n", "").Replace("\n</html>", "").Replace( "<html>", "") .Replace("</html>", "")); } catch (FormatException) { return(null); } } } _parent.Log("DOWNLOAD : " + fileName); } catch (WebException e) { _parent.Log("ERROR - DOWNLOAD : " + fileName + " - " + e.Message); } return(fileContent); }
public int GetVolume() { var ret = _parent.Command("GetVolume()"); return(ret == null ? 0 : Convert.ToInt32(ret[0], CultureInfo.InvariantCulture)); }