2021-10-29 22:35:34 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
using SpotifyAPI.Web;
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
|
|
namespace Selector.Cache
|
2021-11-29 21:04:15 +00:00
|
|
|
{
|
|
|
|
public class CachingAudioFeatureInjectorFactory: IAudioFeatureInjectorFactory {
|
2021-10-29 22:35:34 +01:00
|
|
|
|
|
|
|
private readonly ILoggerFactory LoggerFactory;
|
|
|
|
private readonly IDatabaseAsync Db;
|
|
|
|
|
|
|
|
public CachingAudioFeatureInjectorFactory(
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
IDatabaseAsync db
|
|
|
|
) {
|
|
|
|
LoggerFactory = loggerFactory;
|
|
|
|
Db = db;
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:30:27 +01:00
|
|
|
public async Task<IPlayerConsumer> Get(ISpotifyConfigFactory spotifyFactory, IPlayerWatcher watcher = null)
|
2021-10-29 22:35:34 +01:00
|
|
|
{
|
2023-01-25 20:52:59 +00:00
|
|
|
if (!Magic.Dummy)
|
|
|
|
{
|
|
|
|
var config = await spotifyFactory.GetConfig();
|
|
|
|
var client = new SpotifyClient(config);
|
2021-10-29 22:35:34 +01:00
|
|
|
|
2023-01-25 20:52:59 +00:00
|
|
|
return new CachingAudioFeatureInjector(
|
|
|
|
watcher,
|
|
|
|
Db,
|
|
|
|
client.Tracks,
|
|
|
|
LoggerFactory.CreateLogger<CachingAudioFeatureInjector>()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new DummyAudioFeatureInjector(
|
|
|
|
watcher,
|
|
|
|
LoggerFactory.CreateLogger<DummyAudioFeatureInjector>()
|
|
|
|
);
|
|
|
|
}
|
2021-10-29 22:35:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|