Пример #1
0
 public static void AddSongToPlaylist(Playlist playlist, PlaylistSong song)
 {
     playlist.songs.Add(song);
     if (playlist.playlistTitle == "Your favorite songs")
     {
         playlist.SavePlaylist();
     }
 }
Пример #2
0
 public static void RemoveLevelFromPlaylist(Playlist playlist, string levelId)
 {
     if (playlist.songs.Where(y => y.level != null).Any(x => x.level.levelID == levelId))
     {
         PlaylistSong song = playlist.songs.First(x => x.level != null && x.level.levelID == levelId);
         song.level   = null;
         song.levelId = "";
     }
     if (playlist.playlistTitle == "Your favorite songs")
     {
         playlist.SavePlaylist();
     }
 }
Пример #3
0
        public Playlist(JSONNode playlistNode)
        {
            string image = playlistNode["image"].Value;

            if (!string.IsNullOrEmpty(image))
            {
                try
                {
                    icon = Sprites.Base64ToSprite(image.Substring(image.IndexOf(",") + 1));
                }
                catch
                {
                    Logger.Exception("Unable to convert playlist image to sprite!");
                    icon = Sprites.BeastSaberLogo;
                }
            }
            else
            {
                icon = Sprites.BeastSaberLogo;
            }
            playlistTitle    = playlistNode["playlistTitle"];
            playlistAuthor   = playlistNode["playlistAuthor"];
            customDetailUrl  = playlistNode["customDetailUrl"];
            customArchiveUrl = playlistNode["customArchiveUrl"];
            if (!string.IsNullOrEmpty(customDetailUrl))
            {
                if (!customDetailUrl.EndsWith("/"))
                {
                    customDetailUrl += "/";
                }
                Logger.Log("Found playlist with customDetailUrl! Name: " + playlistTitle + ", CustomDetailUrl: " + customDetailUrl);
            }
            if (!string.IsNullOrEmpty(customArchiveUrl) && customArchiveUrl.Contains("[KEY]"))
            {
                Logger.Log("Found playlist with customArchiveUrl! Name: " + playlistTitle + ", CustomArchiveUrl: " + customArchiveUrl);
            }

            songs = new List <PlaylistSong>();

            foreach (JSONNode node in playlistNode["songs"].AsArray)
            {
                PlaylistSong song = new PlaylistSong();
                song.key      = node["key"];
                song.songName = node["songName"];
                song.hash     = node["hash"];
                song.levelId  = node["levelId"];

                songs.Add(song);
            }

            if (playlistNode["playlistSongCount"] != null)
            {
                playlistSongCount = playlistNode["playlistSongCount"].AsInt;
            }
            if (playlistNode["fileLoc"] != null)
            {
                fileLoc = playlistNode["fileLoc"];
            }

            if (playlistNode["playlistURL"] != null)
            {
                fileLoc = playlistNode["playlistURL"];
            }
        }
        /// <summary>
        /// Favorites used to exist as part of the song_browser_settings.xml
        /// This makes little sense now.  This is the upgrade path.
        /// Convert all existing favorites to the best of our effort into a playlist.
        /// </summary>
        /// <param name="levelIdToCustomLevel"></param>
        /// <param name="levelIdToSongVersion"></param>
        public void ConvertFavoritesToPlaylist(Dictionary <String, SongLoaderPlugin.OverrideClasses.CustomLevel> levelIdToCustomLevel,
                                               Dictionary <string, string> levelIdToSongVersion)
        {
            // Check if we have favorites to convert to the playlist
            if (this.Favorites.Count <= 0)
            {
                return;
            }

            // check if the playlist exists
            String playlistPath   = Path.Combine(Environment.CurrentDirectory, "Playlists", DefaultConvertedFavoritesPlaylistName);
            bool   playlistExists = false;

            if (File.Exists(playlistPath))
            {
                playlistExists = true;
            }

            // abort here if playlist already exits.
            if (playlistExists)
            {
                Logger.Info("Not converting song_browser_setting.xml favorites because {0} already exists...", playlistPath);
                return;
            }

            Logger.Info("Converting {0} Favorites in song_browser_settings.xml to {1}...", this.Favorites.Count, playlistPath);

            // written like this in case we ever want to support adding to this playlist
            Playlist p = null;

            if (playlistExists)
            {
                p = Playlist.LoadPlaylist(playlistPath);
            }
            else
            {
                p = new Playlist
                {
                    playlistTitle  = "Song Browser Favorites",
                    playlistAuthor = "SongBrowser",
                    fileLoc        = "",
                    image          = Base64Sprites.PlaylistIconB64,
                    songs          = new List <PlaylistSong>(),
                };
            }

            List <String> successfullyRemoved = new List <string>();

            this.Favorites.RemoveWhere(levelId =>
            {
                PlaylistSong playlistSong = new PlaylistSong
                {
                    levelId = levelId
                };

                if (levelIdToCustomLevel.ContainsKey(levelId) && levelIdToSongVersion.ContainsKey(levelId))
                {
                    playlistSong.songName = levelIdToCustomLevel[levelId].songName;
                    playlistSong.key      = levelIdToSongVersion[levelId];
                }
                else
                {
                    // No easy way to look up original songs... They will still work but have wrong song name in playlist.
                    playlistSong.songName = levelId;
                    playlistSong.key      = "";
                }

                p.songs.Add(playlistSong);

                return(true);
            });

            p.SavePlaylist(playlistPath);

            if (String.IsNullOrEmpty(this.currentEditingPlaylistFile))
            {
                this.currentEditingPlaylistFile = playlistPath;
            }

            this.Save();
        }
        /// <summary>
        /// Favorites used to exist as part of the song_browser_settings.xml
        /// This makes little sense now.  This is the upgrade path.
        /// Convert all existing favorites to the best of our effort into a playlist.
        /// </summary>
        /// <param name="levelIdToCustomLevel"></param>
        /// <param name="levelIdToSongVersion"></param>
        public void ConvertFavoritesToPlaylist(Dictionary <String, CustomPreviewBeatmapLevel> customSongsMap)
        {
            // map songs in case we are converting a huge list
            Dictionary <String, CustomPreviewBeatmapLevel> levelIdToCustomLevel = new Dictionary <string, CustomPreviewBeatmapLevel>(StringComparer.OrdinalIgnoreCase);

            foreach (var kp in customSongsMap)
            {
                if (levelIdToCustomLevel.ContainsKey(kp.Value.levelID))
                {
                    continue;
                }
                levelIdToCustomLevel.Add(kp.Value.levelID, kp.Value);
            }

            // Check if we have favorites to convert to the playlist
            if (this.Favorites.Count <= 0)
            {
                return;
            }

            // check if the playlist exists
            String playlistPath   = Path.Combine(Environment.CurrentDirectory, "Playlists", DefaultConvertedFavoritesPlaylistName);
            bool   playlistExists = false;

            if (File.Exists(playlistPath))
            {
                playlistExists = true;
            }

            // abort here if playlist already exits.
            if (playlistExists)
            {
                Logger.Info("Not converting song_browser_setting.xml favorites because {0} already exists...", playlistPath);
                return;
            }

            Logger.Info("Converting {0} Favorites in song_browser_settings.xml to {1}...", this.Favorites.Count, playlistPath);

            // written like this in case we ever want to support adding to this playlist
            Playlist p = null;

            if (playlistExists)
            {
                p = Playlist.LoadPlaylist(playlistPath);
            }
            else
            {
                p = new Playlist
                {
                    playlistTitle  = "Song Browser Favorites",
                    playlistAuthor = "SongBrowser",
                    fileLoc        = "",
                    image          = Base64Sprites.SpriteToBase64(Base64Sprites.BeastSaberLogo),
                    songs          = new List <PlaylistSong>(),
                };
            }

            List <String> successfullyRemoved = new List <string>();

            this.Favorites.RemoveWhere(levelId =>
            {
                PlaylistSong playlistSong = new PlaylistSong
                {
                    levelId = levelId
                };

                if (levelIdToCustomLevel.ContainsKey(levelId))
                {
                    playlistSong.songName = levelIdToCustomLevel[levelId].songName;
                    playlistSong.levelId  = levelId;
                    playlistSong.hash     = CustomHelpers.GetSongHash(levelId);
                }
                else
                {
                    // No easy way to look up original songs... They will still work but have wrong song name in playlist.
                    playlistSong.levelId = levelId;
                    playlistSong.hash    = CustomHelpers.GetSongHash(levelId);
                    playlistSong.key     = "";
                }

                p.songs.Add(playlistSong);

                return(true);
            });

            p.SavePlaylist(playlistPath);

            if (String.IsNullOrEmpty(this.currentEditingPlaylistFile))
            {
                this.currentEditingPlaylistFile = playlistPath;
            }

            this.Save();
        }
