Fixed: Extra tests and fixes for new track parser (#632)

* Extra tests and fixes for new track parser

* Address review comments, add extra test, fix logging
pull/636/head
ta264 6 years ago committed by Qstick
parent af65e251d8
commit 6cfc591364

@ -107,26 +107,23 @@ namespace NzbDrone.Common.Test.CacheTests
public void should_clear_expired_when_they_expire()
{
int hitCount = 0;
_cachedString = new Cached<string>();
Func<string> testfunc = () => {
hitCount++;
return null;
};
_cachedString.Values.Should().HaveCount(0);
_cachedString.Get("key", testfunc, TimeSpan.FromMilliseconds(300));
Thread.Sleep(100);
_cachedString.Values.Should().HaveCount(1);
for (int i = 0; i < 10; i++)
{
_cachedString.Get("key", () =>
{
hitCount++;
return null;
}, TimeSpan.FromMilliseconds(300));
_cachedString.Get("key", testfunc, TimeSpan.FromMilliseconds(300));
Thread.Sleep(100);
}
Thread.Sleep(1000);
hitCount.Should().BeInRange(3, 6);
_cachedString.Values.Should().HaveCount(0);
hitCount.Should().Be(1);
}
}

File diff suppressed because it is too large Load Diff

@ -4,150 +4,154 @@
"97189482-89ee-4d31-90c7-ba07b412d7f9",
"9105a5b3-eb68-3a03-9aa8-f3495e602a4f"
],
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
"libraryArtists": [
{
"artist": "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493",
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
}
],
"id": 1
}
],
"id": 1
},
"artist": "cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493",
}
],
"newDownload": false,
"singleRelease": false,
"tracks": [

@ -2,150 +2,154 @@
"expectedMusicBrainzReleaseIds": [
"134f5f3e-8b5f-46ab-809d-8c0dbc794f3e"
],
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
"libraryArtists": [
{
"artist": "c296e10c-110a-4103-9e77-47bfebb7fb2e",
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
}
],
"id": 1
}
],
"id": 1
},
"artist": "c296e10c-110a-4103-9e77-47bfebb7fb2e",
}
],
"newDownload": false,
"singleRelease": false,
"tracks": [

@ -2,150 +2,154 @@
"expectedMusicBrainzReleaseIds": [
"0ce2d66f-e871-415a-9a85-e564f99d4021"
],
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": true
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
"libraryArtists": [
{
"artist": "7ac055fa-e357-4890-9098-010b8094a900",
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": true
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
}
],
"id": 1
}
],
"id": 1
},
"artist": "7ac055fa-e357-4890-9098-010b8094a900",
}
],
"newDownload": false,
"singleRelease": false,
"tracks": [

@ -2,150 +2,154 @@
"expectedMusicBrainzReleaseIds": [
"25f0fa1b-ae04-479a-a182-18a655ff6040"
],
"metadataProfile": {
"name": "Album+Single",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": true
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
"libraryArtists": [
{
"artist": "70248960-cb53-4ea4-943a-edb18f7d336f",
"metadataProfile": {
"name": "Album+Single",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": true
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
}
],
"id": 2
}
],
"id": 2
},
"artist": "70248960-cb53-4ea4-943a-edb18f7d336f",
}
],
"newDownload": true,
"singleRelease": false,
"tracks": [

@ -2,150 +2,154 @@
"expectedMusicBrainzReleaseIds": [
"4e2dd34f-53fe-4d54-b564-b14a2871505e"
],
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
"libraryArtists": [
{
"artist": "6fe07aa5-fec0-4eca-a456-f29bff451b04",
"metadataProfile": {
"name": "Standard",
"primaryAlbumTypes": [
{
"primaryAlbumType": {
"id": 2,
"name": "Single"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 4,
"name": "Other"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 1,
"name": "EP"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 3,
"name": "Broadcast"
},
"allowed": false
},
{
"primaryAlbumType": {
"id": 0,
"name": "Album"
},
"allowed": true
}
],
"secondaryAlbumTypes": [
{
"secondaryAlbumType": {
"id": 0,
"name": "Studio"
},
"allowed": true
},
{
"secondaryAlbumType": {
"id": 3,
"name": "Spokenword"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 2,
"name": "Soundtrack"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 7,
"name": "Remix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 9,
"name": "Mixtape/Street"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 6,
"name": "Live"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 4,
"name": "Interview"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 8,
"name": "DJ-mix"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 10,
"name": "Demo"
},
"allowed": false
},
{
"secondaryAlbumType": {
"id": 1,
"name": "Compilation"
},
"allowed": false
}
],
"releaseStatuses": [
{
"releaseStatus": {
"id": 3,
"name": "Pseudo"
},
"allowed": false
},
{
"releaseStatus": {
"id": 1,
"name": "Promotion"
},
"allowed": false
},
{
"releaseStatus": {
"id": 0,
"name": "Official"
},
"allowed": true
},
{
"releaseStatus": {
"id": 2,
"name": "Bootleg"
},
"allowed": false
}
],
"id": 1
}
],
"id": 1
},
"artist": "6fe07aa5-fec0-4eca-a456-f29bff451b04",
}
],
"newDownload": false,
"singleRelease": false,
"tracks": [

@ -53,13 +53,13 @@ namespace NzbDrone.Core.Test.MediaFiles
var track = Builder<Track>.CreateListOfSize(10)
.TheFirst(1)
.With(a => a.TrackFileId = files[0].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[1].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[2].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[3].Id)
.TheNext(1)
.With(a => a.TrackFileId = files[4].Id)
.TheNext(6)
.With(a => a.TrackFileId = 0)
.All()
@ -115,9 +115,15 @@ namespace NzbDrone.Core.Test.MediaFiles
{
foreach (var file in files)
{
file.Tracks.IsLoaded.Should().BeTrue();
file.Tracks.Value.Should().NotBeNull();
file.Tracks.Value.Should().NotBeEmpty();
file.Album.IsLoaded.Should().BeTrue();
file.Album.Value.Should().NotBeNull();
file.Artist.IsLoaded.Should().BeTrue();
file.Artist.Value.Should().NotBeNull();
file.Artist.Value.Metadata.IsLoaded.Should().BeTrue();
file.Artist.Value.Metadata.Value.Should().NotBeNull();
}
}
}

