Beispiel #1
0
 public Song(string title = "", string artist = "", string album = "", string id = "", SubsonicItem parent = null)
     : base(title, id, SubsonicItemType.Song, parent)
 {
     this.Title = title;
     this.Artist = artist;
     this.Album = album;
 }
 public SubsonicItem(string name, string id, SubsonicItemType itemType, SubsonicItem parent)
     : this(name, id)
 {
     this.ItemType = itemType;
     this.Parent = parent;
 }
Beispiel #3
0
        /// <summary>
        /// Returns a listing of all files in a music directory. Typically used to get list of albums for an artist, or list of songs for an album.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="id">A string which uniquely identifies the music folder. Obtained by calls to getIndexes or getMusicDirectory.</param>
        /// <returns>MusicFolder object containing info for the specified directory</returns>
        public static List<SubsonicItem> GetMusicDirectory(ISubsonicConnection connection, string id)
        {
            Dictionary<string, string> theParameters = new Dictionary<string, string> {{"id", id}};

            string result = connection.GetResponse("getMusicDirectory", theParameters);
            if (string.IsNullOrEmpty(result))
            {
                throw new NullReferenceException("resulting xml is null");
            }

            XmlDocument myXml = new XmlDocument();

            myXml.LoadXml(result);

            List<SubsonicItem> theContents = new List<SubsonicItem>();

            if (myXml.ChildNodes[1].Name == "subsonic-response")
            {
                if (myXml.ChildNodes[1].FirstChild.Name == "directory")
                {
                    SubsonicItem theParent = new SubsonicItem
                    {
                        Name = myXml.ChildNodes[1].FirstChild.Attributes["name"].Value,
                        ID = myXml.ChildNodes[1].FirstChild.Attributes["id"].Value
                    };

                    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;

                        SubsonicItem theItem = new SubsonicItem(title, theId, (isDir ? SubsonicItemType.Folder : SubsonicItemType.Song), theParent);
                        theContents.Add(theItem);
                    }
                }
            }

            return theContents;
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of SubsonicItems that fall inside the parent object 
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="parent">
        /// A <see cref="SubsonicItem"/>
        /// </param>
        /// <param name="ifModifiedSince">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="List<SubsonicItem>"/>
        /// </returns>
        public static List<SubsonicItem> GetItemChildren(ISubsonicConnection connection, SubsonicItem parent, string ifModifiedSince)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();

            // Generate the proper request for the parent type
            string requestType;
            if (parent.ItemType == SubsonicItemType.Library)
            {
                requestType = "getIndexes";
                if (parent.ID != "-1")
                {
                    parameters.Add("musicFolderId", parent.ID);
                }
            }
            else
            {
                requestType = "getMusicDirectory";
                parameters.Add("id", parent.ID);
            }

            // Load the parameters if provided
            if (!string.IsNullOrEmpty(ifModifiedSince))
            {
                parameters.Add("ifModifiedSince", ifModifiedSince);
            }

            // Make the request
            string result = connection.GetResponse(requestType, parameters);

            // Parse the resulting XML string into an XmlDocument
            XmlDocument myXml = new XmlDocument();
            myXml.LoadXml(result);

            // Parse the artist out of the result
            List<SubsonicItem> children = new List<SubsonicItem>();
            if (parent.ItemType == SubsonicItemType.Library)
            {
                if (myXml.ChildNodes[1].Name == "subsonic-response")
                {
                    if (myXml.ChildNodes[1].FirstChild.Name == "indexes")
                    {
                        for (int i = 0; i < myXml.ChildNodes[1].FirstChild.ChildNodes.Count; i++)
                        {
                            // Ignore index name (and entire concept), and move on to parse children
                            for (int j = 0; j < myXml.ChildNodes[1].FirstChild.ChildNodes[i].ChildNodes.Count; j++)
                            {
                                string artist = myXml.ChildNodes[1].FirstChild.ChildNodes[i].ChildNodes[j].Attributes["name"].Value;
                                string id = myXml.ChildNodes[1].FirstChild.ChildNodes[i].ChildNodes[j].Attributes["id"].Value;

                                children.Add(new SubsonicItem(artist, id, SubsonicItemType.Folder, parent));
                            }
                        }
                    }
                }
            }
            // Parse the directory
            else if (parent.ItemType == SubsonicItemType.Folder)
            {
                if (myXml.ChildNodes[1].Name == "subsonic-response")
                {
                    if (myXml.ChildNodes[1].FirstChild.Name == "directory")
                    {
                        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 id = myXml.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["id"].Value;

                            SubsonicItem theItem = new SubsonicItem(title, id, (isDir ? SubsonicItemType.Folder : SubsonicItemType.Song), parent);
                            children.Add(theItem);
                        }
                    }
                }
            }

            return children;
        }