2022-02-16 23:38:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-10-24 17:38:45 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-02-26 21:28:51 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-10-11 23:19:19 +01:00
|
|
|
|
|
2021-10-11 18:17:36 +01:00
|
|
|
|
namespace Selector.CLI
|
|
|
|
|
{
|
2021-10-24 17:38:45 +01:00
|
|
|
|
static class OptionsHelper {
|
|
|
|
|
public static void ConfigureOptions(RootOptions options, IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
config.GetSection(RootOptions.Key).Bind(options);
|
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, WatcherOptions.Key})).Bind(options.WatcherOptions);
|
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, DatabaseOptions.Key})).Bind(options.DatabaseOptions);
|
2021-10-27 23:00:01 +01:00
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, RedisOptions.Key})).Bind(options.RedisOptions);
|
2022-02-25 21:07:22 +00:00
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, JobsOptions.Key})).Bind(options.JobOptions);
|
2022-02-26 21:28:51 +00:00
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, JobsOptions.Key, ScrobbleWatcherJobOptions.Key })).Bind(options.JobOptions.Scrobble);
|
2021-10-24 17:38:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 00:08:42 +00:00
|
|
|
|
public static RootOptions ConfigureOptions(this IConfiguration config)
|
2021-10-24 17:38:45 +01:00
|
|
|
|
{
|
|
|
|
|
var options = config.GetSection(RootOptions.Key).Get<RootOptions>();
|
2022-02-26 21:28:51 +00:00
|
|
|
|
|
2021-10-24 17:38:45 +01:00
|
|
|
|
ConfigureOptions(options, config);
|
2022-02-26 21:28:51 +00:00
|
|
|
|
|
2021-10-24 17:38:45 +01:00
|
|
|
|
return options;
|
2022-02-26 21:28:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RootOptions ConfigureOptionsInjection(this IConfiguration config, IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
var options = config.GetSection(RootOptions.Key).Get<RootOptions>();
|
|
|
|
|
|
|
|
|
|
services.Configure<DatabaseOptions>(config.GetSection(FormatKeys(new[] { RootOptions.Key, DatabaseOptions.Key })));
|
|
|
|
|
services.Configure<RedisOptions>(config.GetSection(FormatKeys(new[] { RootOptions.Key, RedisOptions.Key })));
|
|
|
|
|
services.Configure<WatcherOptions>(config.GetSection(FormatKeys(new[] { RootOptions.Key, WatcherOptions.Key })));
|
|
|
|
|
|
|
|
|
|
services.Configure<JobsOptions>(config.GetSection(FormatKeys(new[] { RootOptions.Key, JobsOptions.Key })));
|
|
|
|
|
services.Configure<ScrobbleWatcherJobOptions>(config.GetSection(FormatKeys(new[] { RootOptions.Key, JobsOptions.Key, ScrobbleWatcherJobOptions.Key })));
|
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
2021-10-24 17:38:45 +01:00
|
|
|
|
|
|
|
|
|
public static string FormatKeys(string[] args) => string.Join(":", args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public class RootOptions
|
2021-10-11 18:17:36 +01:00
|
|
|
|
{
|
|
|
|
|
public const string Key = "Selector";
|
|
|
|
|
|
2021-10-11 23:19:19 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spotify client ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientId { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spotify app secret
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientSecret { get; set; }
|
2022-02-24 00:27:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Service account refresh token for tool spotify usage
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string RefreshToken { get; set; }
|
2021-10-31 08:54:11 +00:00
|
|
|
|
public string LastfmClient { get; set; }
|
|
|
|
|
public string LastfmSecret { get; set; }
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public WatcherOptions WatcherOptions { get; set; } = new();
|
2022-02-25 21:07:22 +00:00
|
|
|
|
public JobsOptions JobOptions { get; set; } = new();
|
2021-10-24 17:38:45 +01:00
|
|
|
|
public DatabaseOptions DatabaseOptions { get; set; } = new();
|
2021-10-27 23:00:01 +01:00
|
|
|
|
public RedisOptions RedisOptions { get; set; } = new();
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public EqualityChecker Equality { get; set; } = EqualityChecker.Uri;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public enum EqualityChecker
|
2021-10-11 23:19:19 +01:00
|
|
|
|
{
|
|
|
|
|
Uri, String
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public class WatcherOptions
|
2021-10-11 23:19:19 +01:00
|
|
|
|
{
|
|
|
|
|
public const string Key = "Watcher";
|
|
|
|
|
|
2021-10-13 23:19:47 +01:00
|
|
|
|
public bool Enabled { get; set; } = true;
|
2021-11-25 18:26:20 +00:00
|
|
|
|
public bool LocalEnabled { get; set; } = true;
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public List<WatcherInstanceOptions> Instances { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public class WatcherInstanceOptions
|
2021-10-11 23:19:19 +01:00
|
|
|
|
{
|
|
|
|
|
public const string Key = "Instances";
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string AccessKey { get; set; }
|
|
|
|
|
public string RefreshKey { get; set; }
|
2021-10-31 08:54:11 +00:00
|
|
|
|
public string LastFmUsername { get; set; }
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public int PollPeriod { get; set; } = 5000;
|
|
|
|
|
public WatcherType Type { get; set; } = WatcherType.Player;
|
2021-10-13 23:19:47 +01:00
|
|
|
|
public List<Consumers> Consumers { get; set; } = default;
|
2021-10-12 20:23:25 +01:00
|
|
|
|
#nullable enable
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public string? PlaylistUri { get; set; }
|
2021-10-12 23:29:05 +01:00
|
|
|
|
public string? WatcherCollection { get; set; }
|
2021-10-12 20:23:25 +01:00
|
|
|
|
#nullable disable
|
2021-10-11 23:19:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public enum Consumers
|
2021-10-13 23:19:47 +01:00
|
|
|
|
{
|
2021-10-31 08:54:11 +00:00
|
|
|
|
AudioFeatures, AudioFeaturesCache, CacheWriter, Publisher, PlayCounter
|
2021-10-13 23:19:47 +01:00
|
|
|
|
}
|
2021-10-24 17:38:45 +01:00
|
|
|
|
|
2021-11-29 21:04:15 +00:00
|
|
|
|
public class RedisOptions
|
2021-10-27 23:00:01 +01:00
|
|
|
|
{
|
|
|
|
|
public const string Key = "Redis";
|
|
|
|
|
|
|
|
|
|
public bool Enabled { get; set; } = false;
|
|
|
|
|
public string ConnectionString { get; set; }
|
|
|
|
|
}
|
2022-02-16 23:38:45 +00:00
|
|
|
|
|
2022-02-25 21:07:22 +00:00
|
|
|
|
public class JobsOptions
|
2022-02-16 23:38:45 +00:00
|
|
|
|
{
|
2022-02-25 21:07:22 +00:00
|
|
|
|
public const string Key = "Job";
|
2022-02-16 23:38:45 +00:00
|
|
|
|
|
|
|
|
|
public bool Enabled { get; set; } = true;
|
2022-02-25 21:07:22 +00:00
|
|
|
|
public ScrobbleWatcherJobOptions Scrobble { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ScrobbleWatcherJobOptions
|
|
|
|
|
{
|
|
|
|
|
public const string Key = "Scrobble";
|
|
|
|
|
|
2022-02-26 21:28:51 +00:00
|
|
|
|
public bool Enabled { get; set; } = true;
|
2022-02-26 23:42:29 +00:00
|
|
|
|
public string FullScrobbleCron { get; set; } = "0 2 * * * ?";
|
2022-02-25 21:07:22 +00:00
|
|
|
|
public TimeSpan InterJobDelay { get; set; } = TimeSpan.FromMinutes(5);
|
|
|
|
|
public TimeSpan InterRequestDelay { get; set; } = TimeSpan.FromMilliseconds(100);
|
|
|
|
|
public DateTime? From { get; set; } = DateTime.UtcNow.AddDays(-14);
|
|
|
|
|
public int PageSize { get; set; } = 200;
|
|
|
|
|
public int Simultaneous { get; set; } = 3;
|
2022-02-16 23:38:45 +00:00
|
|
|
|
}
|
2021-10-11 18:17:36 +01:00
|
|
|
|
}
|