-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,60 @@ | ||
using System.Threading; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AzzyBot.Database; | ||
using AzzyBot.Database.Entities; | ||
using AzzyBot.Logging; | ||
using AzzyBot.Services.Interfaces; | ||
using AzzyBot.Utilities.Encryption; | ||
using AzzyBot.Utilities.Records.AzuraCast; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace AzzyBot.Services.Modules; | ||
|
||
public sealed class AzuraCastFileService(IHostApplicationLifetime applicationLifetime, ILogger<AzuraCastFileService> logger, IQueuedBackgroundTask taskQueue, AzuraCastService azuraCast) | ||
public sealed class AzuraCastFileService(IHostApplicationLifetime applicationLifetime, ILogger<AzuraCastFileService> logger, IQueuedBackgroundTask taskQueue, AzuraCastApiService azuraCast, DbActions dbActions) | ||
{ | ||
private readonly ILogger<AzuraCastFileService> _logger = logger; | ||
private readonly IQueuedBackgroundTask _taskQueue = taskQueue; | ||
Check warning on line 19 in AzzyBot-Next/Services/Modules/AzuraCastFileService.cs GitHub Actions / Build DEBUG for linux - x64
Check warning on line 19 in AzzyBot-Next/Services/Modules/AzuraCastFileService.cs GitHub Actions / Build DEBUG for linux - arm64
Check warning on line 19 in AzzyBot-Next/Services/Modules/AzuraCastFileService.cs GitHub Actions / Build DEBUG for win - x64
|
||
private readonly AzuraCastService _azuraCast = azuraCast; | ||
private readonly AzuraCastApiService _azuraCast = azuraCast; | ||
private readonly DbActions _dbActions = dbActions; | ||
private readonly CancellationToken _cancellationToken = applicationLifetime.ApplicationStopping; | ||
|
||
public void StartAzuraCastFileService() | ||
{ | ||
_logger.AzuraCastFileServiceStarted(); | ||
_logger.AzuraCastFileServiceStart(); | ||
|
||
return; | ||
Task.Run(async () => await BuildWorkItemAsync(_cancellationToken), _cancellationToken); | ||
} | ||
|
||
private async ValueTask BuildWorkItemAsync(CancellationToken cancellationToken) | ||
public async ValueTask BuildWorkItemAsync(CancellationToken cancellationToken) | ||
{ | ||
_logger.AzuraCastFileServiceWorkItem(); | ||
|
||
while (!cancellationToken.IsCancellationRequested) | ||
{ | ||
try | ||
{ | ||
foreach (GuildsEntity guild in await _dbActions.GetGuildsAsync()) | ||
{ | ||
if (guild.AzuraCast is null) | ||
continue; | ||
|
||
AzuraCastEntity azuraCast = guild.AzuraCast; | ||
foreach (AzuraCastStationEntity station in azuraCast.Stations) | ||
{ | ||
IReadOnlyList<FilesRecord> onlineFiles = await _azuraCast.GetFilesOnlineAsync(new(Crypto.Decrypt(azuraCast.BaseUrl)), Crypto.Decrypt(station.ApiKey), station.StationId); | ||
IReadOnlyList<FilesRecord> localFiles = await _azuraCast.GetFilesLocalAsync(station.Id, station.StationId); | ||
|
||
|
||
} | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ } | ||
} | ||
|
||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AzzyBot.Utilities.Records.AzuraCast; | ||
|
||
public sealed record FilesRecord | ||
{ | ||
[JsonPropertyName("unique_id")] | ||
public required string UniqueId { get; init; } | ||
|
||
[JsonPropertyName("path")] | ||
public required string Path { get; init; } | ||
|
||
[JsonPropertyName("song_id")] | ||
public required string SongId { get; init; } | ||
|
||
[JsonPropertyName("artist")] | ||
public required string Artist { get; init; } | ||
|
||
[JsonPropertyName("title")] | ||
public required string Title { get; init; } | ||
|
||
[JsonPropertyName("album")] | ||
public string Album { get; init; } = string.Empty; | ||
} |