adding consumer, changing default poll period

This commit is contained in:
Andy Pack 2025-04-02 08:28:39 +01:00
parent bfc7a0db34
commit b3ae8e65ac
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
4 changed files with 21 additions and 7 deletions
Selector.AppleMusic/Watcher
Selector.CLI/Services
Selector.Event/Consumers
Selector.LastFm/Extensions

@ -6,7 +6,7 @@ namespace Selector.AppleMusic.Watcher
public interface IAppleMusicWatcherFactory public interface IAppleMusicWatcherFactory
{ {
Task<IWatcher> Get<T>(AppleMusicApiProvider appleMusicProvider, string developerToken, string teamId, Task<IWatcher> Get<T>(AppleMusicApiProvider appleMusicProvider, string developerToken, string teamId,
string keyId, string userToken, string id = null, int pollPeriod = 3000) string keyId, string userToken, string id = null, int pollPeriod = 10000)
where T : class, IWatcher; where T : class, IWatcher;
} }
@ -22,7 +22,7 @@ namespace Selector.AppleMusic.Watcher
} }
public async Task<IWatcher> Get<T>(AppleMusicApiProvider appleMusicProvider, string developerToken, public async Task<IWatcher> Get<T>(AppleMusicApiProvider appleMusicProvider, string developerToken,
string teamId, string keyId, string userToken, string id = null, int pollPeriod = 3000) string teamId, string keyId, string userToken, string id = null, int pollPeriod = 10000)
where T : class, IWatcher where T : class, IWatcher
{ {
if (typeof(T).IsAssignableFrom(typeof(AppleMusicPlayerWatcher))) if (typeof(T).IsAssignableFrom(typeof(AppleMusicPlayerWatcher)))

@ -161,7 +161,7 @@ namespace Selector.CLI
if (MappingPersisterFactory is not null && !Magic.Dummy) if (MappingPersisterFactory is not null && !Magic.Dummy)
consumers.Add(await MappingPersisterFactory.Get()); consumers.Add(await MappingPersisterFactory.Get());
if (UserEventFirerFactory is not null) consumers.Add(await UserEventFirerFactory.Get()); if (UserEventFirerFactory is not null) consumers.Add(await UserEventFirerFactory.GetSpotify());
if (dbWatcher.User.LastFmConnected()) if (dbWatcher.User.LastFmConnected())
{ {
@ -187,6 +187,8 @@ namespace Selector.CLI
if (CacheWriterFactory is not null) consumers.Add(await CacheWriterFactory.GetApple()); if (CacheWriterFactory is not null) consumers.Add(await CacheWriterFactory.GetApple());
if (PublisherFactory is not null) consumers.Add(await PublisherFactory.GetApple()); if (PublisherFactory is not null) consumers.Add(await PublisherFactory.GetApple());
if (UserEventFirerFactory is not null) consumers.Add(await UserEventFirerFactory.GetApple());
break; break;
} }

@ -5,7 +5,8 @@ namespace Selector.Events
{ {
public interface IUserEventFirerFactory public interface IUserEventFirerFactory
{ {
public Task<SpotifyUserEventFirer> Get(ISpotifyPlayerWatcher watcher = null); public Task<SpotifyUserEventFirer> GetSpotify(ISpotifyPlayerWatcher watcher = null);
public Task<AppleUserEventFirer> GetApple(IAppleMusicPlayerWatcher watcher = null);
} }
public class UserEventFirerFactory : IUserEventFirerFactory public class UserEventFirerFactory : IUserEventFirerFactory
@ -19,7 +20,7 @@ namespace Selector.Events
UserEvent = userEvent; UserEvent = userEvent;
} }
public Task<SpotifyUserEventFirer> Get(ISpotifyPlayerWatcher watcher = null) public Task<SpotifyUserEventFirer> GetSpotify(ISpotifyPlayerWatcher watcher = null)
{ {
return Task.FromResult(new SpotifyUserEventFirer( return Task.FromResult(new SpotifyUserEventFirer(
watcher, watcher,
@ -27,5 +28,14 @@ namespace Selector.Events
LoggerFactory.CreateLogger<SpotifyUserEventFirer>() LoggerFactory.CreateLogger<SpotifyUserEventFirer>()
)); ));
} }
public Task<AppleUserEventFirer> GetApple(IAppleMusicPlayerWatcher watcher = null)
{
return Task.FromResult(new AppleUserEventFirer(
watcher,
UserEvent,
LoggerFactory.CreateLogger<AppleUserEventFirer>()
));
}
} }
} }

@ -1,4 +1,5 @@
using IF.Lastfm.Core.Api; using IF.Lastfm.Core.Api;
using IF.Lastfm.Core.Scrobblers;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Selector.Extensions; namespace Selector.Extensions;
@ -7,8 +8,7 @@ public static class ServiceExtensions
{ {
public static IServiceCollection AddLastFm(this IServiceCollection services, string client, string secret) public static IServiceCollection AddLastFm(this IServiceCollection services, string client, string secret)
{ {
var lastAuth = new LastAuth(client, secret); services.AddTransient(sp => new LastAuth(client, secret));
services.AddSingleton(lastAuth);
services.AddTransient(sp => new LastfmClient(sp.GetService<LastAuth>())); services.AddTransient(sp => new LastfmClient(sp.GetService<LastAuth>()));
services.AddTransient<ITrackApi>(sp => sp.GetService<LastfmClient>().Track); services.AddTransient<ITrackApi>(sp => sp.GetService<LastfmClient>().Track);
@ -21,6 +21,8 @@ public static class ServiceExtensions
services.AddTransient<ILibraryApi>(sp => sp.GetService<LastfmClient>().Library); services.AddTransient<ILibraryApi>(sp => sp.GetService<LastfmClient>().Library);
services.AddTransient<ITagApi>(sp => sp.GetService<LastfmClient>().Tag); services.AddTransient<ITagApi>(sp => sp.GetService<LastfmClient>().Tag);
services.AddTransient<IScrobbler, MemoryScrobbler>();
return services; return services;
} }
} }