@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
.With(x => x.RecordingMBId = track.ForeignRecordingId)
.With(x => x.Country = IsoCountries.Find("US"))
.With(x => x.Label = release.Label.First())
.With(x => x.Year = (uint)release.Album.Value.ReleaseDate.Value.Year)
.With(x => x.Year = (uint)(release.Album.Value.ReleaseDate?.Year ?? 0))
.Build();
var localTrack = Builder<LocalTrack>
@ -212,5 +212,53 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
Subject.AlbumReleaseDistance(localTracks, release, mapping).NormalizedDistance().Should().Be(0.0);
}
private static DateTime?[] dates = new DateTime?[] { null, new DateTime(2007, 1, 1), DateTime.Now };
[TestCaseSource("dates")]
public void test_null_album_year(DateTime? releaseDate)
{
var tracks = GivenTracks(3);
var release = GivenAlbumRelease("album", tracks);
var localTracks = GivenLocalTracks(tracks, release);
var mapping = GivenMapping(localTracks, tracks);
release.Album.Value.ReleaseDate = null;
release.ReleaseDate = releaseDate;
var result = Subject.AlbumReleaseDistance(localTracks, release, mapping).NormalizedDistance();
if (!releaseDate.HasValue || (localTracks[0].FileTrackInfo.Year == (releaseDate?.Year ?? 0)))
{
result.Should().Be(0.0);
}
else
{
result.Should().NotBe(0.0);
}
}
[TestCaseSource("dates")]
public void test_null_release_year(DateTime? albumDate)
{
var tracks = GivenTracks(3);
var release = GivenAlbumRelease("album", tracks);
var localTracks = GivenLocalTracks(tracks, release);
var mapping = GivenMapping(localTracks, tracks);
release.Album.Value.ReleaseDate = albumDate;
release.ReleaseDate = null;
var result = Subject.AlbumReleaseDistance(localTracks, release, mapping).NormalizedDistance();
if (!albumDate.HasValue || (localTracks[0].FileTrackInfo.Year == (albumDate?.Year ?? 0)))
{
result.Should().Be(0.0);
}
else
{
result.Should().NotBe(0.0);
}
}
}
}

