Exemplo n.º 1
0
        public async Task <List <DataRow> > GetAlbumSongs(string album, CancellationToken token)
        {
            List <DataRow> data = new List <DataRow>();

            var request  = new RestRequest($"library/album/{album}", HttpMethod.Get, null, new KeyValuePair <string, string>("list", "songs"));
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["songs"].IsNullOrEmpty())
            {
                if (!jroot["data"]["album"].IsNullOrEmpty())
                {
                    string albumName = jroot["data"]["album"]["Title"].ToString();
                    data.Add(new HeaderDataRow(albumName, null));
                }

                var jsongs = (JArray)jroot["data"]["songs"];
                foreach (var jsong in jsongs)
                {
                    var dataRow = SongDataRow.Parse((JObject)jsong);
                    data.Add(dataRow);
                    token.ThrowIfCancellationRequested();
                }
            }

            return(data);
        }
Exemplo n.º 2
0
        public async Task <List <DataRow> > GetArtistAlbums(string artist, CancellationToken token)
        {
            List <DataRow> data = new List <DataRow>();

            var request  = new RestRequest($"library/artist/{artist}", HttpMethod.Get, null, new KeyValuePair <string, string>("list", "songs"));
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["artist"].IsNullOrEmpty() && !jroot["data"]["songs"].IsNullOrEmpty())
            {
                string artistName = jroot["data"]["artist"]["NiceName"].ToString();
                data.Add(new HeaderDataRow(artistName, null));

                var    jsongs    = (JArray)jroot["data"]["songs"];
                string lastAlbum = string.Empty;
                foreach (var jsong in jsongs)
                {
                    var dataRow = SongDataRow.Parse((JObject)jsong);
                    if (dataRow.AlbumId != null && dataRow.AlbumId != lastAlbum)
                    {
                        data.Add(new HeaderDataRow(dataRow.Album, new string[] { "album", dataRow.AlbumArtistId + "_" + dataRow.AlbumId }));
                        lastAlbum = dataRow.AlbumId;
                    }

                    data.Add(dataRow);
                    token.ThrowIfCancellationRequested();
                }
            }

            return(data);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a single song viewmodel
        /// </summary>
        public async Task <SongDataRow> GetSong(string song, CancellationToken token)
        {
            var request  = new RestRequest($"library/song/{song}", HttpMethod.Get);
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["song"].IsNullOrEmpty())
            {
                var dataRow = SongDataRow.Parse((JObject)jroot["data"]["song"]);
                return(dataRow);
            }

            return(null);
        }
Exemplo n.º 4
0
        public async Task <List <SongDataRow> > SearchSongs(string songName, string albumName, string artistName, CancellationToken token)
        {
            List <SongDataRow> data = new List <SongDataRow>();

            List <KeyValuePair <string, string> > searchParams = new List <KeyValuePair <string, string> >();

            if (!string.IsNullOrEmpty(songName))
            {
                searchParams.Add(new KeyValuePair <string, string>("song", songName));
            }
            if (!string.IsNullOrEmpty(albumName))
            {
                searchParams.Add(new KeyValuePair <string, string>("album", albumName));
            }
            if (!string.IsNullOrEmpty(artistName))
            {
                searchParams.Add(new KeyValuePair <string, string>("artist", artistName));
            }

            searchParams.Add(new KeyValuePair <string, string>("list", "songs"));

            var request  = new RestRequest($"library/search2", HttpMethod.Get, null, searchParams.ToArray());
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty() && !jroot["data"]["songs"].IsNullOrEmpty())
            {
                foreach (JObject songObject in jroot["data"]["songs"])
                {
                    var dataRow = SongDataRow.Parse(songObject);
                    data.Add(dataRow);
                }
            }

            return(data);
        }
Exemplo n.º 5
0
        public async Task <List <DataRow> > GetFolderContents(string folderPath, CancellationToken token)
        {
            List <DataRow> data = new List <DataRow>();

            var request  = new RestRequest($"library/folder/{folderPath}", HttpMethod.Get);
            var response = await DoRestRequest(request, 100000, token);

            var jroot = JToken.Parse(response.Body);

            token.ThrowIfCancellationRequested();
            if (!jroot.IsNullOrEmpty() && !jroot["data"].IsNullOrEmpty())
            {
                string basePath = jroot["data"]["path"].ToString();
                data.Add(new HeaderDataRow(basePath, null));

                if (!jroot["data"]["folders"].IsNullOrEmpty())
                {
                    foreach (var jfolder in jroot["data"]["folders"])
                    {
                        string folder   = jfolder.ToString();
                        string fullPath = basePath + "/" + folder;
                        data.Add(new FolderDataRow(folder, fullPath));
                    }
                }

                if (!jroot["data"]["songs"].IsNullOrEmpty())
                {
                    foreach (var jsong in jroot["data"]["songs"])
                    {
                        var dataRow = SongDataRow.Parse((JObject)jsong);
                        data.Add(dataRow);
                    }
                }
            }

            return(data);
        }