private static List <BeatmapDataModel> InnerToDataModelList(this IEnumerable <Beatmap> beatmaps) { return(beatmaps.Select((beatmap, i) => { var model = new BeatmapDataModel { Artist = beatmap.Artist, ArtistUnicode = beatmap.ArtistUnicode, BeatmapId = beatmap.BeatmapId, Creator = beatmap.Creator, FolderName = beatmap.FolderName, GameMode = beatmap.GameMode, SongSource = beatmap.SongSource, SongTags = beatmap.SongTags, Title = beatmap.Title, TitleUnicode = beatmap.TitleUnicode, Version = beatmap.Version, BeatmapFileName = beatmap.BeatmapFileName, InOwnDb = beatmap.InOwnDb, BeatmapDbId = beatmap.Id }; try { switch (beatmap.GameMode) { case OSharp.Beatmap.Sections.GamePlay.GameMode.Circle: model.Stars = Math.Round(beatmap.DiffSrNoneStandard, 2); break; case OSharp.Beatmap.Sections.GamePlay.GameMode.Taiko: model.Stars = Math.Round(beatmap.DiffSrNoneTaiko, 2); break; case OSharp.Beatmap.Sections.GamePlay.GameMode.Catch: model.Stars = Math.Round(beatmap.DiffSrNoneCtB, 2); break; case OSharp.Beatmap.Sections.GamePlay.GameMode.Mania: model.Stars = Math.Round(beatmap.DiffSrNoneMania, 2); break; } } catch (Exception ex) { Logger.Error(ex); } return model; }).ToList()); }
public static async Task <string> GetThumbByBeatmapDbId(BeatmapDataModel dataModel) { return(await Task.Run(async() => { await Lock.WaitAsync(); try { if (_appDbOperator.GetMapThumb(dataModel.BeatmapDbId, out var path) && path != null) { if (File.Exists(path)) { return path; } } var folder = dataModel.GetFolder(out var isFromDb, out var freePath); var osuFilePath = isFromDb ? Path.Combine(folder, dataModel.BeatmapFileName) : freePath; if (!File.Exists(osuFilePath)) { return null; } var osuFile = await OsuFile.ReadFromFileAsync(osuFilePath, options => { options.IncludeSection("Events"); options.IgnoreSample(); options.IgnoreStoryboard(); }) .ConfigureAwait(false); if (!osuFile.ReadSuccess) { return null; } var guidStr = Guid.NewGuid().ToString(); var sourceBgFile = osuFile.Events?.BackgroundInfo?.Filename; if (string.IsNullOrWhiteSpace(sourceBgFile)) { _appDbOperator.SetMapThumb(dataModel.BeatmapDbId, null); return null; } var sourceBgPath = Path.Combine(folder, sourceBgFile); if (!File.Exists(sourceBgPath)) { //_appDbOperator.SetMapThumb(dataModel.BeatmapDbId, null); return null; } ResizeImageAndSave(sourceBgPath, guidStr, height: 200); _appDbOperator.SetMapThumb(dataModel.BeatmapDbId, guidStr); return guidStr; } catch (Exception ex) { Logger.Error("Error while creating beatmap thumb cache: {0}", dataModel.GetIdentity()); return default; } finally { Lock.Release(); } })); }