Ejemplo n.º 1
0
        public async Task <Dictionary <string, ScrapedSong> > ReadFeed(IFeedReader reader, IFeedSettings settings, Playlist feedPlaylist, PlaylistStyle playlistStyle)
        {
            //Logger.log?.Info($"Getting songs from {feedName} feed.");
            var songs = await reader.GetSongsFromFeedAsync(settings).ConfigureAwait(false) ?? new Dictionary <string, ScrapedSong>();

            if (songs.Count > 0 && playlistStyle == PlaylistStyle.Replace)
            {
                feedPlaylist.Clear();
            }
            var addDate   = DateTime.Now;
            var decrement = new TimeSpan(1);

            foreach (var scrapedSong in songs)
            {
                if (HistoryManager.TryGetValue(scrapedSong.Value.Hash, out var historyEntry) &&
                    (historyEntry.Flag == HistoryFlag.NotFound ||
                     historyEntry.Flag == HistoryFlag.Deleted))
                {
                    continue;
                }
                //if (string.IsNullOrEmpty(scrapedSong.Value.SongKey))
                //{
                //    try
                //    {
                //        //Logger.log?.Info($"Grabbing key from BeatSaver: {scrapedSong.Value.SongName} by {scrapedSong.Value.MapperName}");
                //        // ScrapedSong doesn't have a Beat Saver key associated with it, probably scraped from ScoreSaber
                //        scrapedSong.Value.UpdateFrom(await BeatSaverReader.GetSongByHashAsync(scrapedSong.Key), false);
                //    }
                //    catch (ArgumentNullException)
                //    {
                //        Logger.log?.Warn($"Unable to find {scrapedSong.Value?.SongName} by {scrapedSong.Value?.MapperName} on Beat Saver ({scrapedSong.Key})");
                //    }
                //}
                var song = scrapedSong.Value.ToPlaylistSong();
                song.DateAdded = addDate;

                feedPlaylist?.TryAdd(song);
                addDate = addDate - decrement;
            }
            feedPlaylist?.TryWriteFile();

            return(songs);
        }
Ejemplo n.º 2
0
        public static SubMenu CreateFeedSettings(string feedName, string feedSource, FeedConfigBase feedConfig, SubMenu parent, string menuHintText = "")
        {
            if (string.IsNullOrEmpty(menuHintText))
            {
                menuHintText = $"Settings for {feedSource}'s {feedName} feed";
            }
            var feedSubMenu = parent.AddSubMenu(feedName, menuHintText, true);
            var enabled     = feedSubMenu.AddBool("Enable",
                                                  $"Enable the {feedName} feed from {feedSource}.");

            enabled.GetValue += delegate { return(feedConfig.Enabled); };
            enabled.SetValue += delegate(bool value)
            {
                if (feedConfig.Enabled == value)
                {
                    return;
                }
                feedConfig.Enabled = value;
                // Config.ConfigChanged = true;
            };

            var maxSongs = feedSubMenu.AddInt("Max Songs",
                                              "Maximum number of songs to download (0 for all).",
                                              0, 500, 5);

            maxSongs.GetValue += delegate { return(feedConfig.MaxSongs); };
            maxSongs.SetValue += delegate(int value)
            {
                if (feedConfig.MaxSongs == value)
                {
                    return;
                }
                feedConfig.MaxSongs = value;
                // Config.ConfigChanged = true;
            };

            var createPlaylist = feedSubMenu.AddBool("Create Playlist",
                                                     $"Maintain a playlist for this feed.");

            createPlaylist.GetValue += delegate { return(feedConfig.CreatePlaylist); };
            createPlaylist.SetValue += delegate(bool value)
            {
                if (feedConfig.CreatePlaylist == value)
                {
                    return;
                }
                feedConfig.CreatePlaylist = value;
                // Config.ConfigChanged = true;
            };

            string[] textSegmentOptions  = new string[] { "Append", "Replace" };
            var      textSegmentsExample = feedSubMenu.AddTextSegments("Playlist Style", "Select 'Append' to add new songs to playlist, 'Replace' to create a fresh playlist with songs read from the feed this session.", textSegmentOptions);

            textSegmentsExample.GetValue += delegate { return(feedConfig.PlaylistStyle == PlaylistStyle.Append ? 0 : 1); };
            textSegmentsExample.SetValue += delegate(int value)
            {
                PlaylistStyle newStyle = value == 0 ? PlaylistStyle.Append : PlaylistStyle.Replace;
                if (feedConfig.PlaylistStyle == newStyle)
                {
                    return;
                }
                feedConfig.PlaylistStyle = newStyle;
                // Config.ConfigChanged = true;
            };
            return(feedSubMenu);
        }