diff --git a/Selector.CLI/Extensions/ServiceExtensions.cs b/Selector.CLI/Extensions/ServiceExtensions.cs index 0f155c3..5273460 100644 --- a/Selector.CLI/Extensions/ServiceExtensions.cs +++ b/Selector.CLI/Extensions/ServiceExtensions.cs @@ -121,8 +121,8 @@ namespace Selector.CLI.Extensions services.AddTransient() .AddTransient(); - //services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); services.AddTransient(); diff --git a/Selector.Data/HistoryPersister.cs b/Selector.Data/HistoryPersister.cs index f9e3cc5..e01d1cd 100644 --- a/Selector.Data/HistoryPersister.cs +++ b/Selector.Data/HistoryPersister.cs @@ -1,8 +1,6 @@ -using System; -using System.Text.Json; -using Selector.Model; +using System.Text.Json; using Microsoft.Extensions.Logging; -using System.Diagnostics.Metrics; +using Selector.Model; namespace Selector.Data; @@ -60,14 +58,16 @@ public class HistoryPersister { if (Config.InitialClear) { - Db.SpotifyListen.RemoveRange(Db.SpotifyListen.Where(x => x.User.UserName == Config.Username)); + var latestTime = input.OrderBy(x => x.ts).Last().ts; + var time = DateTime.Parse(latestTime).ToUniversalTime(); + Db.SpotifyListen.RemoveRange(Db.SpotifyListen.Where(x => x.User.UserName == Config.Username && x.Timestamp <= time)); } var user = Db.Users.Single(u => u.UserName == Config.Username); var counter = 0; - var filtered = input.Where(x => x.ms_played > 20000) + var filtered = input.Where(x => x.ms_played > 30000) .DistinctBy(x => (x.offline_timestamp, x.ts, x.spotify_track_uri)) .ToArray(); diff --git a/Selector.Model/Listen/MetaListenRepository.cs b/Selector.Model/Listen/MetaListenRepository.cs index fa997c7..97ed5c2 100644 --- a/Selector.Model/Listen/MetaListenRepository.cs +++ b/Selector.Model/Listen/MetaListenRepository.cs @@ -4,11 +4,6 @@ using System.Linq; namespace Selector.Model; -public enum PreferenceMode -{ - Greedy, LastFm, Spotify -} - public class MetaListenRepository: IListenRepository { private readonly IScrobbleRepository scrobbleRepository; @@ -27,10 +22,13 @@ public class MetaListenRepository: IListenRepository string albumName = null, string artistName = null, DateTime? from = null, - DateTime? to = null) - { - throw new NotImplementedException(); - } + DateTime? to = null) => GetAll(userId: userId, + username: username, + trackName: trackName, + albumName: albumName, + artistName: artistName, + from: from, + to:to).Count(); public IEnumerable GetAll( string includes = null, @@ -62,14 +60,12 @@ public class MetaListenRepository: IListenRepository albumName: albumName, artistName: artistName, from: from, - to: to) + to: scrobbles.FirstOrDefault()?.Timestamp) .OrderBy(x => x.Timestamp) .ToArray(); + - var scrobbleIter = scrobbles.GetEnumerator(); - var spotIter = spotListens.GetEnumerator(); - - return scrobbles; + return spotListens.Concat(scrobbles); } } diff --git a/Selector.Web/Startup.cs b/Selector.Web/Startup.cs index dd82986..aea55db 100644 --- a/Selector.Web/Startup.cs +++ b/Selector.Web/Startup.cs @@ -67,8 +67,8 @@ namespace Selector.Web services.AddTransient() .AddTransient(); - //services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); services.AddIdentity() .AddEntityFrameworkStores()