@ -17,6 +17,11 @@ using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Profiles.Metadata;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using System.Collections.Generic;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Parser;
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation.Aggregators;
using NzbDrone.Core.MediaFiles.TrackImport.Aggregation;
namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
{
@ -62,23 +67,45 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
Mocker.GetMock<IAddArtistValidator>().Setup(x => x.Validate(It.IsAny<Artist>())).Returns(new ValidationResult());
Mocker.SetConstant<ITrackGroupingService>(Mocker.Resolve<TrackGroupingService>());
// set up the augmenters
List<IAggregate<LocalAlbumRelease>> aggregators = new List<IAggregate<LocalAlbumRelease>> {
Mocker.Resolve<AggregateFilenameInfo>()
};
Mocker.SetConstant<IEnumerable<IAggregate<LocalAlbumRelease>>>(aggregators);
Mocker.SetConstant<IAugmentingService>(Mocker.Resolve<AugmentingService>());
Subject = Mocker.Resolve<IdentificationService>();
}
private void GivenMetadataProfile(MetadataProfile profile)
{
Mocker.GetMock<IMetadataProfileService>().Setup(x => x.Get(It.IsAny<int>())).Returns(profile);
Mocker.GetMock<IMetadataProfileService>().Setup(x => x.Get(profile.Id)).Returns(profile);
}
private List<Artist> GivenArtists(List<ArtistTestCase> artists)
{
var outp = new List<Artist>();
for (int i = 0; i < artists.Count; i++)
{
var meta = artists[i].MetadataProfile;
meta.Id = i + 1;
GivenMetadataProfile(meta);
outp.Add(GivenArtist(artists[i].Artist, meta.Id));
}
return outp;
}
private Artist GivenArtist(string foreignArtistId)
private Artist GivenArtist(string foreignArtistId, int metadataProfileId)
{
var artist = _addArtistService.AddArtist(new Artist {
Metadata = new ArtistMetadata {
ForeignArtistId = foreignArtistId
},
Path = @"c:\test".AsOsAgnostic(),
MetadataProfileId = 1
MetadataProfileId = metadataProfileId
});
var command = new RefreshArtistCommand{
@ -91,6 +118,18 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
return _artistService.FindById(foreignArtistId);
}
private void GivenFingerprints(List<AcoustIdTestCase> fingerprints)
{
Mocker.GetMock<IConfigService>().Setup(x => x.AllowFingerprinting).Returns(AllowFingerprinting.AllFiles);
Mocker.GetMock<IFingerprintingService>().Setup(x => x.IsSetup()).Returns(true);
Mocker.GetMock<IFingerprintingService>()
.Setup(x => x.Lookup(It.IsAny<List<LocalTrack>>(), It.IsAny<double>()))
.Callback((List<LocalTrack> track, double thres) => {
track.ForEach(x => x.AcoustIdResults = fingerprints.SingleOrDefault(f => f.Path == x.Path).AcoustIdResults);
});
}
public static class IdTestCaseFactory
{
// for some reason using Directory.GetFiles causes nUnit to error
@ -99,7 +138,9 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
"PreferMissingToBadMatch.json",
"InconsistentTyposInAlbum.json",
"SucceedWhenManyAlbumsHaveSameTitle.json",
"PenalizeUnknownMedia.json"
"PenalizeUnknownMedia.json",
"CorruptFile.json",
"FilesWithoutTags.json"
};
public static IEnumerable TestCases
@ -122,19 +163,25 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Identification", file);
var testcase = JsonConvert.DeserializeObject<IdTestCase>(File.ReadAllText(path));
GivenMetadataProfile(testcase.MetadataProfile);
var artist = GivenArtist(testcase.Artist);
var artists = GivenArtists(testcase.LibraryArtists);
var specifiedArtist = artists.SingleOrDefault(x => x.Metadata.Value.ForeignArtistId == testcase.Artist);
var tracks = testcase.Tracks.Select(x => new LocalTrack {
Path = x.Path.AsOsAgnostic(),
FileTrackInfo = x.FileTrackInfo
}).ToList();
var result = Subject.Identify(tracks, artist, null, null, testcase.NewDownload, testcase.SingleRelease);
if (testcase.Fingerprints != null)
{
GivenFingerprints(testcase.Fingerprints);
}
var result = Subject.Identify(tracks, specifiedArtist, null, null, testcase.NewDownload, testcase.SingleRelease);
TestLogger.Debug($"Found releases:\n{result.Where(x => x.AlbumRelease != null).Select(x => x.AlbumRelease?.ForeignReleaseId).ToJson()}");
result.Should().HaveCount(testcase.ExpectedMusicBrainzReleaseIds.Count);
result.Select(x => x.AlbumRelease.ForeignReleaseId).ShouldBeEquivalentTo(testcase.ExpectedMusicBrainzReleaseIds);
result.Where(x => x.AlbumRelease != null).Select(x => x.AlbumRelease.ForeignReleaseId).ShouldBeEquivalentTo(testcase.ExpectedMusicBrainzReleaseIds);
}
}
}

