public static void MatchSongsForPlaylist(Playlist playlist, bool matchAll = false) { if (!SongLoader.AreSongsLoaded || SongLoader.AreSongsLoading || playlist.playlistTitle == "All songs" || playlist.playlistTitle == "Your favorite songs") { return; } Logger.Log("Started matching songs for playlist \"" + playlist.playlistTitle + "\"..."); if (!playlist.songs.All(x => x.level != null) || matchAll) { Stopwatch execTime = new Stopwatch(); execTime.Start(); playlist.songs.AsParallel().ForAll(x => { if (x.level == null || matchAll) { try { if (!string.IsNullOrEmpty(x.levelId)) //check that we have levelId and if we do, try to match level { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID == x.levelId); } if (x.level == null && !string.IsNullOrEmpty(x.hash)) //if level is still null, check that we have hash and if we do, try to match level { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID.StartsWith(x.hash.ToUpper())); } if (x.level == null && !string.IsNullOrEmpty(x.key)) //if level is still null, check that we have key and if we do, try to match level { ScrappedSong song = ScrappedData.Songs.FirstOrDefault(z => z.Key == x.key); if (song != null) { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.levelID.StartsWith(song.Hash)); } else { x.level = SongLoader.CustomLevels.FirstOrDefault(y => y.customSongInfo.path.Contains(x.key)); } } } catch (Exception e) { Logger.Warning($"Unable to match song with {(string.IsNullOrEmpty(x.key) ? " unknown key!" : ("key " + x.key + " !"))} Exception: {e}"); } } }); Logger.Log($"Matched all songs for playlist \"{playlist.playlistTitle}\"! Time: {execTime.Elapsed.TotalSeconds.ToString("0.00")}s"); execTime.Reset(); } }
private List <BeatmapLevelSO> FilterPlaylist() { // bail if no playlist, usually means the settings stored one the user then moved. if (this.CurrentPlaylist == null) { Logger.Error("Trying to load a null playlist..."); this.Settings.filterMode = SongFilterMode.None; return(null); } // Get song keys PlaylistsCollection.MatchSongsForPlaylist(this.CurrentPlaylist, true); Logger.Debug("Filtering songs for playlist: {0}", this.CurrentPlaylist.playlistTitle); Dictionary <String, BeatmapLevelSO> levelDict = new Dictionary <string, BeatmapLevelSO>(); foreach (KeyValuePair <string, List <BeatmapLevelSO> > entry in _levelPackToSongs) { foreach (BeatmapLevelSO level in entry.Value) { if (!levelDict.ContainsKey(level.levelID)) { levelDict.Add(level.levelID, level); } } } List <BeatmapLevelSO> songList = new List <BeatmapLevelSO>(); foreach (PlaylistSong ps in this.CurrentPlaylist.songs) { if (ps.level != null) { songList.Add(levelDict[ps.level.levelID]); } else { Logger.Warning("Could not find song in playlist: {0}", ps.songName); } } Logger.Debug("Playlist filtered song count: {0}", songList.Count); return(songList); }
/// <summary> /// Parse the current pp data file. /// Public so controllers can decide when to update it. /// </summary> public void UpdateScoreSaberDataMapping() { Logger.Trace("UpdateScoreSaberDataMapping()"); ScoreSaberDataFile scoreSaberDataFile = ScoreSaberDatabaseDownloader.ScoreSaberDataFile; // bail if (scoreSaberDataFile == null) { Logger.Warning("Score saber data is not ready yet..."); return; } foreach (var level in SongLoader.CustomLevels) { // Skip if (_levelIdToScoreSaberData.ContainsKey(level.levelID)) { continue; } ScoreSaberData scoreSaberData = null; // try to version match first if (_levelIdToSongVersion.ContainsKey(level.levelID)) { String version = _levelIdToSongVersion[level.levelID]; if (scoreSaberDataFile.SongVersionToScoreSaberData.ContainsKey(version)) { scoreSaberData = scoreSaberDataFile.SongVersionToScoreSaberData[version]; } } if (scoreSaberData != null) { //Logger.Debug("{0} = {1}pp", level.songName, pp); _levelIdToScoreSaberData.Add(level.levelID, scoreSaberData); } } }
public bool DeleteSong(Song song) { bool zippedSong = false; string path = ""; CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); if (string.IsNullOrEmpty(song.path)) { if (level != null) { path = level.customSongInfo.path; } } else { path = song.path; } if (string.IsNullOrEmpty(path)) { return(false); } if (!Directory.Exists(path)) { return(false); } if (path.Contains("/.cache/")) { zippedSong = true; } if (zippedSong) { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Unable to delete empty folder!"); } } if (level != null) { SongLoader.Instance.RemoveSongWithLevelID(level.levelID); } Logger.Log($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); return(true); }
public static void MatchSongsForPlaylist(Playlist playlist, bool matchAll = false) { if (!SongCore.Loader.AreSongsLoaded || SongCore.Loader.AreSongsLoading || playlist.playlistTitle == "All songs" || playlist.playlistTitle == "Your favorite songs") { return; } Dictionary <string, CustomPreviewBeatmapLevel> songMap = new Dictionary <string, CustomPreviewBeatmapLevel>(StringComparer.OrdinalIgnoreCase); foreach (var kp in SongCore.Loader.CustomLevels) { var songHash = CustomHelpers.GetSongHash(kp.Value.levelID); if (songMap.ContainsKey(songHash)) { continue; } songMap.Add(songHash, kp.Value); } if (!playlist.songs.All(x => x.level != null) || matchAll) { playlist.songs.AsParallel().ForAll(x => { if (x.level == null || matchAll) { try { // try to use levelID if (!string.IsNullOrEmpty(x.levelId)) { string songHash = CustomHelpers.GetSongHash(x.levelId); if (songMap.ContainsKey(songHash)) { x.level = songMap[songHash]; x.hash = songHash; } } // failed, try again using hash if (x.level == null && !string.IsNullOrEmpty(x.hash)) { // fix broken playlists from a bug in song browser if (x.hash.Contains("custom_level")) { x.hash = CustomHelpers.GetSongHash(x.hash); } if (songMap.ContainsKey(x.hash)) { x.level = songMap[x.hash]; } } if (x.level == null && !string.IsNullOrEmpty(x.key)) { x.level = SongCore.Loader.CustomLevels.FirstOrDefault(y => y.Value.customLevelPath.Contains(x.key)).Value; if (x.level != null && !String.IsNullOrEmpty(x.level.levelID)) { x.hash = CustomHelpers.GetSongHash(x.level.levelID); } } } catch (Exception e) { Logger.Warning($"Unable to match song with {(string.IsNullOrEmpty(x.key) ? " unknown key!" : ("key " + x.key + " !"))}"); } } }); } }
public void DeleteSong(Song song) { bool zippedSong = false; string path = ""; // Console.WriteLine("Deleting: " + song.path); SongCore.Loader.Instance.DeleteSong(song.path, false); /* * CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); * * if (level != null) * SongLoader.Instance.RemoveSongWithLevelID(level.levelID); * * if (string.IsNullOrEmpty(song.path)) * { * if (level != null) * path = level.customSongInfo.path; * } * else * { * path = song.path; * } */ path = song.path.Replace('\\', '/'); if (string.IsNullOrEmpty(path)) { return; } if (!Directory.Exists(path)) { return; } if (path.Contains("/.cache/")) { zippedSong = true; } Task.Run(() => { if (zippedSong) { Logger.Info("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { try { Logger.Info("Deleting \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Unable to delete empty folder!"); } } catch (Exception ex) { Logger.Error("Error Deleting Song:" + song.path); Logger.Error(ex.ToString()); } } Logger.Info($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); }).ConfigureAwait(false); }