public async Task <OfflineSongInfo?> GetSongByFilePathAsync(string path) { OfflineSongInfo?output = null; //TODO: If text cannot be read, the problem is here vvv using (StreamReader sr = new StreamReader(infoFilePath, false)) { LUint totalLines; if (!TryGetTotalLines(sr, out totalLines)) { return(null); } for (LUint i = 0; i < totalLines; i++) { string songLine = await sr.ReadLineAsync(); if (SongCollectionFormatter.GetFilePath(songLine) == path) { output = new OfflineSongInfo(SongCollectionFormatter.DeserializeString(songLine).Value, i); break; } else if (i == totalLines - 1) { //Last index output = null; } } } return(output); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns>Song.Null if cannot find a song</returns> public async Task <OfflineSongInfo?> GetSongByTitleAsync(string inputTitle) { OfflineSongInfo?off; //TODO: If text cannot be read, the problem is here vvv using (StreamReader sr = new StreamReader(infoFilePath, false)) { LUint totalLines; if (!TryGetTotalLines(sr, out totalLines)) { return(null); } #if !TRAINING string minDistanceObjStr = null; LUint minDistance = LUint.MaxValue; LUint objTimesPlayed = 0; LUint lineNum = 0; for (LUint i = 0; i < totalLines; i++) { string songLine = await sr.ReadLineAsync(); string songTitle = SongCollectionFormatter.GetSongTitle(songLine); LUint distance = diffService.DifferenceScore(inputTitle, songTitle); if (distance < minDistance) { minDistanceObjStr = songLine; objTimesPlayed = SongCollectionFormatter.GetTimesPlayed(songLine); lineNum = i; if (distance == 0) { break; } } else if (distance == minDistance) { LUint songTimesPlayed = SongCollectionFormatter.GetTimesPlayed(songLine); if (songTimesPlayed > objTimesPlayed) { minDistanceObjStr = songLine; objTimesPlayed = songTimesPlayed; lineNum = i; } } } if (minDistanceObjStr is null) { off = null; } else { off = new OfflineSongInfo(SongCollectionFormatter.DeserializeString(minDistanceObjStr).Value, lineNum); } #endif } return(off); }
public async Task <OfflineSongInfo?> GetSongByURLAsync(string url) { #if DEBUG LogHelper.Logln("Initializing GetSongByURLAsync(url) in Song Collection", LogType.Debug); #endif OfflineSongInfo?output = null; //TODO: If text cannot be read, the problem is here vvv using (StreamReader sr = new StreamReader(infoFilePath, false)) { LUint totalLines; if (!TryGetTotalLines(sr, out totalLines)) { return(null); } #if DEBUG LogHelper.Logln($"There are a total of {totalLines} of songs.", LogType.Debug); #endif for (LUint i = 0; i < totalLines; i++) { string songLine = await sr.ReadLineAsync(); string oldUrl = SongCollectionFormatter.GetUrl(songLine); #if DEBUG LogHelper.Logln($"oldUrl = {oldUrl}", LogType.Debug); #endif if (oldUrl == url) { output = new OfflineSongInfo(SongCollectionFormatter.DeserializeString(songLine).Value, i); break; } else if (i == totalLines - 1) { //Last index output = null; } } } return(output); }