Example #1
0
        public static void ReloadPlaylists()
        {
            try
            {
                loadedPlaylists.Clear();

                List <string> playlistFiles = new List <string>();

                if (PluginConfig.beatDropInstalled)
                {
                    string[] beatDropJSONPlaylists   = Directory.GetFiles(Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists"), "*.json");
                    string[] beatDropBPLISTPlaylists = Directory.GetFiles(Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists"), "*.bplist");
                    playlistFiles.AddRange(beatDropJSONPlaylists);
                    playlistFiles.AddRange(beatDropBPLISTPlaylists);
                    Logger.Log($"Found {beatDropJSONPlaylists.Length + beatDropBPLISTPlaylists.Length} playlists in BeatDrop folder");
                }

                string[] localJSONPlaylists   = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.json");
                string[] localBPLISTPlaylists = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.bplist");
                playlistFiles.AddRange(localJSONPlaylists);
                playlistFiles.AddRange(localBPLISTPlaylists);

                Logger.Log($"Found {localJSONPlaylists.Length + localBPLISTPlaylists.Length} playlists in Playlists folder");

                foreach (string path in playlistFiles)
                {
                    try
                    {
                        Playlist playlist = Playlist.LoadPlaylist(path);
                        if (Path.GetFileName(path) == "favorites.json" && playlist.playlistTitle == "Your favorite songs")
                        {
                            continue;
                        }
                        loadedPlaylists.Add(playlist);
                        Logger.Log($"Found \"{playlist.playlistTitle}\" by {playlist.playlistAuthor}");
                    }
                    catch (Exception e)
                    {
                        Logger.Log($"Unable to parse playlist @ {path}! Exception: {e}");
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Exception("Unable to load playlists! Exception: " + e);
            }
        }
        public static void ReloadPlaylists(bool fullRefresh = true)
        {
            try
            {
                List <string> playlistFiles = new List <string>();

                if (PluginConfig.beatDropInstalled && Directory.Exists(Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists")))
                {
                    try
                    {
                        string[] beatDropJSONPlaylists   = Directory.GetFiles(Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists"), "*.json");
                        string[] beatDropBPLISTPlaylists = Directory.GetFiles(Path.Combine(PluginConfig.beatDropPlaylistsLocation, "playlists"), "*.bplist");
                        playlistFiles.AddRange(beatDropJSONPlaylists);
                        playlistFiles.AddRange(beatDropBPLISTPlaylists);
                        Plugin.log.Info($"Found {beatDropJSONPlaylists.Length + beatDropBPLISTPlaylists.Length} playlists in BeatDrop folder");
                    }catch (Exception e)
                    {
                        Plugin.log.Warn("Unable to load playlists from BeatDrop folder! Exception: " + e);
                    }
                }

                string[] localJSONPlaylists   = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.json");
                string[] localBPLISTPlaylists = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, "Playlists"), "*.bplist");
                playlistFiles.AddRange(localJSONPlaylists);
                playlistFiles.AddRange(localBPLISTPlaylists);

                Plugin.log.Info($"Found {localJSONPlaylists.Length + localBPLISTPlaylists.Length} playlists in Playlists folder");

                if (fullRefresh)
                {
                    loadedPlaylists.Clear();

                    foreach (string path in playlistFiles)
                    {
                        try
                        {
                            Playlist playlist = Playlist.LoadPlaylist(path);
                            if (Path.GetFileName(path) == "favorites.json" && playlist.playlistTitle == "Your favorite songs")
                            {
                                continue;
                            }
                            loadedPlaylists.Add(playlist);
                        }
                        catch (Exception e)
                        {
                            Plugin.log.Info($"Unable to parse playlist @ {path}! Exception: {e}");
                        }
                    }
                }
                else
                {
                    foreach (string path in playlistFiles)
                    {
                        if (!loadedPlaylists.Any(x => x.fileLoc == path))
                        {
                            try
                            {
                                Playlist playlist = Playlist.LoadPlaylist(path);
                                if (Path.GetFileName(path) == "favorites.json" && playlist.playlistTitle == "Your favorite songs")
                                {
                                    continue;
                                }
                                loadedPlaylists.Add(playlist);

                                if (SongLoader.AreSongsLoaded)
                                {
                                    MatchSongsForPlaylist(playlist);
                                }
                            }
                            catch (Exception e)
                            {
                                Plugin.log.Info($"Unable to parse playlist @ {path}! Exception: {e}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Plugin.log.Critical("Unable to load playlists! Exception: " + e);
            }
        }