Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
emulamer committed Jul 17, 2019
1 parent 51f33c5 commit 4b839ad
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 26 deletions.
4 changes: 3 additions & 1 deletion BeatOn/Core/BeatOnCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ private BeatOnConfig CurrentConfig

_currentConfig = new BeatOnConfig()
{
Config = config
Config = config,
SyncConfig = SyncManager.SyncConfig
};

_currentConfig.IsCommitted = !Engine.HasChanges;
_currentConfig.PropertyChanged += CurrentConfig_PropertyChanged;
}
Expand Down
128 changes: 104 additions & 24 deletions BeatOn/SyncConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@ public SyncConfig()
/// </summary>
public string BeastSaberUsername { get; set; }

/// <summary>
/// The last date/time that a sync was run
/// </summary>
public DateTime? LastSyncDate { get; set; }

/// <summary>
/// True to check all existing songs for any updates to the song itself. This will likely be extremely slow.
/// </summary>
public bool CheckExistingSongsUpdated { get; set; } = false;

private ObservableCollection<FeedConfig> _feedReaders;



/// <summary>
/// List of definitions and settings for feed readers that will sync.
Expand Down Expand Up @@ -122,6 +117,32 @@ public Guid ID
}
}

private int _maxSongs = 100;
public int MaxSongs
{
get
{
return _maxSongs;
}
set
{
bool changed = _maxSongs != value;
_maxSongs = value;
if (changed)
PropChanged(nameof(MaxSongs));
}
}

/// <summary>
/// The last date/time that a sync was run
/// </summary>
public DateTime? LastSyncAttempt { get; set; }

/// <summary>
/// The last date/time that a sync was run
/// </summary>
public DateTime? LastSyncSuccess { get; set; }

private bool _isEnabled;

public bool IsEnabled
Expand Down Expand Up @@ -151,9 +172,14 @@ protected void PropChanged(string propName)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}

public Dictionary<string, ScrapedSong> GetSongs()
/// <summary>
/// Keyed Dictionary<PlaylistID, Dictionary<SongHash, scrapedsong>>
/// </summary>
public virtual Dictionary<string, Dictionary<string, ScrapedSong>> GetSongsByPlaylist()
{
return FeedReader.GetSongsFromFeed(FeedSettings);
var dict = new Dictionary<string, Dictionary<string, ScrapedSong>>();
dict.Add(PlaylistID, FeedReader.GetSongsFromFeed(FeedSettings));
return dict;
}
}

Expand Down Expand Up @@ -222,6 +248,76 @@ protected override IFeedReader FeedReader
}
}

public class BeatSaverFeedConfig : FeedConfig
{
private BeatSaverFeeds _feedType;
public BeatSaverFeeds FeedType
{
get
{
return _feedType;
}
set
{
bool changed = value != _feedType;
_feedType = value;
if (changed)
PropChanged(nameof(FeedType));
}
}

public List<string> Authors { get; set; }
public override string PlaylistID => $"SyncService_BeatSaver{FeedType.ToString()}";

public override string DisplayName
{
get
{
switch (FeedType)
{
case BeatSaverFeeds.DOWNLOADS:
return "Top Downloads";
case BeatSaverFeeds.HOT:
return "Hot";
case BeatSaverFeeds.LATEST:
return "Latest";
case BeatSaverFeeds.PLAYS:
return "Top Played";
case BeatSaverFeeds.AUTHOR:
return $"By Authors"; //todo: consider {((Authors == null) ? "(none)" : ((Authors.Count > 1) ? string.Join(", ", Authors) : Authors.First()))}";
case BeatSaverFeeds.SEARCH:
throw new NotImplementedException();
default:
Log.LogErr($"Unhandled Score Saber FeedType {FeedType}");
return "Sync";
}
}
}
private BeatSaverReader _feedReader;
protected override IFeedReader FeedReader
{
get
{
if (_feedReader == null)
_feedReader = new BeatSaverReader();

return _feedReader;
}
}

protected override IFeedSettings FeedSettings
{
get
{
return new BeatSaverFeedSettings((int)FeedType)
{
MaxSongs = MaxSongs,
Authors = Authors?.ToArray()
};
}
}
}

