Spotify.NET/SpotifyAPI/SpotifyAPI.cs
2014-02-01 13:52:33 +01:00

85 lines
2.4 KiB
C#

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;
using System.Drawing;
namespace SpotifyAPIv1
{
public class SpotifyAPI
{
SpotifyMusicHandler mh;
RemoteHandler rh;
SpotifyEventHandler eh;
public SpotifyAPI()
{
rh = RemoteHandler.GetInstance();
mh = new SpotifyMusicHandler();
eh = new SpotifyEventHandler(this, mh);
}
public void Connect()
{
rh.Init();
}
public SpotifyMusicHandler GetMusicHandler()
{
return mh;
}
public SpotifyEventHandler GetEventHandler()
{
return eh;
}
public static Boolean IsSpotifyRunning()
{
if (Process.GetProcessesByName("spotify").Length < 1)
{
return false;
}
else
return true;
}
public static Boolean IsSpotifyWebHelperRunning()
{
if (Process.GetProcessesByName("SpotifyWebHelper").Length < 1)
{
return false;
}
else
return true;
}
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;
}
public void Update()
{
if (!SpotifyAPI.IsSpotifyWebHelperRunning())
return;
mh.Update(rh.Update());
rh.SendVolumeRequest();
}
}
}