-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
184 lines (182 loc) · 6.58 KB
/
Program.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
using System;
using VTMCLI.Model;
using System.Diagnostics;
using Newtonsoft.Json;
using VTMCLI.Text;
using Terminal.Gui;
namespace VTMCLI
{
class Program
{
private static string _version = "1.0alpha";
public static string Version { get { return _version; } }
public async static Task Main(string[] args)
{
if (args.Length != 0)
{
switch (args[0])
{
case "version":
GetVersion();
break;
case "about":
Console.WriteLine("Nothing");
break;
case "help":
GetHelp();
break;
case "search":
await SearchInit(args);
break;
default:
Console.WriteLine("Error prompt");
break;
}
}
else
{
GuiInit();
}
}
public static void GuiInit()
{
Application.Init();
MessageBox.Query(50, 7,
"Alert", "Do you like console apps?", "Yes", "No");
Application.Shutdown();
}
public static void GetVersion()
{
Console.WriteLine("VTM-CLI " + Version);
}
static HelpText Ht = new HelpText();
public static void GetHelp(int page = 0, int type = 0)
{
Console.WriteLine(Ht.MainHelpText);
}
public static async Task SearchInit(string[] args)
{
var arguments = new Dictionary<string, string>();
arguments.Add("keyword", args[1]);
for (int i = 2; i < args.Length; i++)
{
switch (args[i])
{
case "--type":
try
{
if (!arguments.ContainsKey("type"))
arguments.Add("type", args[i + 1]);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.ToString());
return;
}
i += 2;
break;
case "-t":
try
{
if (!arguments.ContainsKey("type"))
arguments.Add("type", args[i + 1]);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.ToString());
return;
}
i += 2;
break;
case "--limit":
try
{
if (!arguments.ContainsKey("limit"))
arguments.Add("limit", args[i + 1]);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.ToString());
return;
}
i += 2;
break;
case "-l":
try
{
if (!arguments.ContainsKey("limit"))
arguments.Add("limit", args[i + 1]);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.ToString());
return;
}
i += 2;
break;
default:
return;
}
}
SearchType type = SearchType.song;
if (arguments.ContainsKey("type"))
{
try
{
type = (SearchType)Enum.Parse(typeof(SearchType), arguments["type"]);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
Console.WriteLine("Check your option");
}
}
switch (type)
{
case SearchType.song:
var a = await Search<SearchResultModel.Song>(arguments);
foreach (var data in a.Data)
{
Console.WriteLine(data.name);
}
break;
case SearchType.artist:
var b = await Search<SearchResultModel.Artist>(arguments);
foreach (var data in b.Data)
{
Console.WriteLine(data.name.origin);
}
break;
case SearchType.playlist:
var c = await Search<SearchResultModel.Playlist>(arguments);
foreach (var data in c.Data)
{
Console.WriteLine(data.name);
}
break;
case SearchType.user:
var d = await Search<SearchResultModel.User>(arguments);
foreach (var data in d.Data)
{
Console.WriteLine(data.nickname);
}
break;
}
}
enum SearchType { song = 0, artist = 1, playlist = 2, user = 3 }
public async static Task<SearchResultModel.Root<T>> Search<T>(Dictionary<string, string> arguments)
{
string json = "";
try
{
json = await Api.ApiRequest(Url.searchUrl, RestSharp.Method.Get, arguments);
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Lack of arguments.\n Usage:vtmcli search <Keywords> [options]");
Debug.WriteLine("Details:" + e.Message);
}
return JsonConvert.DeserializeObject<SearchResultModel.Root<T>>(json, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
}
}