/// <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> /// 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); } }