Skip to content

Commit d0211fd

Browse files
author
Jonas Dellinger
committed
Merge pull request #14 from gusper/master
Added support for the beta version of Spotify Desktop to the SpotifyLocalAPIClass
2 parents b019e3d + bd5d775 commit d0211fd

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

SpotifyAPI/SpoitfyLocalAPI/SpotifyAPI.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ public class SpotifyLocalAPIClass
1111
SpotifyMusicHandler mh;
1212
RemoteHandler rh;
1313
SpotifyEventHandler eh;
14-
public SpotifyLocalAPIClass()
14+
static bool betaMode;
15+
16+
public SpotifyLocalAPIClass(bool betaMode = false)
1517
{
1618
rh = RemoteHandler.GetInstance();
1719
mh = new SpotifyMusicHandler();
1820
eh = new SpotifyEventHandler(this, mh);
21+
SpotifyLocalAPIClass.betaMode = betaMode;
1922
}
2023

2124
/// <summary>
@@ -26,6 +29,7 @@ public Boolean Connect()
2629
{
2730
return rh.Init();
2831
}
32+
2933
/// <summary>
3034
/// Returns the MusicHandler
3135
/// </summary>
@@ -34,6 +38,7 @@ public SpotifyMusicHandler GetMusicHandler()
3438
{
3539
return mh;
3640
}
41+
3742
/// <summary>
3843
/// Returns the EventHanlder
3944
/// </summary>
@@ -42,62 +47,81 @@ public SpotifyEventHandler GetEventHandler()
4247
{
4348
return eh;
4449
}
50+
4551
/// <summary>
4652
/// Checks if Spotify is running
4753
/// </summary>
4854
/// <returns>True, if it's running, false if not</returns>
4955
public static Boolean IsSpotifyRunning()
5056
{
51-
if (Process.GetProcessesByName("spotify").Length < 1)
57+
var procName = (betaMode) ? "spotifybeta" : "spotify";
58+
59+
if (Process.GetProcessesByName(procName).Length < 1)
5260
return false;
61+
5362
return true;
5463
}
64+
5565
/// <summary>
5666
/// Checks if Spotify's WebHelper is running (Needed for API Calls)
5767
/// </summary>
5868
/// <returns>True, if it's running, false if not</returns>
5969
public static Boolean IsSpotifyWebHelperRunning()
6070
{
61-
if (Process.GetProcessesByName("SpotifyWebHelper").Length < 1)
71+
var procName = (betaMode) ? "spotifybetawebhelper" : "spotifywebhelper";
72+
73+
if (Process.GetProcessesByName(procName).Length < 1)
6274
return false;
75+
6376
return true;
6477
}
78+
6579
/// <summary>
6680
/// Runs Spotify
6781
/// </summary>
6882
public void RunSpotify()
6983
{
70-
if(!IsSpotifyRunning())
71-
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Spotify\\spotify.exe");
84+
var pathToExe = (betaMode) ? @"\spotifybeta\spotifybeta.exe" : @"\spotify\spotify.exe";
85+
86+
if (!IsSpotifyRunning())
87+
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + pathToExe);
7288
}
89+
7390
/// <summary>
7491
/// Runs Spotify's WebHelper
7592
/// </summary>
7693
public void RunSpotifyWebHelper()
7794
{
95+
var pathToExe = (betaMode) ? @"\spotifybeta\spotifybetawebhelper.exe" : @"\spotify\data\spotifywebhelper.exe";
96+
7897
if (!IsSpotifyWebHelperRunning())
79-
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Spotify\\Data\\SpotifyWebHelper.exe");
98+
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + pathToExe);
8099
}
100+
81101
/// <summary>
82102
/// Checks for a valid SpotifyURL (Still not finished)
83103
/// </summary>
84104
/// <param name="url">The Spotify URI starting with "spotify:"</param>
85105
/// <returns>True if the URI is valid, false if not</returns>
86106
public static Boolean IsValidSpotifyURI(String uri)
87107
{
88-
String[] types = new String[] { "track","album","local","artist"};
108+
String[] types = new String[] { "track", "album", "local", "artist" };
89109
String[] split = uri.Split(':');
110+
90111
if (split.Length < 3)
91112
return false;
113+
92114
return split[0] == "spotify" && Array.IndexOf(types, split[1]) > -1 && split[2].Length == 22;
93115
}
116+
94117
/// <summary>
95118
/// Updates and Fetches all current information about the current track etc.
96119
/// </summary>
97120
public void Update()
98121
{
99122
if (!SpotifyLocalAPIClass.IsSpotifyWebHelperRunning() || !SpotifyLocalAPIClass.IsSpotifyRunning())
100123
return;
124+
101125
mh.Update(rh.Update());
102126
}
103127
}

0 commit comments

Comments
 (0)