public void AddSong(Song sg) { if (sg == null) //todo log { Console.Out.WriteLine("!!!WARN!!!! Unable to load song. not adding to playlist"); return; } _Songs.Add(sg); }
/// <summary> /// Returns details for a song. /// </summary> /// <param name="id" required="yes">The song ID.</param> /// <returns>a song</returns> public async Task<Song> getSong(string id) { Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("id", id); Stream theStream = await this.MakeGenericRequest("getSong", parameters); StreamReader sr = new StreamReader(theStream); string result = sr.ReadToEnd(); result = result.Replace(responseHead, "").Replace(responseFoot, ""); XElement nm = XElement.Parse(result); Song sng =new Song(); sng.Id = (string)nm.Attribute("id"); sng.Name = (string)nm.Attribute("title"); sng.Album = (string)nm.Attribute("album"); sng.Artist = (string)nm.Attribute("artist"); sng.Parent = (string)nm.Attribute("parent"); sng.CoverArt = (string)nm.Attribute("coverArt"); sng.Created = (string)nm.Attribute("created"); sng.Duration = (string)nm.Attribute("duration"); sng.BitRate = (string)nm.Attribute("bitRate"); sng.Track = (string)nm.Attribute("track"); sng.Year = (string)nm.Attribute("year"); sng.Genre = (string)nm.Attribute("genre"); sng.Size = (string)nm.Attribute("size"); sng.Suffix = (string)nm.Attribute("suffix"); sng.ContentType = (string)nm.Attribute("contentType"); sng.AlbumId = (string)nm.Attribute("albumId"); sng.ArtistId = (string)nm.Attribute("artistId"); return sng; }
public void AddSong(Song newSong) { _Songs.Add(newSong); }
public static Song GetSong(string id) { Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("id", id); // Make the request Stream theStream = MakeGenericRequest("getSong", parameters); Song s = null; using (StreamReader sr = new StreamReader(theStream)) { string result = sr.ReadToEnd(); // Parse the resulting XML string into an XmlDocument XmlDocument myXML = new XmlDocument(); myXML.LoadXml(result); if (myXML.ChildNodes[1].Name == "subsonic-response") { if (myXML.ChildNodes[1].FirstChild.Name == "song") { s = new Song( myXML.ChildNodes[1].FirstChild.Attributes["title"].Value, myXML.ChildNodes[1].FirstChild.Attributes["id"].Value, myXML.ChildNodes[1].FirstChild.Attributes["artist"].Value, myXML.ChildNodes[1].FirstChild.Attributes["album"].Value, myXML.ChildNodes[1].FirstChild.Attributes["suffix"].Value ); } } } return s; }
/// <summary> /// Returns what is currently being played by all users. Takes no extra parameters. /// </summary> public static Dictionary<string, Song> GetNowPlaying() { #region example data //EXAMPLE DATA // <? xml version = "1.0" encoding = "UTF-8" ?>\n < subsonic - response xmlns = "http://subsonic.org/restapi" status = "ok" version = "1.12.0" > // < nowPlaying > // < entry id = "58160" // parent = "57870" // isDir = "false" // title = "As Far As I Remember" // album = "The Connection" // artist = "Papa Roach" // track = "13" // year = "2012" // genre = "Rock" // coverArt = "57870" // size = "8910048" // contentType = "audio/mpeg" suffix = "mp3" // duration = "222" // bitRate = "320" // path = "Papa Roach/Papa Roach - The Connection/13. As Far As I Remember.mp3" // isVideo = "false" // created = "2015-06-11T12:13:24.000Z" // albumId = "4023" // artistId = "622" // type = "music" // username = "******" // minutesAgo = "2" // playerId = "7" /> // </ nowPlaying > //</ subsonic - response >\n" #endregion Dictionary<string, Song> nowPlaying = new Dictionary<string, Song>(); Dictionary<string, string> theParameters = new Dictionary<string, string>(); Stream theStream = MakeGenericRequest("getNowPlaying", theParameters); StreamReader sr = new StreamReader(theStream); string result = sr.ReadToEnd(); XmlDocument nowPlayingXML = new XmlDocument(); nowPlayingXML.LoadXml(result); if (nowPlayingXML.ChildNodes[1].Name == "subsonic-response") { if (nowPlayingXML.ChildNodes[1].FirstChild.Name == "nowPlaying") { foreach (XmlNode childnode in nowPlayingXML.ChildNodes[1].FirstChild) { string user = childnode.Attributes["username"].Value; Song sg = new Song( childnode.Attributes["artist"].Value, childnode.Attributes["album"].Value, childnode.Attributes["title"].Value, childnode.Attributes["id"].Value, childnode.Attributes["suffix"].Value ); nowPlaying.Add(user + childnode.Attributes["playerId"].Value, sg); } } } return nowPlaying; }
public void AddSong(string title, string id) { Song newSong = new Song(title, id); _Songs.Add(newSong); }
public void AddSong(Song song) { if (song == null) return; //do not accept null. PlayQueue.Enqueue(song); }
/// <summary> /// Performs a search valid for the current version of the subsonic server /// If version is >= 1.4.0 search2 /// Else search /// </summary> /// <param name="query">The Term you want to search for</param> /// <returns>A List of SubsonicItem objects</returns> public static List<SubsonicItem> Search(string query) { Dictionary<string, string> parameters = new Dictionary<string, string>(); Version apiV = new Version(apiVersion); Version Search2Min = new Version("1.4.0"); string request = ""; // Use search for the server version if (apiV >= Search2Min) { request = "search2"; parameters.Add("query", query); } else { request = "search"; parameters.Add("any", query); } // Make the request Stream theStream = MakeGenericRequest(request, parameters); // Read the response as a string StreamReader sr = new StreamReader(theStream); string result = sr.ReadToEnd(); // Parse the resulting XML string into an XmlDocument XmlDocument myXML = new XmlDocument(); myXML.LoadXml(result); List<SubsonicItem> searchResults = new List<SubsonicItem>(); // Parse the artist if (myXML.ChildNodes[1].Name == "subsonic-response") { if (myXML.ChildNodes[1].FirstChild.Name == "searchResult") { for (int i = 0; i < myXML.ChildNodes[1].FirstChild.ChildNodes.Count; i++) { bool isDir = bool.Parse(myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["isDir"].Value); string title = myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["title"].Value; string theId = myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["id"].Value; string artist = ""; string album = ""; if (!isDir) { artist = myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["artist"].Value; album = myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["album"].Value; } SubsonicItem theItem; if (isDir) theItem = new SubsonicItem(title, theId, SubsonicItem.SubsonicItemType.Folder, null); else theItem = new Song(title, artist, album, theId); searchResults.Add(theItem); } } } return searchResults; }