public class ScoreSaberFeedConfig : FeedConfig
{
public override string PlaylistID => $"SyncService_ScoreSaber{FeedType.ToString()}";
Expand All @@ -246,22 +342,6 @@ public override string DisplayName
}
}

private int _maxSongs = 100;
public int MaxSongs
{
get
{
return _maxSongs;
}
set
{
bool changed = _maxSongs != value;
_maxSongs = value;
if (changed)
PropChanged(nameof(MaxSongs));
}
}

private ScoreSaberFeeds _feedType;

public ScoreSaberFeeds FeedType
Expand Down
17 changes: 16 additions & 1 deletion BeatOn/SyncManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void Sync(Guid? onlyID = null)
}
try
{
sync.LastSyncAttempt = DateTime.Now;
var songs = sync.GetSongs();
var playlist = cfg.Config.Playlists.FirstOrDefault(x => x.PlaylistID == sync.PlaylistID);
if (playlist == null)
Expand All @@ -103,7 +104,6 @@ public void Sync(Guid? onlyID = null)
_getConfig().Config = qae.GetCurrentConfig();
cfg = _getConfig();
}
int i = 0;
var toAdd = songs.Where(x => !playlist.SongList.Any(y => y.SongID.ToLower().StartsWith(x.Key.ToLower()))).ToList();
var toRemove = playlist.SongList.Where(x => !songs.Any(y => x.SongID.ToLower().StartsWith(y.Key.ToLower()))).ToList();
toAdd.ForEach(x => {
Expand All @@ -121,6 +121,7 @@ public void Sync(Guid? onlyID = null)
var d = new DeleteSongOp(x.SongID);
qae.OpManager.QueueOp(d);
});
sync.LastSyncSuccess = DateTime.Now;
}
catch (Exception ex)
{
Expand All @@ -134,6 +135,7 @@ public void Sync(Guid? onlyID = null)
Log.LogErr("Exception syncing!", ex);
_showToast($"Failed Sync!", "There was an error syncing.", ClientModels.ToastType.Error, 3);
}
Save();
}

private void LoadConfig()
Expand Down Expand Up @@ -183,11 +185,24 @@ private void SetConfigDefaults()
if (!SyncConfig.FeedReaders.Any(x => (x is ScoreSaberFeedConfig) && (x as ScoreSaberFeedConfig).FeedType == feed))
SyncConfig.FeedReaders.Add(new ScoreSaberFeedConfig() { FeedType = feed, IsEnabled = false });
};

Action<BeatSaverFeeds> checkMakeBV = (BeatSaverFeeds feed) =>
{
if (!SyncConfig.FeedReaders.Any(x => (x is BeatSaverFeedConfig) && (x as BeatSaverFeedConfig).FeedType == feed))
SyncConfig.FeedReaders.Add(new BeatSaverFeedConfig() { FeedType = feed, IsEnabled = false });
};

foreach (BeastSaberFeeds feed in Enum.GetValues(typeof(BeastSaberFeeds)))
checkMakeBS(feed);

foreach (ScoreSaberFeeds feed in Enum.GetValues(typeof(ScoreSaberFeeds)))
checkMakeSS(feed);

foreach (BeatSaverFeeds feed in Enum.GetValues(typeof(BeatSaverFeeds)))
{
if (feed != BeatSaverFeeds.SEARCH)
checkMakeBV(feed);
}
}


Expand Down
8 changes: 8 additions & 0 deletions frontend/src/app/models/ClientSyncSaber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { MessageType, MessageBase } from './MessageBase';

/*Triggers the syncsaberservice to start doing syncs. Setting SyncOnlyID to null will sync all feeds, specifying an ID will sync only that feed */
export class ClientSyncSaber extends MessageBase {
Type: MessageType = MessageType.SyncSaber;

SyncOnlyID: string;
}
10 changes: 10 additions & 0 deletions frontend/src/app/models/ClientUpdateSyncFeedConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MessageType, MessageBase } from './MessageBase';

/*Updates a specific feed configuration. FeedConfig is the configuration data for the feed*/
export class ClientUpdateSyncFeedConfig extends MessageBase {
Type: MessageType = MessageType.UpdateSyncFeedConfig;

ID: string;

FeedConfig: any;
}

0 comments on commit 4b839ad

Please sign in to comment.