Skip to content

Commit

Permalink
Tracks are detected as ads
Browse files Browse the repository at this point in the history
close issue #107
  • Loading branch information
jwallet committed Aug 25, 2019
1 parent 060cf91 commit 9c667b5
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 270 deletions.
2 changes: 1 addition & 1 deletion EspionSpotify.Tests/SpotifyStatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void SpotifyStatusSpotifyPlayingAdOrUnknown_ReturnsExpectingTrack(string
var status = new SpotifyStatus(spotifyWindowInfo);

Assert.Equal(expectedTrack, status.CurrentTrack);
Assert.Equal("Spotify - Ad", status.CurrentTrack.ToString());
Assert.Equal(expectedTrack.ToString(), status.CurrentTrack.ToString());
}
}
}
6 changes: 4 additions & 2 deletions EspionSpotify/Models/SpotifyWindowInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace EspionSpotify.Models
using EspionSpotify.Spotify;

namespace EspionSpotify.Models
{
public class SpotifyWindowInfo
{
public string WindowTitle { get; set; }
public bool IsPlaying { get; set; }

public bool IsTitledSpotify { get => WindowTitle?.ToLowerInvariant().Equals("spotify") ?? false; }
public bool IsTitledSpotify { get => SpotifyStatus.WindowTitleIsSpotify(WindowTitle); }
}
}
2 changes: 1 addition & 1 deletion EspionSpotify/Models/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override string ToString()

if (Ad)
{
song = $"{SPOTIFY} - {FrmEspionSpotify.Rm?.GetString($"logAd") ?? "Ad"}";
song = Artist;
}

return song;
Expand Down
6 changes: 3 additions & 3 deletions EspionSpotify/Spotify/SpotifyConnect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using EspionSpotify.Spotify;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -7,7 +8,6 @@ namespace EspionSpotify
{
public class SpotifyConnect
{
private const string SPOTIFY = "spotify";
private static readonly TimeSpan RunSpotifyInterval = TimeSpan.FromSeconds(3);

private static readonly string[] SpotifyPossiblePaths =
Expand Down Expand Up @@ -73,7 +73,7 @@ public static bool IsSpotifyInstalled()

public static bool IsSpotifyRunning()
{
return Process.GetProcessesByName(SPOTIFY).Length >= 1;
return Process.GetProcessesByName(SpotifyStatus.SPOTIFY).Length >= 1;
}
}
}
4 changes: 1 addition & 3 deletions EspionSpotify/Spotify/SpotifyProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace EspionSpotify
{
public class SpotifyProcess: ISpotifyProcess
{
private const string SPOTIFY = "Spotify";

private readonly int? _spotifyProcessId;
private readonly ISpotifyAudioSession _spotifyAudioSession;

Expand Down Expand Up @@ -65,7 +63,7 @@ public static ICollection<Process> GetSpotifyProcesses()

foreach (var process in Process.GetProcesses())
{
if (process.ProcessName.ToLowerInvariant().Equals(SPOTIFY.ToLowerInvariant()))
if (SpotifyStatus.WindowTitleIsSpotify(process.ProcessName))
{
spotifyProcesses.Add(process);
}
Expand Down
8 changes: 8 additions & 0 deletions EspionSpotify/Spotify/SpotifyStatus.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using EspionSpotify.MediaTags;
using EspionSpotify.Models;
using System;
using System.Linq;

namespace EspionSpotify.Spotify
{
public class SpotifyStatus: ISpotifyStatus
{
public const string SPOTIFY = "spotify";

public Track CurrentTrack { get; set; }

private string[] _windowTitleSeparator { get; }

public static bool WindowTitleIsSpotify(string title)
{
return title?.ToLowerInvariant().Equals(SPOTIFY) ?? false;
}

public SpotifyStatus(SpotifyWindowInfo spotifyWindowInfo)
{
_windowTitleSeparator = new[] {" - "};
Expand Down
8 changes: 5 additions & 3 deletions EspionSpotify/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class Watcher : IWatcher
public bool NumTrackActivated { get => _userSettings.OrderNumber.HasValue; }
public bool AdPlaying { get => _currentTrack.Ad; }
public string SongTitle { get => _currentTrack.ToString(); }
public bool IsRecordUnknownActive { get => _userSettings.RecordUnknownTrackTypeEnabled && _currentTrack.Playing && !SpotifyStatus.WindowTitleIsSpotify(_currentTrack.ToString()); }
public bool IsTypeAllowed
{
get => _currentTrack.IsNormal() || (_userSettings.RecordUnknownTrackTypeEnabled && _currentTrack.Playing);
get => _currentTrack.IsNormal() || IsRecordUnknownActive;
}
public bool IsOldSong
{
Expand Down Expand Up @@ -90,10 +91,11 @@ public bool IsNewTrack(Track track)
return false;
}

_isPlaying = track.Playing;
_currentTrack = track;
_isPlaying = _currentTrack.Playing;

_form.UpdatePlayingTitle(SongTitle);
var adTitle = _currentTrack.Ad && !SpotifyStatus.WindowTitleIsSpotify(_currentTrack.ToString()) ? $"{FrmEspionSpotify.Rm?.GetString($"logAd") ?? "Ad"}: " : "";
_form.UpdatePlayingTitle($"{adTitle}{SongTitle}");

MutesSpotifyAds(AdPlaying);

Expand Down
Loading

0 comments on commit 9c667b5

Please sign in to comment.