Ejemplo n.º 1
0
        /// <summary>
        /// Gets the song detail.
        /// </summary>
        /// <param name="sid">The SID of the song.</param>
        /// <returns></returns>
        public async Task <SongDetail> GetSongDetail(string sid)
        {
            var uri         = ServerConnection.CreateGetSongDetailUri(sid);
            var jsonContent = await ServerConnection.Get(uri, null);

            return(ServerRequests.ParseGetSongDetailResult(jsonContent));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the channel info.
        /// </summary>
        /// <param name="channelId">The channel ID.</param>
        /// <returns></returns>
        public async Task <Channel> GetChannelInfo(int channelId)
        {
            var uri         = ServerConnection.CreateGetChannelInfoUri(channelId);
            var jsonContent = await ServerConnection.Get(uri, null);

            return(ServerRequests.ParseGetChannelInfoResult(jsonContent));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Searches the channel with specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="start">The preferred index of the first channel in the returned channel array.</param>
        /// <param name="maxSize">The maximum size of returned channel array.</param>
        /// <returns>A channel array with the first channel at index <paramref name="start"/>, or an empty array if no channels available.</returns>
        public async Task <PartialList <Channel> > SearchChannel(string query, int start, int maxSize)
        {
            var uri         = ServerConnection.CreateSearchChannelUri(query, start, maxSize);
            var jsonContent = await ServerConnection.Get(uri, null);

            return(ServerRequests.ParseSearchChannelResult(jsonContent));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the recommended channels.
        /// </summary>
        /// <returns>The recommended channels, organized by groups.</returns>
        public async Task <ChannelGroup[]> GetRecommendedChannels()
        {
            var uri         = ServerConnection.CreateGetRecommendedChannelsUri();
            var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest);

            return(ServerRequests.ParseGetRecommendedChannelsResult(jsonContent));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the audio URL of the song.
        /// </summary>
        /// <param name="song">The song.</param>
        /// <returns></returns>
        /// <remarks>The audio URL can be invalid after a period of time. This method can get an updated URL.</remarks>
        public async Task UpdateSongUrl(Song song)
        {
            var uri         = ServerConnection.CreateGetSongUrlUri(song.Sid, song.Ssid);
            var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest);

            song.Url = ServerRequests.ParseGetSongUrlResult(jsonContent);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the offline red heart songs.
        /// </summary>
        /// <param name="maxSize">The maximum amount of returned songs.</param>
        /// <param name="excludedSids">The excluded SIDs of songs.</param>
        /// <returns>
        /// The offline red heart songs.
        /// </returns>
        public async Task <Song[]> GetOfflineRedHeartSongs(int maxSize, IEnumerable <string> excludedSids)
        {
            var uri         = ServerConnection.CreateGetPlayListUri(-3, type: ReportType.CurrentChannelChanged, sid: null, start: null, formats: null, kbps: null, playedTime: null, mode: "offline", excludedSids: excludedSids, max: maxSize);
            var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest);

            return(ServerRequests.ParseGetPlayListResult(jsonContent));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the lyrics.
        /// </summary>
        /// <param name="sid">The SID of the song.</param>
        /// <param name="ssid">The SSID of the song.</param>
        /// <returns></returns>
        public async Task <string> GetLyrics(string sid, string ssid)
        {
            var uri         = ServerRequests.CreateGetLyricsUri(sid, ssid);
            var jsonContent = await ServerConnection.Get(uri, null);

            return(ServerRequests.ParseGetLyricsResult(jsonContent));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Send a report to server.
        /// </summary>
        /// <param name="type">The type of report.</param>
        /// <param name="channelId">The channel ID.</param>
        /// <param name="sid">The SID of current song.</param>
        /// <param name="start">The start song code.</param>
        /// <returns></returns>
        private async Task Report(ReportType type, int channelId, string sid, string start)
        {
            var changeCurrentSong = !(type == ReportType.Like || type == ReportType.CancelLike);

            if (changeCurrentSong)
            {
                CurrentSong = null;
            }
            var uri         = ServerConnection.CreateGetPlayListUri(channelId, type: type, sid: sid, start: start, formats: null, kbps: null, playedTime: null, mode: null, excludedSids: null, max: null);
            var jsonContent = await ServerConnection.Get(uri, ServerConnection.SetSessionInfoToRequest);

            var newPlayList = ServerRequests.ParseGetPlayListResult(jsonContent);

            if (newPlayList.Length == 0)
            {
                if (type != ReportType.CurrentSongEnded)
                {
                    throw new NoAvailableSongsException();
                }
                if (_pendingSongs.Count == 0)
                {
                    await Report(ReportType.PlayListEmpty, channelId, sid, start);

                    return;
                }
            }
            if (channelId == AsyncExpectedChannelId)
            {
                if (newPlayList.Length != 0)
                {
                    if (_pendingSongs == null)
                    {
                        _pendingSongs = new Queue <Song>();
                    }
                    _pendingSongs.Clear();
                    foreach (var song in newPlayList)
                    {
                        _pendingSongs.Enqueue(song);
                    }
                }
                if (changeCurrentSong)
                {
                    CurrentSong = _pendingSongs.Dequeue();
                }
            }
            else
            {
                // TODO: throw exception or not?
            }
        }