Skip to content

Commit

Permalink
Merge pull request jwallet#139 from jwallet/136
Browse files Browse the repository at this point in the history
Display which api is used
  • Loading branch information
jwallet authored Jan 13, 2020
2 parents 851f3b5 + 19cad39 commit d364206
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 84 deletions.
27 changes: 15 additions & 12 deletions EspionSpotify.Tests/EspionSpotify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Lame, Version=1.0.5.22475, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Lame.1.0.7\lib\net20\NAudio.Lame.dll</HintPath>
<Reference Include="NAudio.Lame, Version=1.0.9.26885, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Lame.1.0.9\lib\net40\NAudio.Lame.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
</Reference>
<Reference Include="SpotifyAPI.Web, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI.Web.4.0.0\lib\net46\SpotifyAPI.Web.dll</HintPath>
<HintPath>..\packages\SpotifyAPI.Web.4.0.1\lib\net46\SpotifyAPI.Web.dll</HintPath>
</Reference>
<Reference Include="SpotifyAPI.Web.Auth, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI.Web.Auth.4.0.1\lib\net46\SpotifyAPI.Web.Auth.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand All @@ -84,6 +87,12 @@
<Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\packages\taglib.2.1.0.0\lib\taglib-sharp.dll</HintPath>
</Reference>
<Reference Include="Unosquare.Labs.EmbedIO, Version=2.2.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EmbedIO.2.2.7\lib\net452\Unosquare.Labs.EmbedIO.dll</HintPath>
</Reference>
<Reference Include="Unosquare.Swan.Lite, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Unosquare.Swan.Lite.1.3.1\lib\net461\Unosquare.Swan.Lite.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -123,14 +132,6 @@
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="libmp3lame.32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="libmp3lame.64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand All @@ -140,6 +141,8 @@
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
<Error Condition="!Exists('..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets'))" />
</Target>
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
<Import Project="..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets" Condition="Exists('..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets')" />
</Project>
26 changes: 26 additions & 0 deletions EspionSpotify.Tests/ExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ internal void StringToLastFMNodeStatus_ReturnsExpectedStatus(string value, LastF
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(null, null)]
[InlineData("", null)]
[InlineData("flac", null)]
[InlineData("mp3", MediaFormat.Mp3)]
[InlineData("MP3", MediaFormat.Mp3)]
[InlineData("WAV", MediaFormat.Wav)]
[InlineData("wav", MediaFormat.Wav)]
internal void StringToMediaFormat_ReturnsExpectedFormat(string value, MediaFormat? expected)
{
var actual = value.ToMediaFormat();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(null, null)]
[InlineData("", null)]
[InlineData("API", null)]
[InlineData("spotify", MediaTagsAPI.Spotify)]
[InlineData("lastFM", MediaTagsAPI.LastFM)]
internal void StringToMediaTagsAPI_ReturnsExpectedAPI(string value, MediaTagsAPI? expected)
{
var actual = value.ToMediaTagsAPI();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(null, "")]
[InlineData(" ", "")]
Expand Down
Binary file removed EspionSpotify.Tests/libmp3lame.32.dll
Binary file not shown.
Binary file removed EspionSpotify.Tests/libmp3lame.64.dll
Binary file not shown.
9 changes: 6 additions & 3 deletions EspionSpotify.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.3.1" targetFramework="net461" />
<package id="EmbedIO" version="2.2.7" targetFramework="net461" />
<package id="Moq" version="4.9.0" targetFramework="net461" />
<package id="NAudio" version="1.9.0" targetFramework="net461" />
<package id="NAudio.Lame" version="1.0.7" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" />
<package id="SpotifyAPI.Web" version="4.0.0" targetFramework="net461" />
<package id="NAudio.Lame" version="1.0.9" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
<package id="SpotifyAPI.Web" version="4.0.1" targetFramework="net461" />
<package id="SpotifyAPI.Web.Auth" version="4.0.1" targetFramework="net461" />
<package id="System.IO.Abstractions" version="7.1.1" targetFramework="net461" />
<package id="System.IO.Abstractions.TestingHelpers" version="7.1.1" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
<package id="taglib" version="2.1.0.0" targetFramework="net461" />
<package id="Unosquare.Swan.Lite" version="1.3.1" targetFramework="net461" />
<package id="xunit" version="2.4.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
Expand Down
9 changes: 7 additions & 2 deletions EspionSpotify/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<setting name="Logs" serializeAs="String">
<value />
</setting>
<setting name="MediaTagsAPI" serializeAs="String">
<value>0</value>
</setting>
<!--
Go to https://developer.spotify.com/dashboard/applications/ and register a new application
- (e.g.:) Name: spotify, description: none, building: i don't know
Expand All @@ -90,10 +93,12 @@
</setting>
-->
<setting name="SpotifyAPISecretId" serializeAs="String">
<value />
<value>
</value>
</setting>
<setting name="SpotifyAPIClientId" serializeAs="String">
<value />
<value>
</value>
</setting>
</EspionSpotify.Properties.Settings>
</userSettings>
Expand Down
8 changes: 8 additions & 0 deletions EspionSpotify/Enums/MediaTagsAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EspionSpotify.Enums
{
public enum MediaTagsAPI
{
LastFM = 0,
Spotify
}
}
26 changes: 14 additions & 12 deletions EspionSpotify/EspionSpotify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<ApplicationVersion>0.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -115,8 +117,8 @@
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Lame, Version=1.0.5.22475, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Lame.1.0.7\lib\net20\NAudio.Lame.dll</HintPath>
<Reference Include="NAudio.Lame, Version=1.0.9.26885, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Lame.1.0.9\lib\net40\NAudio.Lame.dll</HintPath>
</Reference>
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand All @@ -129,10 +131,10 @@
<HintPath>..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
</Reference>
<Reference Include="SpotifyAPI.Web, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI.Web.4.0.0\lib\net46\SpotifyAPI.Web.dll</HintPath>
<HintPath>..\packages\SpotifyAPI.Web.4.0.1\lib\net46\SpotifyAPI.Web.dll</HintPath>
</Reference>
<Reference Include="SpotifyAPI.Web.Auth, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI.Web.Auth.4.0.0\lib\net46\SpotifyAPI.Web.Auth.dll</HintPath>
<HintPath>..\packages\SpotifyAPI.Web.Auth.4.0.1\lib\net46\SpotifyAPI.Web.Auth.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -171,6 +173,7 @@
</Compile>
<Compile Include="Enums\LastFMNodeStatus.cs" />
<Compile Include="Enums\AlbumCoverSize.cs" />
<Compile Include="Enums\MediaTagsAPI.cs" />
<Compile Include="Enums\MediaFormat.cs" />
<Compile Include="Enums\TranslationKeys.cs" />
<Compile Include="Extensions\IntExtensions.cs" />
Expand Down Expand Up @@ -316,15 +319,14 @@
<ItemGroup>
<None Include="Resources\release.gif" />
</ItemGroup>
<ItemGroup>
<Content Include="libmp3lame.32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="libmp3lame.64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets" Condition="Exists('..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NAudio.Lame.1.0.9\build\NAudio.Lame.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
10 changes: 10 additions & 0 deletions EspionSpotify/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public static class StringExtensions
return value.ToEnum<LastFMNodeStatus>(ignoreCase: true);
}

