Beispiel #1
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="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 MusicFolder GetMusicDirectory(string id)
        {
            Dictionary <string, string> theParameters = new Dictionary <string, string>
            {
                { "id", id }
            };

            Stream theStream = MakeGenericRequest("getMusicDirectory", theParameters);

            StreamReader sr = new StreamReader(theStream);

            string result = sr.ReadToEnd();

            XmlDocument myXML = new XmlDocument();

            myXML.LoadXml(result);

            MusicFolder theFolder = new MusicFolder("ArtistFolder", id);

            if (myXML.ChildNodes[1].Name == "subsonic-response")
            {
                if (myXML.ChildNodes[1].FirstChild.Name == "directory")
                {
                    theFolder.Name = myXML.ChildNodes[1].FirstChild.Attributes["name"].Value;
                    theFolder.Id   = myXML.ChildNodes[1].FirstChild.Attributes["id"].Value;

                    int i = 0;
                    for (i = 0; i < myXML.ChildNodes[1].FirstChild.ChildNodes.Count; i++)
                    {
                        bool isDir = Boolean.Parse(myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["isDir"].Value);

                        if (isDir)
                        {
                            try
                            {
                                theFolder.AddFolder(MusicFolder.FromXml(myXML.ChildNodes[1].FirstChild.ChildNodes[i]));
                            }
                            catch (Exception e)
                            {
                                //todo log
                            }
                        }
                        else
                        {
                            try
                            {
                                theFolder.AddSong(Song.FromXml(myXML.ChildNodes[1].FirstChild.ChildNodes[i]));
                            }
                            catch (Exception)
                            {
                                //todo log
                            }
                        }
                    }
                }
            }

            return(theFolder);
        }
        public MusicFolder FindFolder(string theFolderName)
        {
            MusicFolder theFolder = _Folders.Find(
                delegate(MusicFolder fldr)
            {
                return(fldr.Name == theFolderName);
            }
                );

            return(theFolder);
        }
        /// <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="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 MusicFolder GetMusicDirectory(string id)
        {
            Dictionary <string, string> theParameters = new Dictionary <string, string>();

            theParameters.Add("id", id);
            Stream theStream = MakeGenericRequest("getMusicDirectory", theParameters);

            StreamReader sr = new StreamReader(theStream);

            string result = sr.ReadToEnd();

            XmlDocument myXML = new XmlDocument();

            myXML.LoadXml(result);

            MusicFolder theFolder = new MusicFolder("ArtistFolder", id);

            if (myXML.ChildNodes[1].Name == "subsonic-response")
            {
                if (myXML.ChildNodes[1].FirstChild.Name == "directory")
                {
                    theFolder.Name = myXML.ChildNodes[1].FirstChild.Attributes["name"].Value;
                    theFolder.id   = myXML.ChildNodes[1].FirstChild.Attributes["id"].Value;

                    int i = 0;
                    for (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;

                        if (isDir)
                        {
                            theFolder.AddFolder(title, theId);
                        }
                        else
                        {
                            theFolder.AddSong(title, theId);
                        }
                    }
                }
            }

            return(theFolder);
        }
Beispiel #4
0
        public static IEnumerable <Song> ListSongsByAlbumId(string albumId)
        {
            MusicFolder albumContens = Subsonic.GetMusicDirectory(albumId);

            return(albumContens.Songs);
        }
Beispiel #5
0
        public static IEnumerable <string> GetAlbumIds(string artistId)
        {
            MusicFolder folderContents = Subsonic.GetMusicDirectory(artistId);

            return(folderContents.Folders.Select(mf => mf.Id));
        }
