Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallet committed Sep 15, 2018
2 parents 7b44304 + de4b8e6 commit 36aeab7
Show file tree
Hide file tree
Showing 15 changed files with 912 additions and 69 deletions.
67 changes: 67 additions & 0 deletions EspionSpotify/Analytics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading.Tasks;

namespace EspionSpotify
{
public class Analytics
{
private const string url = "https://www.google-analytics.com/collect";
private const string tid = "UA-125662919-1";

private readonly HttpClient client = new HttpClient();
private readonly string cid;
private readonly string cm;
private readonly string ul;
private readonly string cs;

public DateTime LastRequest { get; set; } = new DateTime();
public string LastAction { get; set; } = string.Empty;

public Analytics(string clientId, string version)
{
cid = clientId;
cm = version;
ul = CultureInfo.CurrentCulture.Name;
cs = Environment.OSVersion.ToString();
}

public static string GenerateCID()
{
return Guid.NewGuid().ToString();
}

public async Task<bool> LogAction(string action)
{
if (LastAction.Equals(action) && DateTime.Now - LastRequest < TimeSpan.FromMinutes(5)) return false;

var data = new Dictionary<string, string>
{
{ "v", "1" },
{ "tid", tid }, // App id
{ "t", "pageview" }, // Analytics type
{ "cid", cid }, // Client id
{ "cm", cm }, // Campaign medium, App version
{ "av", cm }, // App version
{ "cn", "Spytify" }, // Campaign name
{ "an", "Spytify" }, // App name
{ "cs", cs}, // Campaign source, OS Version
{ "ul", ul }, // User Language
{ "dh", "jwallet.github.io/spy-spotify" }, // Document host
{ "dl", $"/{action}" }, // Document link
{ "dt", action }, // Document title
{ "cd", action } // Screen name
};

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

LastAction = action;
LastRequest = DateTime.Now;

return resp.IsSuccessStatusCode;
}
}
}
3 changes: 3 additions & 0 deletions EspionSpotify/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<setting name="RecordUnknownTrackTypeEnabled" serializeAs="String">
<value>False</value>
</setting>
<setting name="AnalyticsCID" serializeAs="String">
<value />
</setting>
</EspionSpotify.Properties.Settings>
</userSettings>
<runtime>
Expand Down
18 changes: 12 additions & 6 deletions EspionSpotify/AudioSessions/SpotifyAudioSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ public bool IsSpotifyCurrentlyPlaying()
var spotifySoundValue = 0.0;
Thread.Sleep(_sleepValue);

foreach (var audioSession in _spotifyAudioSessionControls)
lock (_spotifyAudioSessionControls)
{
var soundValue = Math.Round(audioSession.AudioMeterInformation.MasterPeakValue * 100.0, 1);
if (soundValue == 0.0) continue;
foreach (var audioSession in _spotifyAudioSessionControls)
{
var soundValue = Math.Round(audioSession.AudioMeterInformation.MasterPeakValue * 100.0, 1);
if (soundValue == 0.0) continue;

spotifySoundValue = soundValue;
spotifySoundValue = soundValue;
}
}

samples.Add(spotifySoundValue);
Expand All @@ -60,9 +63,12 @@ public bool IsSpotifyCurrentlyPlaying()

public void SetSpotifyToMute(bool mute)
{
foreach (var audioSession in _spotifyAudioSessionControls)
lock (_spotifyAudioSessionControls)
{
audioSession.SimpleAudioVolume.Mute = mute;
foreach (var audioSession in _spotifyAudioSessionControls)
{
audioSession.SimpleAudioVolume.Mute = mute;
}
}
}

Expand Down
76 changes: 76 additions & 0 deletions EspionSpotify/Controls/MetroTile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EspionSpotify.Controls
{
public class MetroTile : MetroFramework.Controls.MetroTile
{
private bool _isFocused = false;
private bool _isHovered = false;

protected override void OnPaintForeground(PaintEventArgs e)
{
base.OnPaintForeground(e);

Color color = Color.FromArgb(175, 240, 200);

if (_isHovered || _isFocused)
{
color = Color.FromArgb(30, 215, 96);
}

using (Pen p = new Pen(color))
{
p.Width = 3;
Rectangle borderRect = new Rectangle(1, 1, Width - 3, Height - 3);
e.Graphics.DrawRectangle(p, borderRect);
}
}
protected override void OnGotFocus(EventArgs e)
{
_isFocused = true;
Invalidate();

base.OnGotFocus(e);
}

protected override void OnLostFocus(EventArgs e)
{
_isFocused = false;
_isHovered = false;

Invalidate();
base.OnLostFocus(e);
}

protected override void OnLeave(EventArgs e)
{
Task.Run(async () =>
{
await Task.Delay(150);
base.OnLeave(e);
});
}

protected override void OnMouseEnter(EventArgs e)
{
_isHovered = true;
Invalidate();

base.OnMouseEnter(e);
}

protected override void OnMouseLeave(EventArgs e)
{
_isHovered = false;
Invalidate();

base.OnMouseLeave(e);
}
}
}
8 changes: 8 additions & 0 deletions EspionSpotify/EspionSpotify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -146,9 +150,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Analytics.cs" />
<Compile Include="Controls\MetroComboBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\MetroTile.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\MetroTrackBar.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
2 changes: 1 addition & 1 deletion EspionSpotify/Models/SpotifyWindowInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class SpotifyWindowInfo
public string WindowTitle { get; set; }
public bool IsPlaying { get; set; }

public bool IsTitledSpotify() => WindowTitle?.ToLowerInvariant().Equals("spotify") ?? false;
public bool IsTitledSpotify { get => WindowTitle?.ToLowerInvariant().Equals("spotify") ?? false; }
}
}
12 changes: 12 additions & 0 deletions EspionSpotify/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions EspionSpotify/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
<Setting Name="RecordUnknownTrackTypeEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="AnalyticsCID" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
2 changes: 1 addition & 1 deletion EspionSpotify/Spotify/SpotifyStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void SetSongInfo(ref SpotifyWindowInfo spotifyWindowInfo)
Track = new Track
{
Ad = isAd && isPlaying,
Playing = isPlaying || !spotifyWindowInfo.IsTitledSpotify(),
Playing = isPlaying || !spotifyWindowInfo.IsTitledSpotify,
Artist = GetTitleTag(tags, 1),
Title = GetTitleTag(tags, 2),
TitleExtended = GetTitleTag(tags, 3),
Expand Down
99 changes: 99 additions & 0 deletions EspionSpotify/english.Designer.cs

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

Loading

0 comments on commit 36aeab7

Please sign in to comment.