public static MediaFormat? ToMediaFormat(this string value)
{
return value.ToEnum<MediaFormat>(ignoreCase: true);
}

public static MediaTagsAPI? ToMediaTagsAPI(this string value)
{
return value.ToEnum<MediaTagsAPI>(ignoreCase: true);
}

public static T? ToEnum<T>(this string value, bool ignoreCase) where T : struct
{
var types = typeof(T);
Expand Down
13 changes: 9 additions & 4 deletions EspionSpotify/MediaTags/SpotifyAPI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using EspionSpotify.Models;
using EspionSpotify.Enums;
using EspionSpotify.Models;
using EspionSpotify.Properties;
using SpotifyAPI.Web;
using SpotifyAPI.Web.Auth;
using SpotifyAPI.Web.Enums;
Expand All @@ -11,19 +13,20 @@ namespace EspionSpotify.MediaTags
{
public class SpotifyAPI : ISpotifyAPI, IExternalAPI
{
private string _clientId;
private string _secretId;
private readonly string _clientId;
private readonly string _secretId;
private Token _token;
private DateTimeOffset _nextTokenRenewal;
private AuthorizationCodeAuth _authorizationCodeAuth;
private readonly LastFMAPI _lastFmApi = new LastFMAPI();
private readonly LastFMAPI _lastFmApi;

public SpotifyAPI() { }

public SpotifyAPI(string clientId, string secretId, string redirectUrl = "http://localhost:4002")
{
_clientId = clientId;
_secretId = secretId;
_lastFmApi = new LastFMAPI();

if (!string.IsNullOrEmpty(_clientId) && !string.IsNullOrEmpty(_secretId))
{
Expand All @@ -47,6 +50,8 @@ public async Task<bool> UpdateTrack(Track track)
{
// fallback in case getting the playback did not work
// user might be connected with a different account that the one that granted rights
Settings.Default.MediaTagsAPI = (int)MediaTagsAPI.LastFM;
Settings.Default.Save();
return await _lastFmApi.UpdateTrack(track);
}

Expand Down
30 changes: 21 additions & 9 deletions EspionSpotify/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions EspionSpotify/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@
<Setting Name="AudioEndPointDeviceIndex" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SpotifyAPISecretId" Type="System.String" Scope="User">
<Setting Name="Logs" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SpotifyAPIClientId" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Setting Name="MediaTagsAPI" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="Logs" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Setting Name="SpotifyAPISecretId" Type="System.String" Scope="User">
<Value Profile="(Default)"> </Value>
</Setting>
<Setting Name="SpotifyAPIClientId" Type="System.String" Scope="User">
<Value Profile="(Default)"> </Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion EspionSpotify/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async void Run()

private async void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
{
// TODO: add buffer handler from argument
// TODO: add buffer handler from argument: issue #100
if (_writer != null) await _writer.WriteAsync(e.Buffer, 0, e.BytesRecorded);
}

Expand Down
Loading

0 comments on commit d364206

Please sign in to comment.