Skip to content

Commit

Permalink
1.2 (jwallet#76)
Browse files Browse the repository at this point in the history
* 1.1.5

- added delay stop recording jwallet#74
- fixed start/stop button refresh after click jwallet#75

* faq updated

* resources

* updated consts

* spotify api

.net 4.6 now required
close jwallet#69

* added faq support about cpu minimum performance 100

close jwallet#78

* deleted test

* app config

* removed comments appconfig

* 1.2

* updated doc
  • Loading branch information
jwallet authored Mar 13, 2019
1 parent 813a99b commit 327e8d0
Show file tree
Hide file tree
Showing 70 changed files with 44,384 additions and 228 deletions.
1 change: 0 additions & 1 deletion EspionSpotify.Tests/EspionSpotify.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="FileManagerTests.cs" />
<Compile Include="LastFMAPITests.cs" />
<Compile Include="SpotifyHandlerTests.cs" />
<Compile Include="SpotifyStatusTests.cs" />
<Compile Include="TrackTests.cs" />
Expand Down
29 changes: 0 additions & 29 deletions EspionSpotify.Tests/LastFMAPITests.cs

This file was deleted.

6 changes: 3 additions & 3 deletions EspionSpotify.Tests/SpotifyHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private async void TickEventSpotifyIdling_ReturnsNoEvent()
var track = new Track();

var spotifyStatusMock = new Moq.Mock<ISpotifyStatus>();
spotifyStatusMock.Setup(x => x.Track).Returns(track);
spotifyStatusMock.Setup(x => x.CurrentTrack).Returns(track);
spotifyStatusMock.Setup(x => x.GetTrack()).Returns(track);

var spotifyProcessMock = new Moq.Mock<ISpotifyProcess>();
Expand Down Expand Up @@ -102,7 +102,7 @@ private async void NewTrack_ReturnsAllEvents()
};

var spotifyStatusMock = new Moq.Mock<ISpotifyStatus>();
spotifyStatusMock.Setup(x => x.Track).Returns(currentTrack);
spotifyStatusMock.Setup(x => x.CurrentTrack).Returns(currentTrack);
spotifyStatusMock.Setup(x => x.GetTrack()).Returns(currentTrack);

var spotifyProcessMock = new Moq.Mock<ISpotifyProcess>();
Expand Down Expand Up @@ -162,7 +162,7 @@ private async void TickEventSameTrackPlaying_ReturnsTrackTimeEvent()
};

var spotifyStatusMock = new Moq.Mock<ISpotifyStatus>();
spotifyStatusMock.Setup(x => x.Track).Returns(track);
spotifyStatusMock.Setup(x => x.CurrentTrack).Returns(track);
spotifyStatusMock.Setup(x => x.GetTrack()).Returns(track);

var spotifyProcessMock = new Moq.Mock<ISpotifyProcess>();
Expand Down
12 changes: 6 additions & 6 deletions EspionSpotify.Tests/SpotifyStatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ private void SpotifyStatusSpotifyStandingBy_ReturnsExpectingTrack()

var status = new SpotifyStatus(spotifyWindowInfo);

Assert.Equal(expectedTrack, status.Track);
Assert.Equal("Spotify", status.Track.ToString());
Assert.Equal(expectedTrack, status.CurrentTrack);
Assert.Equal("Spotify", status.CurrentTrack.ToString());
}

[Theory]
Expand All @@ -51,8 +51,8 @@ private void SpotifyStatusTrackPlaying_ReturnsExpectingTrack(string windowTitle,

var status = new SpotifyStatus(spotifyWindowInfo);

Assert.Equal(expectedTrack, status.Track);
Assert.Equal(windowTitle, status.Track.ToString());
Assert.Equal(expectedTrack, status.CurrentTrack);
Assert.Equal(windowTitle, status.CurrentTrack.ToString());
}

