mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
LastFM fixes for bad tracks, now throwing meaningful excpetions from SimpleContract.
This commit is contained in:
parent
ad85bea25a
commit
8aca45a864
5 changed files with 47 additions and 20 deletions
|
@ -2,6 +2,7 @@
|
|||
using Roadie.Library.Configuration;
|
||||
using Roadie.Library.Extensions;
|
||||
using Roadie.Library.Utility;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
|
@ -155,5 +156,33 @@ namespace Roadie.Library.Tests
|
|||
var t = new DirectoryInfo(Path.Combine(Configuration.LibraryFolder, shouldBe));
|
||||
Assert.Equal(t.FullName, releaseFolder);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateReleaseFolderNameInvalidArtistAndReleaseShouldThrowException()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => FolderPathHelper.ReleasePath(null, null, DateTime.MinValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateReleaseFolderNameInvalidReleaseShouldThrowException()
|
||||
{
|
||||
var af = new DirectoryInfo(Path.Combine(Configuration.LibraryFolder, @"E\EM\Empire Of The Moon [9909]"));
|
||||
Assert.Throws<ArgumentException>(() => FolderPathHelper.ReleasePath(af.FullName, null, DateTime.MinValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateReleaseFolderNameBlankReleaseShouldThrowException()
|
||||
{
|
||||
var af = new DirectoryInfo(Path.Combine(Configuration.LibraryFolder, @"E\EM\Empire Of The Moon [9909]"));
|
||||
Assert.Throws<ArgumentException>(() => FolderPathHelper.ReleasePath(af.FullName, "", DateTime.MinValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateReleaseFolderNameTooLongReleaseShouldThrowException()
|
||||
{
|
||||
var af = new DirectoryInfo(Path.Combine(Configuration.LibraryFolder, @"E\EM\Empire Of The Moon [9909]"));
|
||||
var tooLong = new String('X', 500);
|
||||
Assert.Throws<ArgumentException>(() => FolderPathHelper.ReleasePath(af.FullName, tooLong, DateTime.MinValue));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,18 +54,10 @@ namespace Roadie.Library.Tests
|
|||
[Fact]
|
||||
public async Task LastFMReleaseSearch()
|
||||
{
|
||||
//if (!Configuration.Integrations.LastFmProviderEnabled)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
Configuration.Integrations.ApiKeys = new List<ApiKey>();
|
||||
Configuration.Integrations.ApiKeys.Add(new ApiKey
|
||||
if (!Configuration.Integrations.LastFmProviderEnabled)
|
||||
{
|
||||
ApiName = "LastFMApiKey",
|
||||
Key = "a31dd32179375f9e332b89f8b9e38fc5",
|
||||
KeySecret = "35b3684601b2ecf9c0c0c1cfda28159e"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var logger = new EventMessageLogger<LastFmHelper>();
|
||||
logger.Messages += MessageLogger_Messages;
|
||||
|
@ -86,8 +78,8 @@ namespace Roadie.Library.Tests
|
|||
var release = result.Data.FirstOrDefault();
|
||||
Assert.NotNull(release);
|
||||
|
||||
artistName = "Rigor Mortis";
|
||||
title = "The Infinite Carnage";
|
||||
artistName = "Arkhangelsk";
|
||||
title = "Advent";
|
||||
sw = Stopwatch.StartNew();
|
||||
|
||||
// Without Tags
|
||||
|
|
|
@ -255,10 +255,19 @@ namespace Roadie.Library.MetaData.LastFm
|
|||
result.Tags = FilterTags(tagResult.Select(x => x.Name).Distinct().Take(25).ToArray());
|
||||
}
|
||||
}
|
||||
if (lastFmAlbum.Tracks != null)
|
||||
LastTrack[] lastFmTracks = null;
|
||||
try
|
||||
{
|
||||
lastFmTracks = lastFmAlbum.Tracks?.Where(x => x != null).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, $"Error getting LastFM Tracks for [{ artistName }] Query [{ query }]");
|
||||
}
|
||||
if (lastFmTracks?.Any() == true)
|
||||
{
|
||||
var tracks = new List<TrackSearchResult>();
|
||||
foreach (var lastFmTrack in lastFmAlbum.Tracks)
|
||||
foreach (var lastFmTrack in lastFmTracks)
|
||||
{
|
||||
tracks.Add(new TrackSearchResult
|
||||
{
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace Roadie.Library.Utility
|
|||
public static string ReleasePath(string artistFolder, string releaseTitle, DateTime releaseDate, bool createIfNotFound = false)
|
||||
{
|
||||
SimpleContract.Requires<ArgumentException>(!string.IsNullOrEmpty(artistFolder), "Invalid Artist Folder");
|
||||
SimpleContract.Requires<ArgumentException>(artistFolder.Length < MaximumArtistFolderNameLength, $"Artist Folder is longer than maximum allowed [{ MaximumArtistFolderNameLength }]");
|
||||
SimpleContract.Requires<ArgumentException>(artistFolder.Length < MaximumArtistFolderNameLength, $"Artist Folder [{ artistFolder }] is longer than maximum allowed [{ MaximumArtistFolderNameLength }]");
|
||||
|
||||
SimpleContract.Requires<ArgumentException>(!string.IsNullOrEmpty(releaseTitle), "Invalid Release Title");
|
||||
SimpleContract.Requires<ArgumentException>(releaseDate != DateTime.MinValue, "Invalid Release Date");
|
||||
|
|
|
@ -15,10 +15,7 @@ namespace Roadie.Library.Utility
|
|||
{
|
||||
if (!Predicate)
|
||||
{
|
||||
var ex = new TException();
|
||||
// I could not figure out how to set message on a generic Error so I pushed it to Data with Predicate Result as Key
|
||||
ex.Data.Add(Predicate.ToString(), Message);
|
||||
throw ex;
|
||||
throw (TException)Activator.CreateInstance(typeof(TException), Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue