Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions SpotifyAPI.Core/Local/Enums/AlbumArtSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SpotifyAPI.Local.Enums
{
public enum AlbumArtSize
{
Size160,
Size320,
Size640
}
}
12 changes: 12 additions & 0 deletions SpotifyAPI.Core/Local/Enums/UriType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SpotifyAPI.Local.Enums
{
public enum UriType
{
none,
track,
album,
artist,
playlist,
user
}
}
29 changes: 29 additions & 0 deletions SpotifyAPI.Core/Local/ExtendedWebClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Net;
using System.Text;

namespace SpotifyAPI.Local
{
internal class ExtendedWebClient : WebClient
{
public int Timeout { get; set; }

public ExtendedWebClient()
{
// TODO Remove once SSL Issues are resolved #115
ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
Encoding = Encoding.UTF8;
Timeout = 2000;
Headers.Add("Origin", "https://embed.spotify.com");
Headers.Add("Referer", "https://embed.spotify.com/?uri=spotify:track:5Zp4SWOpbuOdnsxLqwgutt");
}

protected override WebRequest GetWebRequest(Uri address)
{
WebRequest webRequest = base.GetWebRequest(address);
if (webRequest != null)
webRequest.Timeout = Timeout;
return webRequest;
}
}
}
39 changes: 39 additions & 0 deletions SpotifyAPI.Core/Local/LocalEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using SpotifyAPI.Local.Models;
using System;

namespace SpotifyAPI.Local
{
/// <summary>
/// Event gets triggered, when the Track is changed
/// </summary>
public class TrackChangeEventArgs
{
public Track OldTrack { get; set; }
public Track NewTrack { get; set; }
}

/// <summary>
/// Event gets triggered, when the Playin-state is changed (e.g Play --> Pause)
/// </summary>
public class PlayStateEventArgs
{
public Boolean Playing { get; set; }
}

/// <summary>
/// Event gets triggered, when the volume changes
/// </summary>
public class VolumeChangeEventArgs
{
public double OldVolume { get; set; }
public double NewVolume { get; set; }
}

/// <summary>
/// Event gets triggered, when the tracktime changes
/// </summary>
public class TrackTimeChangeEventArgs
{
public double TrackTime { get; set; }
}
}
25 changes: 25 additions & 0 deletions SpotifyAPI.Core/Local/Models/CFID.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace SpotifyAPI.Local.Models
{
/// <summary>
/// JSON Response, used internaly
/// </summary>
internal class Cfid
{
public Error Error { get; set; }
public string Token { get; set; }
public string Version { get; set; }
public string ClientVersion { get; set; }
public Boolean Running { get; set; }
}

/// <summary>
/// JSON Response, used internaly
/// </summary>
internal class Error
{
public string Type { get; set; }
public string Message { get; set; }
}
}
14 changes: 14 additions & 0 deletions SpotifyAPI.Core/Local/Models/OpenGraphState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System;

namespace SpotifyAPI.Local.Models
{
public class OpenGraphState
{
[JsonProperty("private_session")]
public Boolean PrivateSession { get; set; }

[JsonProperty("posting_disabled")]
public Boolean PostingDisabled { get; set; }
}
}
22 changes: 22 additions & 0 deletions SpotifyAPI.Core/Local/Models/SpotifyResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;
using System;

namespace SpotifyAPI.Local.Models
{
public class SpotifyResource
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("uri")]
public string Uri { get; set; }

[JsonProperty("location")]
public TrackResourceLocation Location { get; set; }

public SpotifyUri ParseUri()
{
return SpotifyUri.Parse(Uri);
}
}
}
60 changes: 60 additions & 0 deletions SpotifyAPI.Core/Local/Models/SpotifyUri.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using SpotifyAPI.Local.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpotifyAPI.Local.Models
{
public class SpotifyUri
{
private readonly Dictionary<UriType, string> _properties = new Dictionary<UriType, string>();

public string Base { get; }
public UriType Type => _properties?.LastOrDefault().Key ?? UriType.none;
public string Id => _properties?.LastOrDefault().Value;

public SpotifyUri(string uriBase, Dictionary<UriType, string> properties)
{
Base = uriBase;
_properties = properties;
}

public SpotifyUri(string uriBase, UriType uriType, string uriId)
{
Base = uriBase;
_properties.Add(uriType, uriId);
}

public string GetUriPropValue(UriType type)
{
return !_properties.ContainsKey(type) ? null : _properties[type];
}

public static SpotifyUri Parse(string uri)
{
if (string.IsNullOrEmpty(uri))
throw new ArgumentNullException("Uri");

string[] props = uri.Split(':');
if (props.Length < 3 || !Enum.TryParse(props[1], out UriType uriType))
throw new ArgumentException("Unexpected Uri");

Dictionary<UriType, string> properties = new Dictionary<UriType, string> { { uriType, props[2] } };

for (int index = 3; index < props.Length; index += 2)
{
if (Enum.TryParse(props[index], out UriType type))
properties.Add(type, props[index + 1]);
}

return new SpotifyUri(props[0], properties);
}

public override string ToString()
{
return $"{Base}:{string.Join(":", _properties.SelectMany(x => new[] { x.Key.ToString(), x.Value }))}";
}
}
}
52 changes: 52 additions & 0 deletions SpotifyAPI.Core/Local/Models/StatusResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Newtonsoft.Json;

namespace SpotifyAPI.Local.Models
{
public class StatusResponse
{
[JsonProperty("version")]
public int Version { get; set; }

[JsonProperty("client_version")]
public string ClientVersion { get; set; }

[JsonProperty("playing")]
public bool Playing { get; set; }

[JsonProperty("shuffle")]
public bool Shuffle { get; set; }

[JsonProperty("repeat")]
public bool Repeat { get; set; }

[JsonProperty("play_enabled")]
public bool PlayEnabled { get; set; }

[JsonProperty("prev_enabled")]
public bool PrevEnabled { get; set; }

[JsonProperty("next_enabled")]
public bool NextEnabled { get; set; }

[JsonProperty("track")]
public Track Track { get; set; }

[JsonProperty("playing_position")]
public double PlayingPosition { get; set; }

[JsonProperty("server_time")]
public int ServerTime { get; set; }

[JsonProperty("volume")]
public double Volume { get; set; }

[JsonProperty("online")]
public bool Online { get; set; }

[JsonProperty("open_graph_state")]
public OpenGraphState OpenGraphState { get; set; }

[JsonProperty("running")]
public bool Running { get; set; }
}
}
Loading