2021-11-29 21:04:15 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
using IF.Lastfm.Core.Api;
|
|
|
|
|
|
|
|
|
|
namespace Selector.Cache
|
|
|
|
|
{
|
|
|
|
|
public class PlayCounterCachingFactory: IPlayCounterFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly ILoggerFactory LoggerFactory;
|
|
|
|
|
private readonly IDatabaseAsync Cache;
|
|
|
|
|
private readonly LastfmClient Client;
|
|
|
|
|
private readonly LastFmCredentials Creds;
|
|
|
|
|
|
|
|
|
|
public PlayCounterCachingFactory(
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
IDatabaseAsync cache,
|
|
|
|
|
LastfmClient client = null,
|
|
|
|
|
LastFmCredentials creds = null)
|
|
|
|
|
{
|
|
|
|
|
LoggerFactory = loggerFactory;
|
|
|
|
|
Cache = cache;
|
|
|
|
|
Client = client;
|
|
|
|
|
Creds = creds;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 07:30:27 +01:00
|
|
|
|
public Task<IPlayerConsumer> Get(LastfmClient fmClient = null, LastFmCredentials creds = null, IPlayerWatcher watcher = null)
|
2021-11-29 21:04:15 +00:00
|
|
|
|
{
|
|
|
|
|
var client = fmClient ?? Client;
|
|
|
|
|
|
|
|
|
|
if (client is null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("No Last.fm client provided");
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 07:30:27 +01:00
|
|
|
|
return Task.FromResult<IPlayerConsumer>(new PlayCounterCaching(
|
2021-11-29 21:04:15 +00:00
|
|
|
|
watcher,
|
|
|
|
|
client.Track,
|
|
|
|
|
client.Album,
|
|
|
|
|
client.Artist,
|
|
|
|
|
client.User,
|
|
|
|
|
Cache,
|
|
|
|
|
credentials: creds ?? Creds,
|
|
|
|
|
logger: LoggerFactory.CreateLogger<PlayCounterCaching>()
|
2022-02-25 18:32:43 +00:00
|
|
|
|
));
|
2021-11-29 21:04:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|