This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Yamux.cs
executable file
·281 lines (251 loc) · 10 KB
/
Yamux.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using Gdk;
using Gtk;
using Newtonsoft.Json.Linq;
using Pango;
namespace Yamux
{
public class Yamux
{
public static List<Button> ListButtonPlay = new List<Button>();
public static void OpenLinkToWebBrowser(string url)
{
try
{
Process.Start(url);
}
catch
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") {CreateNoWindow = true});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}
public static Dictionary<string, List<string>> GetPlaylists(JToken root)
{
Dictionary<string, List<string>> playlist = new Dictionary<string, List<string>>();
List<string> type = new List<string>();
List<string> playlistUid = new List<string>();
List<string> playlistKind = new List<string>();
List<string> playlistName = new List<string>();
List<string> playlistCoverUri = new List<string>();
type.Add("playlist");
foreach (JToken i in root["playlists"]["results"])
{
playlistUid.Add(i["uid"].ToString());
playlistKind.Add(i["kind"].ToString());
playlistName.Add(i["title"].ToString());
try
{
playlistCoverUri.Add(i["cover"]["uri"].ToString());
}
catch (NullReferenceException)
{
playlistCoverUri.Add("None");
}
}
playlist.Add("type", type);
playlist.Add("uid", playlistUid);
playlist.Add("kind", playlistKind);
playlist.Add("name", playlistName);
playlist.Add("coverUri", playlistCoverUri);
return playlist;
}
public static Dictionary<string, List<string>> GetPodcasts(JToken root)
{
Dictionary<string, List<string>> podcast = new Dictionary<string, List<string>>();
List<string> type = new List<string>();
List<string> podcastId = new List<string>();
List<string> podcastName = new List<string>();
List<string> podcastCoverUri = new List<string>();
type.Add("podcast");
foreach (JToken i in root["podcast_episodes"]["results"])
{
podcastId.Add(i["id"].ToString());
podcastName.Add(i["title"].ToString());
try
{
podcastCoverUri.Add(i["coverUri"].ToString());
}
catch (NullReferenceException)
{
podcastCoverUri.Add("None");
}
}
podcast.Add("type", type);
podcast.Add("id", podcastId);
podcast.Add("name", podcastName);
podcast.Add("coverUri", podcastCoverUri);
return podcast;
}
public static Dictionary<string, List<string>> GetTracks(JToken root)
{
Dictionary<string, List<string>> tracks = new Dictionary<string, List<string>>();
List<string> type = new List<string>();
List<string> trackId = new List<string>();
List<string> trackName = new List<string>();
List<string> trackCoverUri = new List<string>();
type.Add("track");
foreach (JToken i in root["tracks"]["results"])
{
trackId.Add(i["id"].ToString());
trackName.Add(i["title"].ToString());
try
{
trackCoverUri.Add(i["coverUri"].ToString());
}
catch (NullReferenceException)
{
trackCoverUri.Add("None");
}
}
tracks.Add("type", type);
tracks.Add("id", trackId);
tracks.Add("name", trackName);
tracks.Add("coverUri", trackCoverUri);
return tracks;
}
public static Dictionary<string, List<string>> GetArtist(JToken root)
{
Dictionary<string, List<string>> artist = new Dictionary<string, List<string>>();
List<string> type = new List<string>();
List<string> artistId = new List<string>();
List<string> artistName = new List<string>();
List<string> artistCoverUri = new List<string>();
type.Add("artist");
foreach (JToken i in root["artists"]["results"])
{
artistId.Add(i["id"].ToString());
artistName.Add(i["name"].ToString());
try
{
artistCoverUri.Add(i["cover"]["uri"].ToString());
}
catch (NullReferenceException)
{
artistCoverUri.Add("None");
}
}
artist.Add("type", type);
artist.Add("id", artistId);
artist.Add("name", artistName);
artist.Add("coverUri", artistCoverUri);
return artist;
}
public static Dictionary<string, List<string>> GetAlbums(JToken root)
{
Dictionary<string, List<string>> albums = new Dictionary<string, List<string>>();
List<string> type = new List<string>();
List<string> albumsId = new List<string>();
List<string> albumsName = new List<string>();
List<string> albumsCoverUri = new List<string>();
type.Add("album");
foreach (JToken i in root["albums"]["results"])
{
albumsId.Add(i["id"].ToString());
albumsName.Add(i["title"].ToString());
try
{
albumsCoverUri.Add(i["coverUri"].ToString());
}
catch (NullReferenceException)
{
albumsCoverUri.Add("None");
}
}
albums.Add("type", type);
albums.Add("id", albumsId);
albums.Add("name", albumsName);
albums.Add("coverUri", albumsCoverUri);
return albums;
}
public static Dictionary<string, string> GetBest(JToken root)
{
Dictionary<string, string> best = new Dictionary<string, string>();
best.Add("type", root["best"]["type"].ToString());
return best;
}
public static HBox CreateBoxResultSearch(List<string> name, List<string> coverUri, List<string> id, string typeResult)
{
HBox newBox = new HBox();
newBox.Valign = Align.Start;
int b = -1;
foreach (string i in name)
{
b++;
VBox coverImage = new VBox();
Button buttonPlay = new Button();
coverImage.Spacing = 4;
coverImage.MarginTop = 20;
coverImage.MarginBottom = 15;
coverImage.Valign = Align.Start;
coverImage.Halign = Align.Start;
newBox.Add(coverImage);
newBox.Spacing = 8;
Label nameBestLabel = new Label(i);
FontDescription tpfNameBest = new FontDescription();
tpfNameBest.Size = 11264;
nameBestLabel.ModifyFont(tpfNameBest);
nameBestLabel.MaxWidthChars = 20;
nameBestLabel.Ellipsize = EllipsizeMode.End;
nameBestLabel.Halign = Align.Center;
nameBestLabel.Valign = Align.Start;
string uri;
Pixbuf imagePixbuf;
if (coverUri[b] != "None")
{
uri = "https://" + coverUri[b].Replace("%%", "50x50");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://" + coverUri[b].Replace("%%", "100x100"));
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
imagePixbuf = new Pixbuf(stream);
}
response.Close();
}
else
{
uri = "null";
imagePixbuf = new Pixbuf(Path.GetFullPath("Svg/icons8_rock_music_100_negate.png"));
}
if (typeResult != "playlist")
{
buttonPlay.Name = "{'type': \"" + typeResult + "\",'id': \"" + id[b] + "\", 'uri': \""+ uri + "\" }";
}
else
{
buttonPlay.Name = "{ 'type': \"" + typeResult + "\", 'uid': \"" + Search.uidPlaylist[b] + "\", 'kind': \"" + Search.kindPlaylist[b] + "\", 'uri': \"" + uri + "\"}";
}
Console.WriteLine(buttonPlay.Name);
Image image = new Image(imagePixbuf);
image.Halign = Align.Fill;
buttonPlay.Image = image;
buttonPlay.Relief = ReliefStyle.None;
ListButtonPlay.Add(buttonPlay);
coverImage.Add(buttonPlay);
coverImage.Add(nameBestLabel);
newBox.Add(coverImage);
}
return newBox;
}
}
}