Beispiel #6
0
			/// <summary>
			/// Returns an indexed structure of all artists
			/// </summary>
			/// <param name="musicFolderId" required="no">If specified, only return artists in the music folder with the given ID. See getMusicFolders</param>
			/// <param name="ifModifiedSince" required="no">If specified, only return a result if the artist collection has changed since the given time (in milliseconds since 1 Jan 1970).</param>
			/// <returns></returns>
			public async Task<MusicFolder> getIndexes(string musicFolderId = null, string ifModifiedSince = null)
			{
				Dictionary<string, string> parameters = new Dictionary<string, string>();
				 if (!string.IsNullOrEmpty(musicFolderId))
					parameters.Add("musicFolderId", musicFolderId);

				 if (!string.IsNullOrEmpty(ifModifiedSince))
					parameters.Add("ifModifiedSince", ifModifiedSince);

				Stream theStream = await this.MakeGenericRequest("getIndexes", parameters);
				

				StreamReader sr = new StreamReader(theStream);

				string result = sr.ReadToEnd();

				result = result.Replace(responseHead, "").Replace(responseFoot, "");

				XElement indexes = XElement.Parse(result);

				MusicFolder Indexes = new MusicFolder("Root","-1");

				Indexes.Folders.AddRange((from sh in indexes.Elements("shortcut")
												select new MusicFolder 
												{
													id = (string)sh.Attribute("id"),
													Name = (string)sh.Attribute("name"),
													ItemType = SubsonicItem.SubsonicItemType.Folder 

												}).ToList());

				IEnumerable<XElement> ind = indexes.Elements("index");

				Indexes.Folders.AddRange((from art in ind.Elements("artist")
											select new MusicFolder 
											{
												id = (string)art.Attribute("id"),
												Name = (string)art.Attribute("name"),
												ItemType = SubsonicItem.SubsonicItemType.Folder 
											}).ToList());



				Indexes.Songs.AddRange((from nm in indexes.Elements("child")
									select new Song
									{
										Id = (string)nm.Attribute("id"),
										Name = (string)nm.Attribute("title"),
										Album = (string)nm.Attribute("album"),
										Artist = (string)nm.Attribute("artist"),
										Parent = (string)nm.Attribute("parent"),
										CoverArt = (string)nm.Attribute("coverArt"),
										Created = (string)nm.Attribute("created"),
										Duration = (string)nm.Attribute("duration"),
										BitRate = (string)nm.Attribute("bitRate"),
										Track = (string)nm.Attribute("track"),
										Year = (string)nm.Attribute("year"),
										Genre = (string)nm.Attribute("genre"),
										Size = (string)nm.Attribute("size"),
										Suffix = (string)nm.Attribute("suffix"),
										ContentType = (string)nm.Attribute("contentType")
										
									}).ToList());

				return Indexes;
			}
Beispiel #7
0
			public async Task<MusicFolder> search3(string query, string artistCount = null, string artistOffset = null, string albumCount = null, string albumOffset = null, string songCount = null, string songOffset = null)
			{
				Dictionary<string, string> parameters = new Dictionary<string, string>();
				parameters.Add("query", query);
				if (!string.IsNullOrEmpty(artistCount))
					parameters.Add("artistCount", artistCount);
				if (!string.IsNullOrEmpty(artistOffset))
					parameters.Add("artistOffset", artistOffset);
				if (!string.IsNullOrEmpty(albumCount))
					parameters.Add("albumCount", albumCount);
				if (!string.IsNullOrEmpty(albumOffset))
					parameters.Add("albumOffset", albumOffset);
				if (!string.IsNullOrEmpty(songCount))
					parameters.Add("songCount", songCount);
				if (!string.IsNullOrEmpty(songOffset))
					parameters.Add("songOffset", songOffset);

				Stream theStream = await this.MakeGenericRequest("search3", parameters);
				

				StreamReader sr = new StreamReader(theStream);

				string result = sr.ReadToEnd();

				result = result.Replace(responseHead, "").Replace(responseFoot, "");

				XElement Xel = XElement.Parse(result);
				MusicFolder SearchResult = new MusicFolder();
				SearchResult.Artists.AddRange((from nm in Xel.Elements("artist")
											   select new Artist
											   {
												   Id = (string)nm.Attribute("id"),
												   Name = (string)nm.Attribute("name"),
												   CoverArt = (string)nm.Attribute("coverArt"),
												   AlbumCount = (string)nm.Attribute("albumCount")
											   }).ToList());
				SearchResult.Albums.AddRange((from nm in Xel.Elements("album")
											  select new Album
											  {
												  id = (string)nm.Attribute("id"),
												  Name = (string)nm.Attribute("name"),
												  CoverArt = (string)nm.Attribute("coverArt"),
												  SongCount = (string)nm.Attribute("songCount"),
												  Created = (string)nm.Attribute("created"),
												  Duration = (string)nm.Attribute("duration"),
												  Artist = (string)nm.Attribute("artist"),
												  ArtistId = (string)nm.Attribute("artistId")
											  }).ToList());
				SearchResult.Songs.AddRange((from nm in Xel.Elements("song")
											 select new Song
											 {
												 Id = (string)nm.Attribute("id"),
												 Name = (string)nm.Attribute("title"),
												 Album = (string)nm.Attribute("album"),
												 Artist = (string)nm.Attribute("artist"),
												 Parent = (string)nm.Attribute("parent"),
												 CoverArt = (string)nm.Attribute("coverArt"),
												 Created = (string)nm.Attribute("created"),
												 Duration = (string)nm.Attribute("duration"),
												 BitRate = (string)nm.Attribute("bitRate"),
												 Track = (string)nm.Attribute("track"),
												 Year = (string)nm.Attribute("year"),
												 Genre = (string)nm.Attribute("genre"),
												 Size = (string)nm.Attribute("size"),
												 Suffix = (string)nm.Attribute("suffix"),
												 ContentType = (string)nm.Attribute("contentType"),
												 AlbumId = (string)nm.Attribute("albumId"),
												 ArtistId = (string)nm.Attribute("artistId")
											 }).ToList());

				return SearchResult;
			}
