Skip to content

Commit 90a0f42

Browse files
committed
Update TidalCommand --ignore-artist-album-amount
1 parent cffe468 commit 90a0f42

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

MiniMediaScanner/Commands/UpdateTidalCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public class UpdateTidalCommand : ICommand
7474
IsRequired = false,
7575
EnvironmentVariable = "UPDATETIDAL_NONPULLED_ARTISTS")]
7676
public bool UpdateNonpulledArtists { get; set; }
77+
78+
[CommandOption("ignore-artist-album-amount",
79+
Description = "Ignore artists that have over a certain amount of albums, >500 albums is not normal",
80+
IsRequired = false,
81+
EnvironmentVariable = "UPDATETIDAL_IGNORE_ARTIST_ALBUM_AMOUNT")]
82+
public int IgnoreArtistAlbumAmount { get; set; } = 500;
7783

7884
public async ValueTask ExecuteAsync(IConsole console)
7985
{
@@ -96,7 +102,8 @@ public async ValueTask ExecuteAsync(IConsole console)
96102
ProxyFile,
97103
Proxy,
98104
ProxyMode,
99-
PreventUpdateWithinDays);
105+
PreventUpdateWithinDays,
106+
IgnoreArtistAlbumAmount);
100107

101108
if (!string.IsNullOrWhiteSpace(ArtistFilePath) && File.Exists(ArtistFilePath))
102109
{

MiniMediaScanner/Commands/UpdateTidalCommandHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ public UpdateTidalCommandHandler(string connectionString,
1818
string proxyFile,
1919
string singleProxy,
2020
string proxyMode,
21-
int preventUpdateWithinDays)
21+
int preventUpdateWithinDays,
22+
int ignoreArtistAlbumAmount)
2223
{
2324
_tidalRepository = new TidalRepository(connectionString);
24-
_tidalService = new TidalService(connectionString, secretTokens, countryCode, proxyFile, singleProxy, proxyMode, preventUpdateWithinDays);
25+
_tidalService = new TidalService(connectionString, secretTokens, countryCode, proxyFile, singleProxy, proxyMode, preventUpdateWithinDays, ignoreArtistAlbumAmount);
2526
}
2627

2728
public async Task UpdateTidalArtistsByNameAsync(string artistName)

MiniMediaScanner/Services/TidalService.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@
33
using MiniMediaScanner.Callbacks;
44
using MiniMediaScanner.Callbacks.Status;
55
using MiniMediaScanner.Enums;
6+
using MiniMediaScanner.Helpers;
67
using MiniMediaScanner.Models.Tidal;
78
using MiniMediaScanner.Repositories;
9+
using Spectre.Console;
810

911
namespace MiniMediaScanner.Services;
1012

1113
public class TidalService
1214
{
1315
public readonly int PreventUpdateWithinDays;
1416
private readonly TidalAPICacheLayerService _tidalAPIService;
15-
private readonly UpdateTidalRepository _updateTidalRepository;
17+
private readonly string _connectionString;
18+
private readonly int _ignoreArtistAlbumAmount;
1619

1720
public TidalService(string connectionString,
1821
List<TidalTokenClientSecret> secretTokens,
1922
string countryCode,
2023
string proxyFile,
2124
string singleProxy,
2225
string proxyMode,
23-
int preventUpdateWithinDays)
26+
int preventUpdateWithinDays,
27+
int ignoreArtistAlbumAmount)
2428
{
29+
_ignoreArtistAlbumAmount = ignoreArtistAlbumAmount;
30+
_connectionString = connectionString;
2531
this.PreventUpdateWithinDays = preventUpdateWithinDays;
26-
_updateTidalRepository = new UpdateTidalRepository(connectionString);
2732
_tidalAPIService = new TidalAPICacheLayerService(secretTokens, countryCode, proxyFile, singleProxy, proxyMode);
2833
}
2934

@@ -65,6 +70,7 @@ public async Task UpdateArtistByNameAsync(string artistName,
6570
public async Task UpdateArtistByIdAsync(int artistId,
6671
Action<UpdateTidalCallback>? callback = null)
6772
{
73+
UpdateTidalRepository _updateTidalRepository = new UpdateTidalRepository(_connectionString);
6874
await _updateTidalRepository.SetConnectionAsync();
6975

7076
try
@@ -115,6 +121,12 @@ public async Task UpdateArtistByIdAsync(int artistId,
115121
.Where(x => x.Type == "albums")
116122
.ToList();
117123

124+
if (albums.Count >= _ignoreArtistAlbumAmount)
125+
{
126+
await _updateTidalRepository.CommitAsync();
127+
return;
128+
}
129+
118130
int progress = 1;
119131
foreach (var album in albums)
120132
{
@@ -371,11 +383,14 @@ await _updateTidalRepository.UpsertTrackAsync(int.Parse(track.Id),
371383

372384
private async Task<TidalSearchResponse?> InsertArtistInfoAsync(int artistId, bool ignorePeventCheck = false)
373385
{
386+
UpdateTidalRepository _updateTidalRepository = new UpdateTidalRepository(_connectionString);
387+
await _updateTidalRepository.SetConnectionAsync();
374388
if (!ignorePeventCheck)
375389
{
376390
DateTime? lastSyncTime = await _updateTidalRepository.GetArtistLastSyncTimeAsync(artistId);
377391
if (lastSyncTime?.Year > 2000 && DateTime.Now.Subtract(lastSyncTime.Value).TotalDays < PreventUpdateWithinDays)
378392
{
393+
await _updateTidalRepository.CommitAsync();
379394
return null;
380395
}
381396
}
@@ -386,6 +401,7 @@ await _updateTidalRepository.UpsertTrackAsync(int.Parse(track.Id),
386401
artistInfo?.Data == null ||
387402
artistInfo?.Included == null)
388403
{
404+
await _updateTidalRepository.CommitAsync();
389405
return null;
390406
}
391407

@@ -406,6 +422,7 @@ await _updateTidalRepository.UpsertArtistImageLinkAsync(artistId,
406422
imageLink.Meta.Height);
407423
}
408424

425+
await _updateTidalRepository.CommitAsync();
409426
return artistInfo;
410427
}
411428
}

0 commit comments

Comments
 (0)