[Theory]
Expand All @@ -77,8 +77,8 @@ private void SpotifyStatusSpotifyPlayingAdOrUnknown_ReturnsExpectingTrack(string

var status = new SpotifyStatus(spotifyWindowInfo);

Assert.Equal(expectedTrack, status.Track);
Assert.Equal("Spotify - Ad", status.Track.ToString());
Assert.Equal(expectedTrack, status.CurrentTrack);
Assert.Equal("Spotify - Ad", status.CurrentTrack.ToString());
}
}
}
2 changes: 1 addition & 1 deletion EspionSpotify.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
8 changes: 4 additions & 4 deletions EspionSpotify/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace EspionSpotify
{
public class Analytics
{
private const string url = "https://www.google-analytics.com/collect";
private const string tid = "UA-125662919-1";
private const string ANALYTICS_URL = "https://www.google-analytics.com/collect";
private const string ANALYTICS_TID = "UA-125662919-1";

private readonly HttpClient client = new HttpClient();
private readonly string cid;
Expand Down Expand Up @@ -40,7 +40,7 @@ public async Task<bool> LogAction(string action)
var data = new Dictionary<string, string>
{
{ "v", "1" },
{ "tid", tid }, // App id
{ "tid", ANALYTICS_TID }, // App id
{ "t", "pageview" }, // Analytics type
{ "cid", cid }, // Client id
{ "cm", cm }, // Campaign medium, App version
Expand All @@ -56,7 +56,7 @@ public async Task<bool> LogAction(string action)
};

var content = new FormUrlEncodedContent(data);
var resp = await client.PostAsync(url, content);
var resp = await client.PostAsync(ANALYTICS_URL, content);

LastAction = action;
LastRequest = DateTime.Now;
Expand Down
23 changes: 20 additions & 3 deletions EspionSpotify/App.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="EspionSpotify.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down Expand Up @@ -75,6 +75,23 @@
<setting name="AudioEndPointDeviceIndex" serializeAs="String">
<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
- Accept the terms
Click on the new spotify application that you created and click on Edit the settings
- Set as "Redirect URI" the value "http://localhost:4002", Add and save it.
On the spotify app dashboard, get
- The "Client ID"
- The "Client Secret" (click on Show)
Paste the ids below
-->
<setting name="SpotifyAPIClientId" serializeAs="String">
<value></value>
</setting>
<setting name="SpotifyAPISecretId" serializeAs="String">
<value></value>
</setting>
</EspionSpotify.Properties.Settings>
</userSettings>
</configuration>
12 changes: 6 additions & 6 deletions EspionSpotify/AudioSessions/SpotifyAudioSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace EspionSpotify.AudioSessions
{
public class SpotifyAudioSession : MainAudioSession, ISpotifyAudioSession
{
private const int _sleepValue = 50;
private const int _numberOfSamples = 3;
private const int SLEEP_VALUE = 50;
private const int NUMBER_OF_SAMPLES = 3;

private Process _spytifyProcess;
private readonly ICollection<int> _spotifyProcessesIds;
Expand All @@ -34,20 +34,20 @@ public SpotifyAudioSession(int? audioEndPointDeviceIndex)

public void SleepWhileTheSongEnds()
{
for (var times = 1000; IsSpotifyCurrentlyPlaying() && times > 0; times -= _sleepValue * _numberOfSamples)
for (var times = 1000; IsSpotifyCurrentlyPlaying() && times > 0; times -= SLEEP_VALUE * NUMBER_OF_SAMPLES)
{
Thread.Sleep(_sleepValue);
Thread.Sleep(SLEEP_VALUE);
}
}

public bool IsSpotifyCurrentlyPlaying()
{
var samples = new List<double>();

for (var sample = 0; sample < _numberOfSamples; sample++)
for (var sample = 0; sample < NUMBER_OF_SAMPLES; sample++)
{
var spotifySoundValue = 0.0;
Thread.Sleep(_sleepValue);
Thread.Sleep(SLEEP_VALUE);

lock (SpotifyAudioSessionControls)
{
Expand Down
19 changes: 17 additions & 2 deletions EspionSpotify/EspionSpotify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EspionSpotify</RootNamespace>
<AssemblyName>Spytify</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -119,6 +119,7 @@
<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>
<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">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand All @@ -129,6 +130,12 @@
<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.3.0.0\lib\SpotifyAPI.Web.dll</HintPath>
</Reference>
<Reference Include="SpotifyAPI.Web.Auth, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SpotifyAPI.Web.Auth.3.1.2\lib\net46\SpotifyAPI.Web.Auth.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
Expand All @@ -143,6 +150,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.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Unosquare.Swan.Lite.0.38.1\lib\net452\Unosquare.Swan.Lite.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Analytics.cs" />
Expand Down Expand Up @@ -178,9 +191,11 @@
<Compile Include="AudioSessions\IMainAudioSession.cs" />
<Compile Include="AudioSessions\ISpotifyAudioSession.cs" />
<Compile Include="Enums\LanguageType.cs" />
<Compile Include="MediaTags\ILastFMAPI.cs" />
<Compile Include="MediaTags\ExternalAPI.cs" />
<Compile Include="MediaTags\IExternalAPI.cs" />
<Compile Include="MediaTags\IMP3Tags.cs" />
<Compile Include="MediaTags\MP3Tags.cs" />
<Compile Include="MediaTags\SpotifyAPI.cs" />
<Compile Include="Models\GitHub\Asset.cs" />
<Compile Include="Models\GitHub\Release.cs" />
<Compile Include="Models\GitHub\User.cs" />
Expand Down
8 changes: 4 additions & 4 deletions EspionSpotify/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class FileManager
private readonly UserSettings _userSettings;
private readonly Track _track;

private const int FirstSongNameCount = 1;
private const int FIRST_SONG_NAME_COUNT = 1;
private readonly string _windowsExlcudedChars = $"[{Regex.Escape(new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()))}]";

public FileManager(UserSettings userSettings, Track track)
Expand All @@ -22,7 +22,7 @@ public FileManager(UserSettings userSettings, Track track)
public string GetFileName(string songName, int count, string path = null)
{
var ending = _userSettings.MediaFormat.ToString().ToLower();
songName += count > FirstSongNameCount ? $"{_userSettings.TrackTitleSeparator}{count}" : string.Empty;
songName += count > FIRST_SONG_NAME_COUNT ? $"{_userSettings.TrackTitleSeparator}{count}" : string.Empty;
return path != null ? $"{path}\\{songName}.{ending}" : $"{songName}.{ending}";
}

Expand All @@ -43,8 +43,8 @@ public string BuildFileName(string path, bool includePath = true)
}

var songNameTrackNumber = Regex.Replace($"{track}{songName}", "\\s", _userSettings.TrackTitleSeparator);
var filename = GetFileName(songNameTrackNumber, FirstSongNameCount, includePath ? path : null);
var count = FirstSongNameCount;
var filename = GetFileName(songNameTrackNumber, FIRST_SONG_NAME_COUNT, includePath ? path : null);
var count = FIRST_SONG_NAME_COUNT;

while (_userSettings.DuplicateAlreadyRecordedTrack && File.Exists(GetFileName(songNameTrackNumber, count, path)))
{
Expand Down
7 changes: 4 additions & 3 deletions EspionSpotify/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ namespace EspionSpotify
{
internal static class GitHub
{
private const string _repoReleaseLink = "https://api.github.com/repos/jwallet/spy-spotify/releases/latest";
private const string REPO_RELEASE_LINK = "https://api.github.com/repos/jwallet/spy-spotify/releases/latest";
private const string SPYTIFY = "Spytify";

public static async void GetVersion()
{
if (!Uri.TryCreate(_repoReleaseLink, UriKind.Absolute, out var uri)) return;
if (!Uri.TryCreate(REPO_RELEASE_LINK, UriKind.Absolute, out var uri)) return;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
request.UserAgent = "Spytify";
request.UserAgent = SPYTIFY;

var content = new MemoryStream();

Expand Down
7 changes: 7 additions & 0 deletions EspionSpotify/MediaTags/ExternalApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EspionSpotify.MediaTags
{
public static class ExternalAPI
{
public static IExternalAPI Instance { get; set; } = new LastFMAPI();
}
}
10 changes: 10 additions & 0 deletions EspionSpotify/MediaTags/IExternalAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using EspionSpotify.Models;
using System.Threading.Tasks;

namespace EspionSpotify.MediaTags
{
public interface IExternalAPI
{
Task<bool> UpdateTrack(Track track);
}
}
10 changes: 0 additions & 10 deletions EspionSpotify/MediaTags/ILastFMAPI.cs

This file was deleted.

Loading

0 comments on commit 327e8d0

Please sign in to comment.