@ -47,7 +47,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
protected override string GetString(MemberInfo memberInfo)
{
int length = generator.Next(0, 100);
int length = generator.Next(1, 100);
char[] chars = new char[length];
@ -102,6 +102,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
return outp;
}
[Repeat(100)]
private List<LocalTrack> GivenVaTracks(string root, string album, int count)
{
var settings = new BuilderSettings();
@ -135,7 +136,9 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
}
// GivenVaTracks uses random names so repeat multiple times to try to prompt any intermittent failures
[Test]
[Repeat(100)]
public void all_different_artists_is_various_artists()
{
var tracks = GivenVaTracks(@"C:\music\incoming".AsOsAgnostic(), "album", 10);
@ -153,6 +156,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
}
[Test]
[Repeat(100)]
public void mostly_different_artists_is_various_artists()
{
var dir = @"C:\music\incoming".AsOsAgnostic();
@ -172,6 +176,16 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
TrackGroupingService.IsVariousArtists(tracks).Should().Be(true);
}
[TestCase("Va?!")]
[TestCase("Va Va Voom")]
[TestCase("V.A. Jr.")]
[TestCase("Ca Va")]
public void va_in_artist_name_is_not_various_artists(string artist)
{
var tracks = GivenTracks(@"C:\music\incoming".AsOsAgnostic(), artist, "album", 10);
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
}
[TestCase(1)]
[TestCase(2)]
[TestCase(10)]
@ -308,6 +322,7 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
}
[Test]
[Repeat(100)]
public void should_group_va_release()
{
var tracks = GivenVaTracks(@"C:\music\incoming".AsOsAgnostic(), "album", 10);
@ -365,5 +380,29 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport.Identification
output.Count.Should().Be(1);
output[0].LocalTracks.Count.Should().Be(12);
}
[Test]
public void should_cope_with_one_album_in_subfolder_of_another()
{
var tracks = GivenTracks($"C:\\music\\incoming\\album".AsOsAgnostic(),
"artist1", "album", 10);
tracks.AddRange(GivenTracks($"C:\\music\\incoming\\album\\anotheralbum".AsOsAgnostic(),
"artist2", "album2", 10));
TrackGroupingService.IsVariousArtists(tracks).Should().Be(false);
TrackGroupingService.LooksLikeSingleRelease(tracks).Should().Be(false);
var output = Subject.GroupTracks(tracks);
foreach(var group in output)
{
TestLogger.Debug($"*** group {group} ***");
TestLogger.Debug(string.Join("\n", group.LocalTracks.Select(x => x.Path)));
}
output.Count.Should().Be(2);
output[0].LocalTracks.Count.Should().Be(10);
output[1].LocalTracks.Count.Should().Be(10);
}
}
}

