Spotify History storing from CLI and inclusion in the front end #50

Merged
Sarsoo merged 3 commits from spotifyhistory into master 2022-10-08 19:59:35 +01:00
4 changed files with 20 additions and 24 deletions
Showing only changes of commit 26b4c3fa64 - Show all commits

View File

@ -121,8 +121,8 @@ namespace Selector.CLI.Extensions
services.AddTransient<IScrobbleRepository, ScrobbleRepository>() services.AddTransient<IScrobbleRepository, ScrobbleRepository>()
.AddTransient<ISpotifyListenRepository, SpotifyListenRepository>(); .AddTransient<ISpotifyListenRepository, SpotifyListenRepository>();
//services.AddTransient<IListenRepository, MetaListenRepository>(); services.AddTransient<IListenRepository, MetaListenRepository>();
services.AddTransient<IListenRepository, SpotifyListenRepository>(); //services.AddTransient<IListenRepository, SpotifyListenRepository>();
services.AddTransient<IScrobbleMappingRepository, ScrobbleMappingRepository>(); services.AddTransient<IScrobbleMappingRepository, ScrobbleMappingRepository>();

View File

@ -1,8 +1,6 @@
using System; using System.Text.Json;
using System.Text.Json;
using Selector.Model;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Diagnostics.Metrics; using Selector.Model;
namespace Selector.Data; namespace Selector.Data;
@ -60,14 +58,16 @@ public class HistoryPersister
{ {
if (Config.InitialClear) 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 user = Db.Users.Single(u => u.UserName == Config.Username);
var counter = 0; 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)) .DistinctBy(x => (x.offline_timestamp, x.ts, x.spotify_track_uri))
.ToArray(); .ToArray();

View File

@ -4,11 +4,6 @@ using System.Linq;
namespace Selector.Model; namespace Selector.Model;
public enum PreferenceMode
{
Greedy, LastFm, Spotify
}
public class MetaListenRepository: IListenRepository public class MetaListenRepository: IListenRepository
{ {
private readonly IScrobbleRepository scrobbleRepository; private readonly IScrobbleRepository scrobbleRepository;
@ -27,10 +22,13 @@ public class MetaListenRepository: IListenRepository
string albumName = null, string albumName = null,
string artistName = null, string artistName = null,
DateTime? from = null, DateTime? from = null,
DateTime? to = null) DateTime? to = null) => GetAll(userId: userId,
{ username: username,
throw new NotImplementedException(); trackName: trackName,
} albumName: albumName,
artistName: artistName,
from: from,
to:to).Count();
public IEnumerable<IListen> GetAll( public IEnumerable<IListen> GetAll(
string includes = null, string includes = null,
@ -62,14 +60,12 @@ public class MetaListenRepository: IListenRepository
albumName: albumName, albumName: albumName,
artistName: artistName, artistName: artistName,
from: from, from: from,
to: to) to: scrobbles.FirstOrDefault()?.Timestamp)
.OrderBy(x => x.Timestamp) .OrderBy(x => x.Timestamp)
.ToArray(); .ToArray();
var scrobbleIter = scrobbles.GetEnumerator();
var spotIter = spotListens.GetEnumerator();
return scrobbles; return spotListens.Concat(scrobbles);
} }
} }

View File

@ -67,8 +67,8 @@ namespace Selector.Web
services.AddTransient<IScrobbleRepository, ScrobbleRepository>() services.AddTransient<IScrobbleRepository, ScrobbleRepository>()
.AddTransient<ISpotifyListenRepository, SpotifyListenRepository>(); .AddTransient<ISpotifyListenRepository, SpotifyListenRepository>();
//services.AddTransient<IListenRepository, MetaListenRepository>(); services.AddTransient<IListenRepository, MetaListenRepository>();
services.AddTransient<IListenRepository, SpotifyListenRepository>(); //services.AddTransient<IListenRepository, SpotifyListenRepository>();
services.AddIdentity<ApplicationUser, IdentityRole>() services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>() .AddEntityFrameworkStores<ApplicationDbContext>()