Skip to content

Commit

Permalink
Merge pull request #2 from idubnori/alpha2
Browse files Browse the repository at this point in the history
Merged alpha2.
  • Loading branch information
idubnori authored Feb 7, 2018
2 parents 3489135 + a3d9240 commit f87e171
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/TrackInfoReader/Models/Item.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ShairportSync.Metadata.Models
{
public class Item
internal class Item
{
public string Type { get; set; }
public string Code { get; set; }
Expand Down
16 changes: 7 additions & 9 deletions src/TrackInfoReader/Parsers/TrackInfoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static IObservable<TrackInfo> GetObservable(IObservable<Item> itemSource)

private static IObservable<TrackInfo> Parse(this IObservable<Item> itemSource)
{
var artworkMetadataSource = itemSource.Where(m => m.Code == "PICT");
var artworkItemSource = itemSource.Where(m => m.Code == "PICT");

var bufferClosing = itemSource.Where(m => m.Code == "mden");
var trackSource = itemSource
Expand All @@ -32,10 +32,10 @@ private static IObservable<TrackInfo> Parse(this IObservable<Item> itemSource)
.Where(t => t.Item1?.Mper != t.Item2.Mper && t.Item2.Mper != null)
.Select(t => t.Item2);

var artworkTrackSource = artworkMetadataSource
.WithLatestFrom(trackSource, (i, h) => new Artwork(h) { Artwork = i.Data });
var artworkTrackSource = artworkItemSource
.WithLatestFrom(trackSource, (i, t) => new Artwork(t) { Artwork = i.Data });

return mperChangesTrackSource.Merge(artworkTrackSource).ToWithArtwork();
return mperChangesTrackSource.ToWithArtwork(artworkTrackSource);
}

private static TrackInfo ToTrack(this IList<Item> items)
Expand All @@ -52,14 +52,12 @@ private static TrackInfo ToTrack(this IList<Item> items)
return trackInfo;
}

private static IObservable<TrackInfo> ToWithArtwork(this IObservable<TrackInfo> trackSource)
private static IObservable<TrackInfo> ToWithArtwork(this IObservable<TrackInfo> trackSource, IObservable<Artwork> artworkSource)
{
var artworkSource = trackSource.Where(t => t is Artwork);

var trackWithArtworkSource = trackSource
.WithLatestFrom(artworkSource.StartWith(default(Artwork)), (t, a) => t.UpdateArtwork((Artwork)a));
.WithLatestFrom(artworkSource.StartWith(default(Artwork)), (t, a) => t.UpdateArtwork(a));

return trackWithArtworkSource;
return trackWithArtworkSource.Merge(artworkSource);
}

private static TrackInfo UpdateArtwork(this TrackInfo trackInfo, Artwork artwork)
Expand Down
15 changes: 8 additions & 7 deletions src/TrackInfoReader/TrackInfoReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
<RootNamespace>ShairportSync.Metadata</RootNamespace>
<Authors>idubnori</Authors>
<Company />
<Version>0.1.0-alpha1</Version>
<Version>0.1.0-alpha2</Version>
<Copyright>Copyright (c) 2018 idubnori.</Copyright>
<PackageProjectUrl>https://github.com/idubnori/shairport-sync-trackinfo-reader/</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/idubnori/shairport-sync-trackinfo-reader/blob/master/LICENSE</PackageLicenseUrl>
<PackageTags>shairport-sync, metadata, track, Raspberry Pi, System.Reactive</PackageTags>
<Description>ShairportSync.TrackInfoReader is a shairport-sync metadata parser which provides track information (artist, album, song title and artwork image) as IObservable&lt;TrackInfo&gt; .
<Description>ShairportSync.TrackInfoReader is a shairport-sync metadata parser which provides track information (artist, album, song title, artwork image, etc.) as Rx ( IObservable&lt;TrackInfo&gt; ).

This works on .NET Standard 2.0 compliant platforms like .NET Core 2 / Mono.
(i.e. Raspberry Pi 2/3, Mac, etc.)</Description>
<PackageReleaseNotes>First release.</PackageReleaseNotes>
<AssemblyVersion>0.1.0.1</AssemblyVersion>
<FileVersion>0.1.0.1</FileVersion>
This library works on .NET Standard 2.0 compliant platforms like .NET Core 2 / Mono.
i.e. works on Raspberry Pi 2 / 3, Mac, Linux, etc.
</Description>
<PackageReleaseNotes>https://github.com/idubnori/shairport-sync-trackinfo-reader/releases</PackageReleaseNotes>
<AssemblyVersion>0.1.0.2</AssemblyVersion>
<FileVersion>0.1.0.2</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
8 changes: 6 additions & 2 deletions tests/TrackInfoReader.Tests/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
using System.Threading.Tasks;
using Microsoft.Reactive.Testing;
using ShairportSync.Metadata.Models;
using Xunit;

namespace TrackInfoReader.Tests
{
internal static class HelperExtensions
{
public static bool IsDefaultArtwork(this TrackInfo actual)
public static bool AssertDefaultArtwork(this TrackInfo actual)
{
return actual.Artwork == "default.png"; // TODO
var expected = "default.png"; // TODO
Assert.Equal(expected, actual.Artwork);

return actual.Artwork == expected;
}

public static bool IsArtWork(this TrackInfo actual)
Expand Down
166 changes: 166 additions & 0 deletions tests/TrackInfoReader.Tests/TestData/next-song-no-image-in-same-album

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/TrackInfoReader.Tests/TrackInfoReader.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<ProjectReference Include="..\..\src\TrackInfoReader\TrackInfoReader.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="TestData\next-song-no-image-in-same-album">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestData\metadata-onetrack-oneartwork">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
16 changes: 13 additions & 3 deletions tests/TrackInfoReader.Tests/TrackInfoReaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Reactive;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Reactive.Testing;
using ShairportSync.Metadata.Models;
using Xunit;
Expand All @@ -22,12 +23,21 @@ public async Task OneTrackWithArtwork_OneTrackAndOneArtwork()
var actual = await SubscribeMetadataFileAsync(metadataTestFile);

actual.Messages.AssertEqual(
OnNext<TrackInfo>(0, t => t.IsSameSong(expectedTrack) && t.IsDefaultArtwork()),
OnNext<TrackInfo>(0, t => t.IsSameSong(expectedTrack) && t.AssertDefaultArtwork()),
OnNext<TrackInfo>(0, t => t.IsSameSong(expectedTrack) && t.IsArtWork()),
OnCompleted<TrackInfo>(0)
);
}

[Fact]
public async Task SecondSongWithNoArtwork_LastArtworkIsDefault()
{
var metadataTestFile = @"./TestData/next-song-no-image-in-same-album";

var actual = await SubscribeMetadataFileAsync(metadataTestFile);

Logger.LogDebug(actual.Messages.DebugInfo(t => t.DebugInfo()));
var actualLastArtwork = actual.Messages[3].Value.Value;
actualLastArtwork.AssertDefaultArtwork();
}
}
}
2 changes: 2 additions & 0 deletions tests/TrackInfoReader.Tests/TrackInfoReaderTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protected async Task<ITestableObserver<TrackInfo>> SubscribeMetadataFileAsync(st
//pipeServer.WaitForPipeDrain();
await pipeServer.WriteMetadataAsync(metadataFile);

Logger.LogDebug(mockObserver.Messages.DebugInfo(t => t.DebugInfo()));

using (new CompositeDisposable {trackSubscriber, pipeClient, pipeServer})
{
return mockObserver;
Expand Down

0 comments on commit f87e171

Please sign in to comment.