@ -128,5 +128,58 @@ FINGERPRINT=AQAHJlMURlEURcgP6cwRD43Y4Ptw9FowncWPWkf6GB9-JYdP9OgJHw8u4Apw4SsOHMdx
files[0].AcoustIdResults.Should().BeNull();
files[1].AcoustIdResults.Should().BeNull();
}
[Test]
public void should_not_fail_if_duration_reported_as_zero()
{
UseRealHttp();
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "missing.mp3");
var localTrack = new LocalTrack { Path = path };
var acoustId = new AcoustId {
Duration = 0,
Fingerprint = "fingerprint"
};
Subject.Lookup(new List<Tuple<LocalTrack, AcoustId>> { Tuple.Create(localTrack, acoustId)}, 0.5);
}
[Test]
public void should_not_throw_if_fingerprint_invalid()
{
UseRealHttp();
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "missing.mp3");
var localTrack = new LocalTrack { Path = path };
var acoustId = new AcoustId {
Duration = 1,
Fingerprint = "fingerprint"
};
var files = new List<Tuple<LocalTrack, AcoustId>> { Tuple.Create(localTrack, acoustId)};
Subject.Lookup(files, 0.5);
files[0].Item1.AcoustIdResults.Should().BeNull();
}
[Test]
public void should_not_fail_for_some_invalid_fingerprints()
{
UseRealHttp();
var files = new [] {
"nin.mp3",
"nin.flac"
}.Select(x => new LocalTrack { Path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", x) }).ToList();
var idpairs = files.Select(x => Tuple.Create(x, Subject.GetFingerprint(x.Path))).ToList();
idpairs.Add(Tuple.Create(new LocalTrack(), new AcoustId { Duration = 1, Fingerprint = "fingerprint" }));
Subject.Lookup(idpairs, 0.5);
idpairs[0].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
idpairs[1].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
idpairs[2].Item1.AcoustIdResults.Should().BeNull();
}
}
}

@ -70,7 +70,12 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
});
var options = new IdTestCase {
ExpectedMusicBrainzReleaseIds = new List<string> {"expected-id-1", "expected-id-2", "..."},
MetadataProfile = artist?.MetadataProfile.Value,
LibraryArtists = new List<ArtistTestCase> {
new ArtistTestCase {
Artist = artist?.Metadata.Value.ForeignArtistId ?? "expected-artist-id (dev: don't forget to add metadata profile)",
MetadataProfile = artist?.MetadataProfile.Value
}
},
Artist = artist?.Metadata.Value.ForeignArtistId,
Album = album?.ForeignAlbumId,
Release = release?.ForeignReleaseId,
@ -400,8 +405,12 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
result.Mapping.Add(localTracks[pair.Item1], Tuple.Create(mbTracks[pair.Item2], distances[pair.Item1, pair.Item2]));
_logger.Trace("Mapped {0} to {1}, dist: {2}", localTracks[pair.Item1], mbTracks[pair.Item2], costs[pair.Item1, pair.Item2]);
}
result.LocalExtra = localTracks.Except(result.Mapping.Keys).ToList();
_logger.Trace($"Unmapped files:\n{string.Join("\n", result.LocalExtra)}");
result.MBExtra = mbTracks.Except(result.Mapping.Values.Select(x => x.Item1)).ToList();
_logger.Trace($"Missing tracks:\n{string.Join("\n", result.MBExtra)}");
return result;
}
@ -435,7 +444,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
dist.AddString("track_artist", localTrack.FileTrackInfo.ArtistTitle, mbTrack.ArtistMetadata.Value.Name);
}
if (localTrack.FileTrackInfo.TrackNumbers[0] > 0 && mbTrack.AbsoluteTrackNumber > 0)
if (localTrack.FileTrackInfo.TrackNumbers.FirstOrDefault() > 0 && mbTrack.AbsoluteTrackNumber > 0)
{
dist.AddBool("track_index", TrackIndexIncorrect(localTrack, mbTrack, totalTrackNumber));
}
@ -489,21 +498,22 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
// Year
var localYear = MostCommon(localTracks.Select(x => x.FileTrackInfo.Year));
if (localYear > 0 && release.Album.Value.ReleaseDate.HasValue)
if (localYear > 0 && (release.Album.Value.ReleaseDate.HasValue || release.ReleaseDate.HasValue))
{
var albumYear = release.Album.Value.ReleaseDate.Value.Year;
var releaseYear = release.ReleaseDate.Value.Year;
var albumYear = release.Album.Value.ReleaseDate?.Year ?? 0;
var releaseYear = release.ReleaseDate?.Year ?? 0;
if (localYear == albumYear || localYear == releaseYear)
{
dist.Add("year", 0.0);
}
else
{
var diff = Math.Abs(localYear - albumYear);
var diff_max = Math.Abs(DateTime.Now.Year - albumYear);
var remoteYear = albumYear > 0 ? albumYear : releaseYear;
var diff = Math.Abs(localYear - remoteYear);
var diff_max = Math.Abs(DateTime.Now.Year - remoteYear);
dist.AddRatio("year", diff, diff_max);
}
_logger.Trace("year: {0} vs {1}; {2}", localYear, release.Album.Value.ReleaseDate?.Year, dist.NormalizedDistance());
_logger.Trace($"year: {localYear} vs {release.Album.Value.ReleaseDate?.Year} or {release.ReleaseDate?.Year}; {dist.NormalizedDistance()}");
}
// If we parsed a country from the files use that, otherwise use our preference
@ -513,7 +523,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
if (country != null)
{
dist.AddEquality("country", country.Name, release.Country);
_logger.Trace("country: {0} vs {1}; {2}", country, string.Join(", ", release.Country), dist.NormalizedDistance());
_logger.Trace("country: {0} vs {1}; {2}", country.Name, string.Join(", ", release.Country), dist.NormalizedDistance());
}
else if (preferredCountries.Count > 0)
{

@ -9,17 +9,30 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
public string Path { get; set; }
public ParsedTrackInfo FileTrackInfo { get; set; }
}
public class ArtistTestCase
{
public string Artist { get; set; }
public MetadataProfile MetadataProfile { get; set; }
}
public class AcoustIdTestCase
{
public string Path { get; set; }
public List<string> AcoustIdResults { get; set; }
}
public class IdTestCase
{
public List<string> ExpectedMusicBrainzReleaseIds { get; set; }
public MetadataProfile MetadataProfile { get; set; }
public List<ArtistTestCase> LibraryArtists { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public string Release { get; set; }
public bool NewDownload { get; set; }
public bool SingleRelease { get; set; }
public List<BasicLocalTrack> Tracks { get; set; }
public List<AcoustIdTestCase> Fingerprints { get; set; }
}
}

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.Parser.Model;
@ -207,7 +208,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Identification
// reset and put current folder into output
subdirRegex = null;
output.AddRange(tracks.Where(x => x.Path.StartsWith(folder)));
output.AddRange(tracks.Where(x => PathEqualityComparer.Instance.Equals(Path.GetDirectoryName(x.Path), folder)));
// check if the start of another multi disc match
foreach (var marker in multiDiscMarkers)

