Spotify.NET/SpotifyAPI/SpotifyAPI.cs

85 lines
2.4 KiB
C#
Raw Normal View History

2014-01-07 15:26:03 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Windows;
using System.Management;
using System.Diagnostics;
2014-01-08 22:22:54 +00:00
using System.Drawing;
2014-01-07 15:26:03 +00:00
namespace SpotifyAPIv1
{
public class SpotifyAPI
{
2014-02-01 12:52:33 +00:00
SpotifyMusicHandler mh;
2014-01-07 15:26:03 +00:00
RemoteHandler rh;
2014-02-01 12:52:33 +00:00
SpotifyEventHandler eh;
2014-01-07 15:26:03 +00:00
public SpotifyAPI()
{
rh = RemoteHandler.GetInstance();
2014-02-01 12:52:33 +00:00
mh = new SpotifyMusicHandler();
eh = new SpotifyEventHandler(this, mh);
2014-01-07 15:26:03 +00:00
}
public void Connect()
{
rh.Init();
}
2014-02-01 12:52:33 +00:00
public SpotifyMusicHandler GetMusicHandler()
2014-01-08 22:22:54 +00:00
{
return mh;
}
2014-02-01 12:52:33 +00:00
public SpotifyEventHandler GetEventHandler()
2014-01-08 22:22:54 +00:00
{
return eh;
}
2014-02-01 12:52:33 +00:00
public static Boolean IsSpotifyRunning()
{
if (Process.GetProcessesByName("spotify").Length < 1)
{
return false;
}
else
return true;
}
public static Boolean IsSpotifyWebHelperRunning()
2014-01-07 15:26:03 +00:00
{
if (Process.GetProcessesByName("SpotifyWebHelper").Length < 1)
{
2014-02-01 12:52:33 +00:00
return false;
2014-01-07 15:26:03 +00:00
}
else
return true;
}
2014-02-01 12:52:33 +00:00
public void RunSpotify()
{
if(!IsSpotifyRunning())
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Spotify\\spotify.exe");
}
public void RunSpotifyWebHelper()
{
if (!IsSpotifyWebHelperRunning())
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Spotify\\Data\\SpotifyWebHelper.exe");
}
public Boolean IsValidSpotifyURL(String url)
{
String[] types = new String[] { "track","album","local","artist"};
String[] split = url.Split(':');
if (split.Length < 3)
return false;
return split[0] == "spotify" && Array.IndexOf(types, split[1]) > -1 && split[2].Length == 22;
}
2014-01-07 15:26:03 +00:00
public void Update()
{
2014-02-01 12:52:33 +00:00
if (!SpotifyAPI.IsSpotifyWebHelperRunning())
return;
2014-01-08 22:22:54 +00:00
mh.Update(rh.Update());
2014-02-01 12:52:33 +00:00
rh.SendVolumeRequest();
2014-01-07 15:26:03 +00:00
}
}
}