-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaResponse.cs
60 lines (57 loc) · 1.67 KB
/
MediaResponse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using SimpleJSON;
namespace CobaltSharp;
/// <summary>
/// The object used to get info on where to download/stream media
/// </summary>
public struct MediaResponse
{
/// <summary>
/// API Response Status
/// </summary>
public Status status;
/// <summary>
/// Text
/// </summary>
public string text;
/// <summary>
/// Direct link to a file or to cobalt's stream
/// </summary>
public string? url;
/// <summary>
/// Type of Picker
/// </summary>
public PickerType? pickerType;
/// <summary>
/// Picker Items
/// </summary>
public PickerItem[] picker;
/// <summary>
/// Direct link to a file or to cobalt's stream
/// </summary>
public string? audio;
internal MediaResponse(string response)
{
JSONNode jsonObject = JSON.Parse(response);
status = StatusHelper.FomString(jsonObject["status"].Value);
text = jsonObject["text"].Value;
if (jsonObject.HasKey("url"))
url = jsonObject["url"].Value;
if (jsonObject.HasKey("pickerType"))
{
PickerType pt;
Enum.TryParse(jsonObject["pickerType"].Value, out pt);
pickerType = pt;
}
if (jsonObject.HasKey("picker"))
{
List<PickerItem> items = new();
foreach (JSONNode jsonNode in jsonObject["picker"].Values)
items.Add(new PickerItem(jsonNode));
picker = items.ToArray();
}
else
picker = Array.Empty<PickerItem>();
if (jsonObject.HasKey("audio"))
audio = jsonObject["audio"].Value;
}
}