Beispiel #8
0
			public async Task<MusicFolder> getStarred2()
			{
				Dictionary<string, string> parameters = new Dictionary<string, string>();

				Stream theStream = await this.MakeGenericRequest("getStarred2", parameters);
				

				StreamReader sr = new StreamReader(theStream);

				string result = sr.ReadToEnd();

				result = result.Replace(responseHead, "").Replace(responseFoot, "");

				XElement Xel = XElement.Parse(result);
				MusicFolder starred = new MusicFolder();
				starred.Artists.AddRange((from nm in Xel.Elements("artist")
										  select new Artist
										  {
											  Id = (string)nm.Attribute("id"),
											  Name = (string)nm.Attribute("name")
										  }).ToList());
				starred.Albums.AddRange((from nm in Xel.Elements("album")
										 select new Album
										 {
											 id = (string)nm.Attribute("id"),
											 Name = (string)nm.Attribute("name"),
											 CoverArt = (string)nm.Attribute("coverArt"),
											 SongCount = (string)nm.Attribute("songCount"),
											 Created = (string)nm.Attribute("created"),
											 Duration = (string)nm.Attribute("duration"),
											 Artist = (string)nm.Attribute("artist"),
											 ArtistId = (string)nm.Attribute("artistId"),
											 starred = (string)nm.Attribute("starred")
										 }).ToList());
				starred.Songs.AddRange((from nm in Xel.Elements("song")
										select new Song
										{
											Id = (string)nm.Attribute("id"),
											Name = (string)nm.Attribute("title"),
											Album = (string)nm.Attribute("album"),
											Artist = (string)nm.Attribute("artist"),
											Parent = (string)nm.Attribute("parent"),
											CoverArt = (string)nm.Attribute("coverArt"),
											Created = (string)nm.Attribute("created"),
											Duration = (string)nm.Attribute("duration"),
											BitRate = (string)nm.Attribute("bitRate"),
											Track = (string)nm.Attribute("track"),
											Year = (string)nm.Attribute("year"),
											Genre = (string)nm.Attribute("genre"),
											Size = (string)nm.Attribute("size"),
											Suffix = (string)nm.Attribute("suffix"),
											ContentType = (string)nm.Attribute("contentType"),
											AlbumId = (string)nm.Attribute("albumId"),
											ArtistId = (string)nm.Attribute("artistId"),
											Starred = (string)nm.Attribute("starred")
										}).ToList());

				return starred;
			}
Beispiel #9
0
			public void AddFolder(string name, string id)
			{
				MusicFolder newFolder = new MusicFolder(name, id);
				_Folders.Add(newFolder);
			}
Beispiel #10
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="id" required="yes">A string which uniquely identifies the music folder. Obtained by calls to getIndexes or getMusicDirectory.</param>
			/// <returns>A music folder</returns>
			public async Task<MusicFolder> getMusicDirectory(string id)
			{
				Dictionary<string, string> parameters = new Dictionary<string, string>();
		
				parameters.Add("id", id);			

				Stream theStream = await this.MakeGenericRequest("getMusicDirectory", parameters);
				

				StreamReader sr = new StreamReader(theStream);

				string result = sr.ReadToEnd();

				result = result.Replace(responseHead, "").Replace(responseFoot, "");

				XElement XDirectory = XElement.Parse(result);

				MusicFolder Directory = new MusicFolder((string)XDirectory.Attribute("name"),(string)XDirectory.Attribute("id"));

				Directory.Folders.AddRange((from dir in XDirectory.Elements("child")
							where dir.Attribute("isDir").Value == "true"
							select new MusicFolder{
								id = (string)dir.Attribute("id"),
								Name = (string)dir.Attribute("name")
							}).ToList());

				Directory.Songs.AddRange((from nm in XDirectory.Elements("child")
										  where nm.Attribute("isDir").Value == "false"
											select new Song 
											{

												Id = (string)nm.Attribute("id"),
												Name = (string)nm.Attribute("title"),
												Album = (string)nm.Attribute("album"),
												Artist = (string)nm.Attribute("artist"),
												Parent = (string)nm.Attribute("parent"),
												CoverArt = (string)nm.Attribute("coverArt"),
												Created = (string)nm.Attribute("created"),
												Duration = (string)nm.Attribute("duration"),
												BitRate = (string)nm.Attribute("bitRate"),
												Track = (string)nm.Attribute("track"),
												Year = (string)nm.Attribute("year"),
												Genre = (string)nm.Attribute("genre"),
												Size = (string)nm.Attribute("size"),
												Suffix = (string)nm.Attribute("suffix"),
												ContentType = (string)nm.Attribute("contentType"),
												AlbumId = (string)nm.Attribute("albumId"),
												ArtistId = (string)nm.Attribute("artistId")

											}).ToList());

				return Directory;
			}
