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;
}
IdentifyDuplicates(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
.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 PlayCountPuller PlayCountPuller;
private readonly ApplicationDbContext Db;
private readonly IScrobbleRepository ScrobbleRepository;
public NowPlayingHub(
IDatabaseAsync cache,
AudioFeaturePuller featurePuller,
ApplicationDbContext db,
IScrobbleRepository scrobbleRepository,
PlayCountPuller playCountPuller = null
)
{
@ -40,6 +42,7 @@ namespace Selector.Web.Hubs
AudioFeaturePuller = featurePuller;
PlayCountPuller = playCountPuller;
Db = db;
ScrobbleRepository = scrobbleRepository;
}
public async Task OnConnected()
@ -89,10 +92,15 @@ namespace Selector.Web.Hubs
.SingleOrDefault()
?? throw new SqlNullValueException("No user returned");
if(user.LastFmConnected())
if (user.LastFmConnected())
{
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)
{
await Clients.Caller.OnNewPlayCount(playCount);

View File

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

View File

@ -17,7 +17,7 @@ namespace Selector
/// </summary>
/// <param name="watcher">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>
/// Start watcher collection

View File

@ -43,7 +43,7 @@ namespace Selector
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);
if (IsRunning) context.Start();

View File

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