/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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 <List <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)); }
/// <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)); }
/// <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)); }
/// <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.Count == 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.Count != 0) { if (_pendingSongs == null) { _pendingSongs = new List <Song>(); } _pendingSongs.Clear(); _pendingSongs = newPlayList; } if (changeCurrentSong) { CurrentSong = _pendingSongs[0]; } } else { // TODO: throw exception or not? } }
public async Task <List <Song> > GetSongs(Channel newChannel, string Songsid = null, ChangeChannelCommandType type = ChangeChannelCommandType.Normal) { var start = type == ChangeChannelCommandType.Normal ? newChannel.Start : null; var uri = ServerConnection.CreateGetPlayListUri(newChannel.Id, type: ReportType.CurrentChannelChanged, sid: Songsid, 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 == null || newPlayList?.Count == 0) { //TODO return(new List <Song>()); } else { return(newPlayList); } }