Beispiel #11
0
 public void AddFolder(MusicFolder f)
 {
     _Folders.Add(f);
 }
Beispiel #12
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="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 MusicFolder GetMusicDirectory(string id)
        {
            Dictionary<string, string> theParameters = new Dictionary<string, string>
            {
                {"id", id}
            };

            Stream theStream = MakeGenericRequest("getMusicDirectory", theParameters);

            StreamReader sr = new StreamReader(theStream);

            string result = sr.ReadToEnd();

            XmlDocument myXML = new XmlDocument();
            myXML.LoadXml(result);

            MusicFolder theFolder = new MusicFolder("ArtistFolder", id);

            if (myXML.ChildNodes[1].Name == "subsonic-response")
            {
                if (myXML.ChildNodes[1].FirstChild.Name == "directory")
                {
                    theFolder.Name = myXML.ChildNodes[1].FirstChild.Attributes["name"].Value;
                    theFolder.Id = myXML.ChildNodes[1].FirstChild.Attributes["id"].Value;

                    int i = 0;
                    for (i = 0; i < myXML.ChildNodes[1].FirstChild.ChildNodes.Count; i++)
                    {
                        bool isDir = Boolean.Parse(myXML.ChildNodes[1].FirstChild.ChildNodes[i].Attributes["isDir"].Value);

                        if (isDir)
                        {
                            try
                            {
                                theFolder.AddFolder(MusicFolder.FromXml(myXML.ChildNodes[1].FirstChild.ChildNodes[i]));
                            }
                            catch (Exception e)
                            {
                                //todo log
                            }
                        }
                        else
                        {
                            try
                            {
                                theFolder.AddSong(Song.FromXml(myXML.ChildNodes[1].FirstChild.ChildNodes[i]));
                            }
                            catch (Exception)
                            {
                                //todo log
                            }
                        }
                    }
                }
            }

            return theFolder;
        }
Beispiel #13
0
        public MusicFolder FindFolder(string theFolderName)
        {
            MusicFolder theFolder = _Folders.Find(fldr => fldr.Name == theFolderName);

            return(theFolder);
        }
Beispiel #14
0
 public void AddFolder(MusicFolder f)
 {
     _Folders.Add(f);
 }
Beispiel #15
0
        public void AddFolder(string name, string id)
        {
            MusicFolder newFolder = new MusicFolder(name, id);

            _Folders.Add(newFolder);
        }
        /// <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="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 MusicFolder GetMusicDirectory(string id)
        {
            Dictionary<string, string> theParameters = new Dictionary<string, string>();
            theParameters.Add("id", id);
            Stream theStream = MakeGenericRequest("getMusicDirectory", theParameters);

            StreamReader sr = new StreamReader(theStream);

            string result = sr.ReadToEnd();

            XmlDocument myXML = new XmlDocument();
            myXML.LoadXml(result);

            MusicFolder theFolder = new MusicFolder("ArtistFolder", id);

            if (myXML.ChildNodes[1].Name == "subsonic-response")
            {
                if (myXML.ChildNodes[1].FirstChild.Name == "directory")
                {
                    theFolder.Name = myXML.ChildNodes[1].FirstChild.Attributes["name"].Value;
                    theFolder.id = myXML.ChildNodes[1].FirstChild.Attributes["id"].Value;

                    int i = 0;
                    for (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;

                        if (isDir)
                            theFolder.AddFolder(title, theId);
                        else
                            theFolder.AddSong(title, theId);
                    }
                }
            }

            return theFolder;
        }