| 1 |
using System.ComponentModel; |
| 2 |
|
| 3 |
namespace Blog.Models; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
public sealed record RvrbSnapshot( |
| 11 |
DateTimeOffset GeneratedAt, |
| 12 |
RvrbLive? Live, |
| 13 |
RvrbTotals Totals, |
| 14 |
IReadOnlyList<RvrbDay> PlaysPerDay, |
| 15 |
IReadOnlyList<RvrbDj> TopDjs, |
| 16 |
IReadOnlyList<RvrbTrack> TopTracks, |
| 17 |
IReadOnlyList<RvrbArtist> TopArtists, |
| 18 |
IReadOnlyList<RvrbPlay> RecentPlays); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public sealed record RvrbLive( |
| 25 |
string? ChannelId, |
| 26 |
RvrbCurrentTrack? CurrentTrack, |
| 27 |
int Dopes, |
| 28 |
int Stars, |
| 29 |
bool AutoDoped, |
| 30 |
bool AutoStarred, |
| 31 |
int QueuedTracks, |
| 32 |
int KnownBots, |
| 33 |
IReadOnlyList<RvrbDjSlot> Djs, |
| 34 |
TimeSpan Lap); |
| 35 |
|
| 36 |
|
| 37 |
public sealed record RvrbCurrentTrack( |
| 38 |
string? SpotifyTrackId, |
| 39 |
string? Name, |
| 40 |
IReadOnlyList<string> ArtistNames, |
| 41 |
IReadOnlyList<string> SpotifyArtistIds, |
| 42 |
TimeSpan? Duration, |
| 43 |
string? AlbumArt, |
| 44 |
TimeSpan? Elapsed, |
| 45 |
TimeSpan? Remaining) |
| 46 |
{ |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public double? Progress => Duration is { TotalMilliseconds: > 0 } total && Elapsed is { } elapsed |
| 52 |
? Math.Clamp(elapsed.TotalMilliseconds / total.TotalMilliseconds, 0, 1) |
| 53 |
: null; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
public sealed record RvrbDjSlot( |
| 58 |
string RvrbId, |
| 59 |
string? Name, |
| 60 |
TimeSpan AverageTrack, |
| 61 |
int PlayCount, |
| 62 |
bool Measured, |
| 63 |
bool Current, |
| 64 |
TimeSpan Wait); |
| 65 |
|
| 66 |
|
| 67 |
public sealed record RvrbTotals( |
| 68 |
long Plays, |
| 69 |
long Votes, |
| 70 |
long Dopes, |
| 71 |
long Stars, |
| 72 |
long Users, |
| 73 |
long Djs, |
| 74 |
long Tracks, |
| 75 |
long Artists, |
| 76 |
DateTimeOffset? FirstPlayAt, |
| 77 |
DateTimeOffset? LastPlayAt); |
| 78 |
|
| 79 |
|
| 80 |
public sealed record RvrbDay(DateOnly Date, int Plays); |
| 81 |
|
| 82 |
|
| 83 |
public sealed record RvrbDj(string Name, string? UserName, int Plays, int Dopes, int Stars, int Score); |
| 84 |
|
| 85 |
|
| 86 |
public sealed record RvrbTrack( |
| 87 |
string TrackName, |
| 88 |
IReadOnlyList<string> ArtistNames, |
| 89 |
string? SpotifyTrackId, |
| 90 |
IReadOnlyList<string> SpotifyArtistIds, |
| 91 |
int Plays, |
| 92 |
int Dopes, |
| 93 |
int Stars, |
| 94 |
int Score); |
| 95 |
|
| 96 |
|
| 97 |
public sealed record RvrbArtist( |
| 98 |
string ArtistName, |
| 99 |
string? SpotifyArtistId, |
| 100 |
int Plays, |
| 101 |
int Dopes, |
| 102 |
int Stars, |
| 103 |
int Score); |
| 104 |
|
| 105 |
|
| 106 |
public sealed record RvrbPlay( |
| 107 |
DateTimeOffset PlayedAt, |
| 108 |
string? Dj, |
| 109 |
string TrackName, |
| 110 |
IReadOnlyList<string> ArtistNames, |
| 111 |
string? SpotifyTrackId, |
| 112 |
IReadOnlyList<string> SpotifyArtistIds, |
| 113 |
TimeSpan? Duration, |
| 114 |
int Dopes, |
| 115 |
int Stars, |
| 116 |
int Score); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
[ImmutableObject(true)] |
| 126 |
public sealed record RvrbStatus(DateTimeOffset FetchedAt, RvrbSnapshot? Snapshot, string? Error) |
| 127 |
{ |
| 128 |
public static RvrbStatus Reachable(RvrbSnapshot snapshot) => |
| 129 |
new(DateTimeOffset.UtcNow, snapshot, null); |
| 130 |
|
| 131 |
public static RvrbStatus Unreachable(string error) => new(DateTimeOffset.UtcNow, null, error); |
| 132 |
} |