forked from darkalfx/requestrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsFileUpgrader.cs
244 lines (195 loc) · 14.1 KB
/
SettingsFileUpgrader.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
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Requestrr.WebApi.RequestrrBot.DownloadClients.Overseerr;
using Requestrr.WebApi.RequestrrBot.DownloadClients.Radarr;
using Requestrr.WebApi.RequestrrBot.DownloadClients.Sonarr;
namespace Requestrr.WebApi
{
public static class SettingsFileUpgrader
{
public static void Upgrade(string settingsFilePath)
{
dynamic settingsJson = JObject.Parse(File.ReadAllText(settingsFilePath));
if (settingsJson.Version.ToString().Equals("1.0.0", StringComparison.InvariantCultureIgnoreCase))
{
var botClientJson = settingsJson["BotClient"] as JObject;
var monitoredChannels = !string.IsNullOrWhiteSpace(botClientJson.GetValue("MonitoredChannels").ToString())
? botClientJson.GetValue("MonitoredChannels").ToString().Split(" ").Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim())
: Array.Empty<string>();
((JObject)settingsJson["ChatClients"]["Discord"]).Add("MonitoredChannels", JToken.FromObject(monitoredChannels));
((JObject)settingsJson["BotClient"]).Remove("MonitoredChannels");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("TvShowRoles", JToken.FromObject(Array.Empty<string>()));
((JObject)settingsJson["ChatClients"]["Discord"]).Add("MovieRoles", JToken.FromObject(Array.Empty<string>()));
settingsJson.ChatClients.Discord.EnableDirectMessageSupport = false;
((JObject)settingsJson["DownloadClients"]["Ombi"]).Add("BaseUrl", string.Empty);
((JObject)settingsJson["DownloadClients"]["Radarr"]).Add("BaseUrl", string.Empty);
((JObject)settingsJson["DownloadClients"]["Radarr"]).Add("SearchNewRequests", true);
((JObject)settingsJson["DownloadClients"]["Radarr"]).Add("MonitorNewRequests", true);
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Add("BaseUrl", string.Empty);
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Add("SearchNewRequests", true);
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Add("MonitorNewRequests", true);
settingsJson.Version = "1.0.1";
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.0.1", StringComparison.InvariantCultureIgnoreCase)
|| settingsJson.Version.ToString().Equals("1.0.2", StringComparison.InvariantCultureIgnoreCase)
|| settingsJson.Version.ToString().Equals("1.0.3", StringComparison.InvariantCultureIgnoreCase)
|| settingsJson.Version.ToString().Equals("1.0.4", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.0.5";
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.0.5", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.0.6";
((JObject)settingsJson).Add("Port", 5060);
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.0.6", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.0.9";
((JObject)settingsJson["ChatClients"]["Discord"]).Add("AutomaticallyNotifyRequesters", true);
((JObject)settingsJson["ChatClients"]["Discord"]).Add("NotificationMode", "PrivateMessages");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("NotificationChannels", JToken.FromObject(Array.Empty<int>()));
((JObject)settingsJson["ChatClients"]["Discord"]).Add("AutomaticallyPurgeCommandMessages", false);
((JObject)settingsJson["ChatClients"]["Discord"]).Add("DisplayHelpCommandInDMs", true);
((JObject)settingsJson["ChatClients"]["Discord"]).Add("EnableRequestsThroughDirectMessages", (bool)((JObject)settingsJson["ChatClients"]["Discord"]).GetValue("EnableDirectMessageSupport"));
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("EnableDirectMessageSupport");
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.0.9", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.10.0";
((JObject)settingsJson["TvShows"]).Add("Restrictions", "None");
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.10.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.11.0";
((JObject)settingsJson).Add("BaseUrl", string.Empty);
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.11.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.12.0";
((JObject)settingsJson["DownloadClients"]).Add("Overseerr", JToken.FromObject(new OverseerrSettings()));
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.12.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.13.0";
((JObject)settingsJson["ChatClients"]).Add("Language", "english");
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.13.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.14.0";
if (((JObject)settingsJson["Movies"]).TryGetValue("Command", StringComparison.InvariantCultureIgnoreCase, out _))
{
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("DisplayHelpCommandInDMs");
((JObject)settingsJson["BotClient"]).Remove("CommandPrefix");
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("TvShowRoles");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("TvShowRoles", JToken.FromObject(Array.Empty<int>()));
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("MovieRoles");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("MovieRoles", JToken.FromObject(Array.Empty<int>()));
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("NotificationChannels");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("NotificationChannels", JToken.FromObject(Array.Empty<int>()));
((JObject)settingsJson["ChatClients"]["Discord"]).Remove("MonitoredChannels");
((JObject)settingsJson["ChatClients"]["Discord"]).Add("MonitoredChannels", JToken.FromObject(Array.Empty<int>()));
((JObject)settingsJson["Movies"]).Remove("Command");
((JObject)settingsJson["TvShows"]).Remove("Command");
}
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.14.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "1.15.0";
((JObject)settingsJson).Add("DisableAuthentication", false);
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("1.15.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "2.0.0";
var radarrCategories = new[]
{
new RadarrCategory
{
Id = 0,
Name = "movie",
ProfileId = (int)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("MovieProfileId"),
RootFolder = (string)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("MovieRootFolder"),
MinimumAvailability = (string)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("MovieMinimumAvailability"),
Tags = ((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("MovieTags").ToObject<int[]>()
},
new RadarrCategory
{
Id = 1,
Name = "movie-anime",
ProfileId = (int)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("AnimeProfileId"),
RootFolder = (string)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("AnimeRootFolder"),
MinimumAvailability = (string)((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("AnimeMinimumAvailability"),
Tags = ((JObject)settingsJson["DownloadClients"]["Radarr"]).GetValue("AnimeTags").ToObject<int[]>()
},
};
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("MovieProfileId");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("MovieRootFolder");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("MovieMinimumAvailability");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("MovieTags");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("AnimeProfileId");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("AnimeRootFolder");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("AnimeMinimumAvailability");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Remove("AnimeTags");
((JObject)settingsJson["DownloadClients"]["Radarr"]).Add("Categories", JToken.FromObject(radarrCategories));
var sonarrCategories = new[]
{
new SonarrCategory
{
Id = 0,
Name = "tv",
ProfileId = (int)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("TvProfileId"),
RootFolder = (string)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("TvRootFolder"),
Tags = ((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("TvTags").ToObject<int[]>(),
LanguageId = (int)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("TvLanguageId"),
UseSeasonFolders = (bool)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("TvUseSeasonFolders"),
SeriesType = "standard",
},
new SonarrCategory
{
Id = 1,
Name = "tv-anime",
ProfileId = (int)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("AnimeProfileId"),
RootFolder = (string)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("AnimeRootFolder"),
Tags = ((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("AnimeTags").ToObject<int[]>(),
LanguageId = (int)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("AnimeLanguageId"),
UseSeasonFolders = (bool)((JObject)settingsJson["DownloadClients"]["Sonarr"]).GetValue("AnimeUseSeasonFolders"),
SeriesType = "anime",
},
};
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("TvProfileId");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("TvRootFolder");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("TvTags");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("TvLanguageId");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("TvUseSeasonFolders");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("AnimeProfileId");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("AnimeRootFolder");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("AnimeTags");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("AnimeLanguageId");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Remove("AnimeUseSeasonFolders");
((JObject)settingsJson["DownloadClients"]["Sonarr"]).Add("Categories", JToken.FromObject(sonarrCategories));
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
if (settingsJson.Version.ToString().Equals("2.0.0", StringComparison.InvariantCultureIgnoreCase))
{
settingsJson.Version = "2.1.0";
var defaultApiUserID = (string)((JObject)settingsJson["DownloadClients"]["Overseerr"]).GetValue("DefaultApiUserID");
((JObject)settingsJson["DownloadClients"]["Overseerr"]).Remove("DefaultApiUserID");
((JObject)settingsJson["DownloadClients"]["Overseerr"]).Add("Movies", JToken.FromObject(new OverseerrMovieSettings { DefaultApiUserId = defaultApiUserID }));
((JObject)settingsJson["DownloadClients"]["Overseerr"]).Add("TvShows", JToken.FromObject(new OverseerrTvShowSettings { DefaultApiUserId = defaultApiUserID }));
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(settingsJson));
}
}
}
}