/// <summary> /// Configures songs list query /// </summary> /// <param name="filter">song filter</param> /// <returns>configured query</returns> private IQuery <SongDTO> GetQuery(SongFilter filter) { var query = songListQuery; query.ClearSortCriterias(); query.Filter = filter; return(query); }
public IEnumerable <SongDTO> ListSongs(SongFilter filter) { using (UnitOfWorkProvider.Create()) { _songListQuery.Filter = filter; return(_songListQuery.Execute() ?? new List <SongDTO>()); } }
public IEnumerable <Song> GetSong([FromQuery] SongFilter filter) { var songs = _context.Songs.Select(song => song); if (filter.Rating != null) { songs = songs.Where(song => song.Rating == filter.Rating); } if (filter.Size != null) { songs = songs.Skip((filter.Page - 1) * filter.Size.Value).Take(filter.Size.Value); } return(songs); }
public SongListQueryResultDTO ListAllSongs(SongFilter filter, int requiredPage = 1) { using (UnitOfWorkProvider.Create()) { var query = GetQuery(filter); query.Skip = Math.Max(0, requiredPage - 1) * PageSize; query.Take = PageSize; var sortOrder = filter.SortAscending ? SortDirection.Ascending : SortDirection.Descending; return(new SongListQueryResultDTO { RequestedPage = requiredPage, TotalResultCount = query.GetTotalRowCount(), ResultsPage = query.Execute(), Filter = filter }); } }
public async Task <IActionResult> Get([FromQuery] SongFilter filter) { try { var result = new PagedCollectionResponse <SongDto>(); if (string.IsNullOrEmpty(filter.City)) { if (filter.Lat == null && filter.Lon == null) { return(BadRequest("Please fill [lat] and [lon] or [city]")); } result.Items = await QueryAsync(new GetSongsByTemperatureOfCoordinatesQuery(filter.Lat.Value, filter.Lon.Value, filter.Offset, filter.Limit)); } else { result.Items = await QueryAsync(new GetSongsByTemperatureOfCityQuery(filter.City, filter.Offset, filter.Limit)); } //Get next page URL string SongFilter nextFilter = filter.Clone() as SongFilter; nextFilter.Offset += filter.Limit; String nextUrl = result.Items.Count() <= 0 ? null : this.Url.Action("Get", null, nextFilter, Request.Scheme); //Get previous page URL string SongFilter previousFilter = filter.Clone() as SongFilter; previousFilter.Offset -= filter.Limit; String previousUrl = previousFilter.Offset <= 0 ? null : this.Url.Action("Get", null, previousFilter, Request.Scheme); result.NextPage = !String.IsNullOrWhiteSpace(nextUrl) ? new Uri(nextUrl) : null; result.PreviousPage = !String.IsNullOrWhiteSpace(previousUrl) ? new Uri(previousUrl) : null; return(Ok(result)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
private List <JSONObject> GetSongListFromResults(JSONNode result, string SearchString, ref string errorMessage, SongFilter filter = SongFilter.All, string sortby = "-rating", int reverse = 1) { List <JSONObject> songs = new List <JSONObject>(); if (result != null) { // Add query results to out song database. if (result["docs"].IsArray) { var downloadedsongs = result["docs"].AsArray; for (int i = 0; i < downloadedsongs.Count; i++) { new SongMap(downloadedsongs[i].AsObject); } foreach (JSONObject currentSong in result["docs"].AsArray) { new SongMap(currentSong); } } else { new SongMap(result.AsObject); } } var list = MapDatabase.Search(SearchString); try { string[] sortorder = sortby.Split(' '); list.Sort(delegate(SongMap c1, SongMap c2) { return(reverse * CompareSong(c1.song, c2.song, ref sortorder)); }); } catch (Exception e) { //QueueChatMessage($"Exception {e} sorting song list"); Plugin.Log($"Exception sorting a returned song list. {e.ToString()}"); } foreach (var song in list) { errorMessage = SongSearchFilter(song.song, false, filter); if (errorMessage == "") { songs.Add(song.song); } } return(songs); }
// BUG: Testing major changes. This will get seriously refactored soon. private async Task CheckRequest(RequestInfo requestInfo) { TwitchUser requestor = requestInfo.requestor; string request = requestInfo.request; string normalrequest = normalize.NormalizeBeatSaverString(requestInfo.request); var id = GetBeatSaverId(normalize.RemoveSymbols(ref request, normalize._SymbolsNoDash)); if (id != "") { // Remap song id if entry present. This is one time, and not correct as a result. No recursion right now, could be confusing to the end user. if (songremap.ContainsKey(id) && !requestInfo.flags.HasFlag(CmdFlags.NoFilter)) { request = songremap[id]; QueueChatMessage($"Remapping request {requestInfo.request} to {request}"); } string requestcheckmessage = IsRequestInQueue(normalize.RemoveSymbols(ref request, normalize._SymbolsNoDash)); // Check if requested ID is in Queue if (requestcheckmessage != "") { QueueChatMessage(requestcheckmessage); return; } if (RequestBotConfig.Instance.OfflineMode && RequestBotConfig.Instance.offlinepath != "" && !MapDatabase.MapLibrary.ContainsKey(id)) { foreach (string directory in Directory.GetDirectories(RequestBotConfig.Instance.offlinepath, id + "*")) { await MapDatabase.LoadCustomSongs(directory, id); await Task.Run(async() => { while (MapDatabase.DatabaseLoading) { await Task.Delay(25); } }); break; } } } JSONNode result = null; string errorMessage = ""; // Get song query results from beatsaver.com if (!RequestBotConfig.Instance.OfflineMode) { string requestUrl = (id != "") ? $"https://beatsaver.com/api/maps/detail/{normalize.RemoveSymbols(ref request, normalize._SymbolsNoDash)}" : $"https://beatsaver.com/api/search/text/0?q={normalrequest}"; var resp = await Plugin.WebClient.GetAsync(requestUrl, System.Threading.CancellationToken.None); if (resp.IsSuccessStatusCode) { result = resp.ConvertToJsonNode(); } else { errorMessage = $"Invalid BeatSaver ID \"{request}\" specified. {requestUrl}"; } } SongFilter filter = SongFilter.All; if (requestInfo.flags.HasFlag(CmdFlags.NoFilter)) { filter = SongFilter.Queue; } List <JSONObject> songs = GetSongListFromResults(result, request, ref errorMessage, filter, requestInfo.state.sort != "" ? requestInfo.state.sort : AddSortOrder.ToString()); bool autopick = RequestBotConfig.Instance.AutopickFirstSong || requestInfo.flags.HasFlag(CmdFlags.Autopick); // Filter out too many or too few results if (songs.Count == 0) { if (errorMessage == "") { errorMessage = $"No results found for request \"{request}\""; } } else if (!autopick && songs.Count >= 4) { errorMessage = $"Request for '{request}' produces {songs.Count} results, narrow your search by adding a mapper name, or use https://beatsaver.com to look it up."; } else if (!autopick && songs.Count > 1 && songs.Count < 4) { var msg = new QueueLongMessage(1, 5); msg.Header($"@{requestor.DisplayName}, please choose: "); foreach (var eachsong in songs) { msg.Add(new DynamicText().AddSong(eachsong).Parse(BsrSongDetail), ", "); } msg.end("...", $"No matching songs for for {request}"); return; } else { if (!requestInfo.flags.HasFlag(CmdFlags.NoFilter)) { errorMessage = SongSearchFilter(songs[0], false); } } // Display reason why chosen song was rejected, if filter is triggered. Do not add filtered songs if (errorMessage != "") { QueueChatMessage(errorMessage); return; } JSONObject song = songs[0]; // Song requests should try to be current. If the song was local, we double check for a newer version //if ((song["downloadUrl"].Value == "") && !RequestBotConfig.Instance.OfflineMode ) //{ // //QueueChatMessage($"song: {song["id"].Value.ToString()} ,{song["songName"].Value}"); // yield return Utilities.Download($"https://beatsaver.com/api/maps/detail/{song["id"].Value.ToString()}", Utilities.DownloadType.Raw, null, // // Download success // (web) => // { // result = JSON.Parse(web.downloadHandler.text); // var newsong = result["song"].AsObject; // if (result != null && newsong["version"].Value != "") // { // new SongMap(newsong); // song = newsong; // } // }, // // Download failed, song probably doesn't exist on beatsaver // (web) => // { // // Let player know that the song is not current on BeatSaver // requestInfo.requestInfo += " *LOCAL ONLY*"; // ; //errorMessage = $"Invalid BeatSaver ID \"{request}\" specified. {requestUrl}"; // }); //} RequestTracker[requestor.Id].numRequests++; listcollection.add(duplicatelist, song["id"].Value); if ((requestInfo.flags.HasFlag(CmdFlags.MoveToTop))) { RequestQueue.Songs.Insert(0, new SongRequest(song, requestor, requestInfo.requestTime, RequestStatus.Queued, requestInfo.requestInfo)); } else { RequestQueue.Songs.Add(new SongRequest(song, requestor, requestInfo.requestTime, RequestStatus.Queued, requestInfo.requestInfo)); } RequestQueue.Write(); Writedeck(requestor, "savedqueue"); // This can be used as a backup if persistent Queue is turned off. if (!requestInfo.flags.HasFlag(CmdFlags.SilentResult)) { new DynamicText().AddSong(ref song).QueueMessage(AddSongToQueueText.ToString()); } Dispatcher.RunOnMainThread(() => { UpdateRequestUI(); _refreshQueue = true; }); }
public IEnumerable <SongDTO> ListSongsShuffle(SongFilter filter) { return(_songService.ListSongsShuffle(filter)); }
public IEnumerable <SongDTO> ListSongsShuffle(SongFilter filter) { return(ListSongs(filter).Shuffle()); }