2021-10-29 22:35:34 +01:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using SpotifyAPI.Web;
|
|
|
|
|
|
|
|
namespace Selector.Cache {
|
|
|
|
|
|
|
|
public class CurrentlyPlayingDTO {
|
2021-11-05 07:58:48 +00:00
|
|
|
public CurrentlyPlayingContextDTO Context { get; set; }
|
2021-10-29 22:35:34 +01:00
|
|
|
public string Username { get; set; }
|
|
|
|
|
|
|
|
public FullTrack Track { get; set; }
|
|
|
|
public FullEpisode Episode { get; set; }
|
|
|
|
|
|
|
|
public static explicit operator CurrentlyPlayingDTO(ListeningChangeEventArgs e)
|
|
|
|
{
|
|
|
|
if(e.Current.Item is FullTrack track)
|
|
|
|
{
|
|
|
|
return new()
|
|
|
|
{
|
|
|
|
Context = e.Current,
|
|
|
|
Username = e.Username,
|
|
|
|
Track = track
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else if (e.Current.Item is FullEpisode episode)
|
|
|
|
{
|
|
|
|
return new()
|
|
|
|
{
|
|
|
|
Context = e.Current,
|
|
|
|
Username = e.Username,
|
|
|
|
Episode = episode
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new ArgumentException("Unknown item item");
|
|
|
|
}
|
|
|
|
}
|
2021-11-05 07:58:48 +00:00
|
|
|
|
|
|
|
public override string ToString() => $"[{Username}] [{Context}]";
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CurrentlyPlayingContextDTO
|
|
|
|
{
|
|
|
|
public Device Device { get; set; }
|
|
|
|
public string RepeatState { get; set; }
|
|
|
|
public bool ShuffleState { get; set; }
|
|
|
|
public Context Context { get; set; }
|
|
|
|
public long Timestamp { get; set; }
|
|
|
|
public int ProgressMs { get; set; }
|
|
|
|
public bool IsPlaying { get; set; }
|
|
|
|
|
|
|
|
public string CurrentlyPlayingType { get; set; }
|
|
|
|
public Actions Actions { get; set; }
|
|
|
|
|
|
|
|
public static implicit operator CurrentlyPlayingContextDTO(CurrentlyPlayingContext context)
|
|
|
|
{
|
|
|
|
return new CurrentlyPlayingContextDTO {
|
|
|
|
Device = context.Device,
|
|
|
|
RepeatState = context.RepeatState,
|
|
|
|
ShuffleState = context.ShuffleState,
|
|
|
|
Context = context.Context,
|
|
|
|
Timestamp = context.Timestamp,
|
|
|
|
ProgressMs = context.ProgressMs,
|
|
|
|
IsPlaying = context.IsPlaying,
|
|
|
|
CurrentlyPlayingType = context.CurrentlyPlayingType,
|
|
|
|
Actions = context.Actions
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString() => $"{IsPlaying}, {Device?.DisplayString()}";
|
2021-10-29 22:35:34 +01:00
|
|
|
}
|
|
|
|
}
|