@ -13,6 +13,7 @@ using System;
using NzbDrone.Common.EnvironmentInfo;
using System.Threading;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace NzbDrone.Core.Parser
{
@ -337,19 +338,25 @@ namespace NzbDrone.Core.Parser
httpRequest.SetContent(Compress(Encoding.UTF8.GetBytes(sb.ToString())));
httpRequest.Headers.Add("Content-Encoding", "gzip");
httpRequest.Headers.ContentType = "application/x-www-form-urlencoded";
httpRequest.SuppressHttpError = true;
var httpResponse = _httpClient.Post<LookupResponse>(httpRequest);
if (httpResponse.HasHttpError)
{
throw new HttpException(httpRequest, httpResponse);
}
var response = httpResponse.Resource;
if (!string.IsNullOrEmpty(response.ErrorMessage))
// The API will give errors if fingerprint isn't found or is invalid.
// We don't want to stop the entire import because the fingerprinting failed
// so just log and return.
if (httpResponse.HasHttpError || (response != null && response.Status != "ok"))
{
_logger.Debug("Webservice error: {0}", response.ErrorMessage);
if (response != null && response.Error != null)
{
_logger.Debug($"Webservice error {response.Error.Code}: {response.Error.Message}");
}
else
{
_logger.Warn("HTTP Error - {0}", httpResponse);
}
return;
}
@ -373,15 +380,26 @@ namespace NzbDrone.Core.Parser
}
_logger.Debug("Fingerprinting complete.");
var SerializerSettings = Json.GetSerializerSettings();
SerializerSettings.Formatting = Formatting.None;
var output = new { Fingerprints = toLookup.Select(x => new { Path = x.Item1.Path, AcoustIdResults = x.Item1.AcoustIdResults }) };
_logger.Debug($"*** FingerprintingService TestCaseGenerator ***\n{JsonConvert.SerializeObject(output, SerializerSettings)}");
}
private class LookupResponse
{
public string StatusCode { get; set; }
public string ErrorMessage { get; set; }
public string Status { get; set; }
public LookupError Error { get; set; }
public List<LookupResultListItem> Fingerprints { get; set; }
}
private class LookupError
{
public string Message { get; set; }
public int Code { get; set; }
}
private class LookupResultListItem
{
public int index { get; set; }

Loading…
Cancel
Save