Improve SpotifyGame (#1039)

* Initial commit

* Add TrackUrl

* Rename AlbumArt to AlbumArtUrl for consistency
This commit is contained in:
Still Hsu
2018-04-29 23:15:24 +08:00
committed by Christopher F
parent 3631886d2b
commit 73dc884d47
3 changed files with 17 additions and 8 deletions

View File

@@ -34,6 +34,8 @@ namespace Discord
public static string GetSpotifyAlbumArtUrl(string albumArtId)
=> $"https://i.scdn.co/image/{albumArtId}";
public static string GetSpotifyDirectUrl(string trackId)
=> $"https://open.spotify.com/track/{trackId}";
private static string FormatToExtension(ImageFormat format, string imageId)
{

View File

@@ -7,17 +7,20 @@ namespace Discord
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SpotifyGame : Game
{
public IEnumerable<string> Artists { get; internal set; }
public string AlbumArt { get; internal set; }
public IReadOnlyCollection<string> Artists { get; internal set; }
public string AlbumTitle { get; internal set; }
public string TrackTitle { get; internal set; }
public string SyncId { get; internal set; }
public string SessionId { get; internal set; }
public TimeSpan? Duration { get; internal set; }
public string TrackId { get; internal set; }
public string SessionId { get; internal set; }
public string AlbumArtUrl { get; internal set; }
public string TrackUrl { get; internal set; }
internal SpotifyGame() { }
public override string ToString() => Name;
public override string ToString() => $"{string.Join(", ", Artists)} - {TrackTitle} ({Duration})";
private string DebuggerDisplay => $"{Name} (Spotify)";
}
}

View File

@@ -1,3 +1,6 @@
using System.Collections.Immutable;
using System.Linq;
namespace Discord.WebSocket
{
internal static class EntityExtensions
@@ -15,12 +18,13 @@ namespace Discord.WebSocket
{
Name = model.Name,
SessionId = model.SessionId.GetValueOrDefault(),
SyncId = model.SyncId.Value,
TrackId = model.SyncId.Value,
TrackUrl = CDN.GetSpotifyDirectUrl(model.SyncId.Value),
AlbumTitle = albumText,
TrackTitle = model.Details.GetValueOrDefault(),
Artists = model.State.GetValueOrDefault()?.Split(';'),
Artists = model.State.GetValueOrDefault()?.Split(';').Select(x=>x?.Trim()).ToImmutableArray(),
Duration = timestamps?.End - timestamps?.Start,
AlbumArt = albumArtId != null ? CDN.GetSpotifyAlbumArtUrl(albumArtId) : null,
AlbumArtUrl = albumArtId != null ? CDN.GetSpotifyAlbumArtUrl(albumArtId) : null,
Type = ActivityType.Listening
};
}