injecting artist scrobble count

removing all now playings from pages
This commit is contained in:
andy 2022-02-24 23:32:02 +00:00
parent abf22f6cf9
commit d6e720ed72
6 changed files with 18 additions and 9 deletions

View File

@ -97,11 +97,11 @@ namespace Selector
scrobbles = page1.Scrobbles; scrobbles = page1.Scrobbles;
} }
IdentifyDuplicates(scrobbles);
logger.LogDebug("Ordering and filtering pulled scrobbles"); logger.LogDebug("Ordering and filtering pulled scrobbles");
scrobbles = RemoveNowPlaying(scrobbles); scrobbles = scrobbles.Where(s => !(s.IsNowPlaying is bool playing && playing));
IdentifyDuplicates(scrobbles);
var nativeScrobbles = scrobbles var nativeScrobbles = scrobbles
.DistinctBy(s => new { s.TimePlayed?.UtcDateTime, s.Name, s.ArtistName }) .DistinctBy(s => new { s.TimePlayed?.UtcDateTime, s.Name, s.ArtistName })

View File

@ -28,11 +28,13 @@ namespace Selector.Web.Hubs
private readonly AudioFeaturePuller AudioFeaturePuller; private readonly AudioFeaturePuller AudioFeaturePuller;
private readonly PlayCountPuller PlayCountPuller; private readonly PlayCountPuller PlayCountPuller;
private readonly ApplicationDbContext Db; private readonly ApplicationDbContext Db;
private readonly IScrobbleRepository ScrobbleRepository;
public NowPlayingHub( public NowPlayingHub(
IDatabaseAsync cache, IDatabaseAsync cache,
AudioFeaturePuller featurePuller, AudioFeaturePuller featurePuller,
ApplicationDbContext db, ApplicationDbContext db,
IScrobbleRepository scrobbleRepository,
PlayCountPuller playCountPuller = null PlayCountPuller playCountPuller = null
) )
{ {
@ -40,6 +42,7 @@ namespace Selector.Web.Hubs
AudioFeaturePuller = featurePuller; AudioFeaturePuller = featurePuller;
PlayCountPuller = playCountPuller; PlayCountPuller = playCountPuller;
Db = db; Db = db;
ScrobbleRepository = scrobbleRepository;
} }
public async Task OnConnected() public async Task OnConnected()
@ -89,10 +92,15 @@ namespace Selector.Web.Hubs
.SingleOrDefault() .SingleOrDefault()
?? throw new SqlNullValueException("No user returned"); ?? throw new SqlNullValueException("No user returned");
if(user.LastFmConnected()) if (user.LastFmConnected())
{ {
var playCount = await PlayCountPuller.Get(user.LastFmUsername, track, artist, album, albumArtist); var playCount = await PlayCountPuller.Get(user.LastFmUsername, track, artist, album, albumArtist);
if (user.ScrobbleSavingEnabled())
{
playCount.Artist = ScrobbleRepository.GetAll(userId: user.Id, artistName: artist).Count();
}
if (playCount is not null) if (playCount is not null)
{ {
await Clients.Caller.OnNewPlayCount(playCount); await Clients.Caller.OnNewPlayCount(playCount);

View File

@ -54,6 +54,7 @@ namespace Selector.Web
services.AddDbContext<ApplicationDbContext>(options => services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("Default")) options.UseNpgsql(Configuration.GetConnectionString("Default"))
); );
services.AddTransient<IScrobbleRepository, ScrobbleRepository>();
services.AddIdentity<ApplicationUser, IdentityRole>() services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>() .AddEntityFrameworkStores<ApplicationDbContext>()

View File

@ -17,7 +17,7 @@ namespace Selector
/// </summary> /// </summary>
/// <param name="watcher">New watcher</param> /// <param name="watcher">New watcher</param>
/// <param name="consumers">Consumers to subscribe to new watcher</param> /// <param name="consumers">Consumers to subscribe to new watcher</param>
public IWatcherContext Add(IWatcher watcher, List<IConsumer> consumers); public IWatcherContext Add(IWatcher watcher, IEnumerable<IConsumer> consumers);
/// <summary> /// <summary>
/// Start watcher collection /// Start watcher collection

View File

@ -43,7 +43,7 @@ namespace Selector
return Add(watcher, default); return Add(watcher, default);
} }
public IWatcherContext Add(IWatcher watcher, List<IConsumer> consumers) public IWatcherContext Add(IWatcher watcher, IEnumerable<IConsumer> consumers)
{ {
var context = WatcherContext.From(watcher, consumers); var context = WatcherContext.From(watcher, consumers);
if (IsRunning) context.Start(); if (IsRunning) context.Start();

View File

@ -24,10 +24,10 @@ namespace Selector
Watcher = watcher; Watcher = watcher;
} }
public WatcherContext(IWatcher watcher, List<IConsumer> consumers) public WatcherContext(IWatcher watcher, IEnumerable<IConsumer> consumers)
{ {
Watcher = watcher; Watcher = watcher;
Consumers = consumers ?? new(); Consumers = consumers.ToList() ?? new();
} }
public static WatcherContext From(IWatcher watcher) public static WatcherContext From(IWatcher watcher)
@ -35,7 +35,7 @@ namespace Selector
return new(watcher); return new(watcher);
} }
public static WatcherContext From(IWatcher watcher, List<IConsumer> consumers) public static WatcherContext From(IWatcher watcher, IEnumerable<IConsumer> consumers)
{ {
return new(watcher, consumers); return new(watcher, consumers);
} }