Пример #6
0
        public Playlist(JSONNode playlistNode)
        {
            string image = playlistNode["image"].Value;

            // If we cannot find an image or parse the provided one correctly, fall back to anything.
            // It will never be displayed by SongBrowser.
            if (!string.IsNullOrEmpty(image))
            {
                try
                {
                    icon = Sprites.Base64ToSprite(image.Substring(image.IndexOf(",") + 1));
                }
                catch
                {
                    Logger.Exception("Unable to convert playlist image to sprite!");
                    icon = Sprites.StarFullIcon;
                }
            }
            else
            {
                icon = Sprites.StarFullIcon;
            }
            playlistTitle    = playlistNode["playlistTitle"];
            playlistAuthor   = playlistNode["playlistAuthor"];
            customDetailUrl  = playlistNode["customDetailUrl"];
            customArchiveUrl = playlistNode["customArchiveUrl"];
            if (!string.IsNullOrEmpty(customDetailUrl))
            {
                if (!customDetailUrl.EndsWith("/"))
                {
                    customDetailUrl += "/";
                }
                Logger.Log("Found playlist with customDetailUrl! Name: " + playlistTitle + ", CustomDetailUrl: " + customDetailUrl);
            }
            if (!string.IsNullOrEmpty(customArchiveUrl) && customArchiveUrl.Contains("[KEY]"))
            {
                Logger.Log("Found playlist with customArchiveUrl! Name: " + playlistTitle + ", CustomArchiveUrl: " + customArchiveUrl);
            }

            songs = new List <PlaylistSong>();

            foreach (JSONNode node in playlistNode["songs"].AsArray)
            {
                PlaylistSong song = new PlaylistSong();
                song.key      = node["key"];
                song.songName = node["songName"];
                song.hash     = node["hash"];
                song.levelId  = node["levelId"];

                songs.Add(song);
            }

            if (playlistNode["playlistSongCount"] != null)
            {
                playlistSongCount = playlistNode["playlistSongCount"].AsInt;
            }
            if (playlistNode["fileLoc"] != null)
            {
                fileLoc = playlistNode["fileLoc"];
            }

            if (playlistNode["playlistURL"] != null)
            {
                fileLoc = playlistNode["playlistURL"];
            }
        }