@muhammedaksam/easiarr 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api/arr-api.ts +27 -2
- package/src/api/custom-format-api.ts +212 -0
- package/src/api/prowlarr-api.ts +301 -0
- package/src/api/quality-profile-api.ts +205 -0
- package/src/apps/registry.ts +2 -4
- package/src/data/trash-profiles.ts +252 -0
- package/src/ui/screens/AppConfigurator.ts +34 -2
- package/src/ui/screens/MainMenu.ts +33 -1
- package/src/ui/screens/ProwlarrSetup.ts +378 -0
- package/src/ui/screens/TRaSHProfileSetup.ts +371 -0
- package/src/utils/debug.ts +27 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prowlarr Setup Screen
|
|
3
|
+
* Configures Prowlarr integration with *arr apps, FlareSolverr, and proxies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { BoxRenderable, CliRenderer, TextRenderable, KeyEvent } from "@opentui/core"
|
|
7
|
+
import { createPageLayout } from "../components/PageLayout"
|
|
8
|
+
import { EasiarrConfig } from "../../config/schema"
|
|
9
|
+
import { getApp } from "../../apps/registry"
|
|
10
|
+
import { ProwlarrClient, ArrAppType } from "../../api/prowlarr-api"
|
|
11
|
+
import { readEnvSync } from "../../utils/env"
|
|
12
|
+
import { debugLog } from "../../utils/debug"
|
|
13
|
+
|
|
14
|
+
interface SetupResult {
|
|
15
|
+
name: string
|
|
16
|
+
status: "pending" | "configuring" | "success" | "error" | "skipped"
|
|
17
|
+
message?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type Step = "menu" | "sync-apps" | "flaresolverr" | "sync-profiles" | "done"
|
|
21
|
+
|
|
22
|
+
const ARR_APP_TYPES: Record<string, ArrAppType> = {
|
|
23
|
+
radarr: "Radarr",
|
|
24
|
+
sonarr: "Sonarr",
|
|
25
|
+
lidarr: "Lidarr",
|
|
26
|
+
readarr: "Readarr",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class ProwlarrSetup extends BoxRenderable {
|
|
30
|
+
private config: EasiarrConfig
|
|
31
|
+
private cliRenderer: CliRenderer
|
|
32
|
+
private onBack: () => void
|
|
33
|
+
private keyHandler!: (key: KeyEvent) => void
|
|
34
|
+
private results: SetupResult[] = []
|
|
35
|
+
private currentStep: Step = "menu"
|
|
36
|
+
private contentBox!: BoxRenderable
|
|
37
|
+
private pageContainer!: BoxRenderable
|
|
38
|
+
private menuIndex = 0
|
|
39
|
+
private prowlarrClient: ProwlarrClient | null = null
|
|
40
|
+
|
|
41
|
+
constructor(cliRenderer: CliRenderer, config: EasiarrConfig, onBack: () => void) {
|
|
42
|
+
const { container: pageContainer, content: contentBox } = createPageLayout(cliRenderer, {
|
|
43
|
+
title: "Prowlarr Setup",
|
|
44
|
+
stepInfo: "Configure indexer sync and proxies",
|
|
45
|
+
footerHint: "↑↓ Navigate Enter Select Esc Back",
|
|
46
|
+
})
|
|
47
|
+
super(cliRenderer, { width: "100%", height: "100%" })
|
|
48
|
+
this.add(pageContainer)
|
|
49
|
+
|
|
50
|
+
this.config = config
|
|
51
|
+
this.cliRenderer = cliRenderer
|
|
52
|
+
this.onBack = onBack
|
|
53
|
+
this.contentBox = contentBox
|
|
54
|
+
this.pageContainer = pageContainer
|
|
55
|
+
|
|
56
|
+
this.initProwlarrClient()
|
|
57
|
+
this.initKeyHandler()
|
|
58
|
+
this.refreshContent()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private initProwlarrClient(): void {
|
|
62
|
+
const env = readEnvSync()
|
|
63
|
+
const apiKey = env["API_KEY_PROWLARR"]
|
|
64
|
+
if (apiKey) {
|
|
65
|
+
const prowlarrConfig = this.config.apps.find((a) => a.id === "prowlarr")
|
|
66
|
+
const port = prowlarrConfig?.port || 9696
|
|
67
|
+
this.prowlarrClient = new ProwlarrClient("localhost", port, apiKey)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private initKeyHandler(): void {
|
|
72
|
+
this.keyHandler = (key: KeyEvent) => {
|
|
73
|
+
debugLog("Prowlarr", `Key: ${key.name}, step=${this.currentStep}`)
|
|
74
|
+
|
|
75
|
+
if (key.name === "escape" || (key.name === "c" && key.ctrl)) {
|
|
76
|
+
if (this.currentStep === "menu") {
|
|
77
|
+
this.cleanup()
|
|
78
|
+
} else {
|
|
79
|
+
this.currentStep = "menu"
|
|
80
|
+
this.refreshContent()
|
|
81
|
+
}
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.currentStep === "menu") {
|
|
86
|
+
this.handleMenuKeys(key)
|
|
87
|
+
} else if (this.currentStep === "done") {
|
|
88
|
+
if (key.name === "return" || key.name === "escape") {
|
|
89
|
+
this.currentStep = "menu"
|
|
90
|
+
this.refreshContent()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.cliRenderer.keyInput.on("keypress", this.keyHandler)
|
|
95
|
+
debugLog("Prowlarr", "Key handler registered")
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private handleMenuKeys(key: KeyEvent): void {
|
|
99
|
+
const menuItems = this.getMenuItems()
|
|
100
|
+
|
|
101
|
+
if (key.name === "up" && this.menuIndex > 0) {
|
|
102
|
+
this.menuIndex--
|
|
103
|
+
this.refreshContent()
|
|
104
|
+
} else if (key.name === "down" && this.menuIndex < menuItems.length - 1) {
|
|
105
|
+
this.menuIndex++
|
|
106
|
+
this.refreshContent()
|
|
107
|
+
} else if (key.name === "return") {
|
|
108
|
+
this.executeMenuItem(this.menuIndex)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private getMenuItems(): { name: string; description: string; action: () => void }[] {
|
|
113
|
+
return [
|
|
114
|
+
{
|
|
115
|
+
name: "🔗 Sync *arr Apps",
|
|
116
|
+
description: "Connect Radarr/Sonarr/etc to Prowlarr",
|
|
117
|
+
action: () => this.syncArrApps(),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "🛡️ Setup FlareSolverr",
|
|
121
|
+
description: "Add Cloudflare bypass proxy",
|
|
122
|
+
action: () => this.setupFlareSolverr(),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "📊 Create Sync Profiles",
|
|
126
|
+
description: "Limited API indexer profiles",
|
|
127
|
+
action: () => this.createSyncProfiles(),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "↩️ Back",
|
|
131
|
+
description: "Return to main menu",
|
|
132
|
+
action: () => this.cleanup(),
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private executeMenuItem(index: number): void {
|
|
138
|
+
const items = this.getMenuItems()
|
|
139
|
+
if (index >= 0 && index < items.length) {
|
|
140
|
+
items[index].action()
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async syncArrApps(): Promise<void> {
|
|
145
|
+
if (!this.prowlarrClient) {
|
|
146
|
+
this.results = [{ name: "Prowlarr", status: "error", message: "API key not found" }]
|
|
147
|
+
this.currentStep = "done"
|
|
148
|
+
this.refreshContent()
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.currentStep = "sync-apps"
|
|
153
|
+
this.results = []
|
|
154
|
+
|
|
155
|
+
const arrApps = this.config.apps.filter((a) => a.enabled && Object.keys(ARR_APP_TYPES).includes(a.id))
|
|
156
|
+
const env = readEnvSync()
|
|
157
|
+
const prowlarrConfig = this.config.apps.find((a) => a.id === "prowlarr")
|
|
158
|
+
const prowlarrPort = prowlarrConfig?.port || 9696
|
|
159
|
+
|
|
160
|
+
for (const app of arrApps) {
|
|
161
|
+
const appType = ARR_APP_TYPES[app.id]
|
|
162
|
+
if (!appType) continue
|
|
163
|
+
|
|
164
|
+
this.results.push({ name: app.id, status: "configuring" })
|
|
165
|
+
this.refreshContent()
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const apiKey = env[`API_KEY_${app.id.toUpperCase()}`]
|
|
169
|
+
if (!apiKey) {
|
|
170
|
+
const result = this.results.find((r) => r.name === app.id)
|
|
171
|
+
if (result) {
|
|
172
|
+
result.status = "skipped"
|
|
173
|
+
result.message = "No API key"
|
|
174
|
+
}
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const appDef = getApp(app.id)
|
|
179
|
+
const port = app.port || appDef?.defaultPort || 7878
|
|
180
|
+
|
|
181
|
+
// In Docker, use container names for inter-container communication
|
|
182
|
+
await this.prowlarrClient.addArrApp(appType, app.id, port, apiKey, "prowlarr", prowlarrPort)
|
|
183
|
+
|
|
184
|
+
const result = this.results.find((r) => r.name === app.id)
|
|
185
|
+
if (result) {
|
|
186
|
+
result.status = "success"
|
|
187
|
+
}
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const result = this.results.find((r) => r.name === app.id)
|
|
190
|
+
if (result) {
|
|
191
|
+
result.status = "error"
|
|
192
|
+
result.message = error instanceof Error ? error.message : "Unknown error"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this.refreshContent()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Trigger sync
|
|
199
|
+
try {
|
|
200
|
+
await this.prowlarrClient.syncApplications()
|
|
201
|
+
} catch {
|
|
202
|
+
// Sync might fail if no apps, that's ok
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
this.currentStep = "done"
|
|
206
|
+
this.refreshContent()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private async setupFlareSolverr(): Promise<void> {
|
|
210
|
+
if (!this.prowlarrClient) {
|
|
211
|
+
this.results = [{ name: "Prowlarr", status: "error", message: "API key not found" }]
|
|
212
|
+
this.currentStep = "done"
|
|
213
|
+
this.refreshContent()
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this.currentStep = "flaresolverr"
|
|
218
|
+
this.results = [{ name: "FlareSolverr", status: "configuring" }]
|
|
219
|
+
this.refreshContent()
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
// Check if FlareSolverr is enabled
|
|
223
|
+
const fsConfig = this.config.apps.find((a) => a.id === "flaresolverr")
|
|
224
|
+
if (!fsConfig?.enabled) {
|
|
225
|
+
this.results[0].status = "skipped"
|
|
226
|
+
this.results[0].message = "FlareSolverr not enabled in config"
|
|
227
|
+
} else {
|
|
228
|
+
const fsPort = fsConfig.port || 8191
|
|
229
|
+
// In Docker, use container name for FlareSolverr
|
|
230
|
+
await this.prowlarrClient.configureFlareSolverr(`http://flaresolverr:${fsPort}`)
|
|
231
|
+
this.results[0].status = "success"
|
|
232
|
+
this.results[0].message = "Proxy added with 'flaresolverr' tag"
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
this.results[0].status = "error"
|
|
236
|
+
this.results[0].message = error instanceof Error ? error.message : "Unknown error"
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
this.currentStep = "done"
|
|
240
|
+
this.refreshContent()
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private async createSyncProfiles(): Promise<void> {
|
|
244
|
+
if (!this.prowlarrClient) {
|
|
245
|
+
this.results = [{ name: "Prowlarr", status: "error", message: "API key not found" }]
|
|
246
|
+
this.currentStep = "done"
|
|
247
|
+
this.refreshContent()
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
this.currentStep = "sync-profiles"
|
|
252
|
+
this.results = [
|
|
253
|
+
{ name: "Automatic Search", status: "configuring" },
|
|
254
|
+
{ name: "Interactive Search", status: "configuring" },
|
|
255
|
+
]
|
|
256
|
+
this.refreshContent()
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
await this.prowlarrClient.createLimitedAPISyncProfiles()
|
|
260
|
+
this.results[0].status = "success"
|
|
261
|
+
this.results[0].message = "RSS disabled, auto+interactive enabled"
|
|
262
|
+
this.results[1].status = "success"
|
|
263
|
+
this.results[1].message = "RSS+auto disabled, interactive only"
|
|
264
|
+
} catch (error) {
|
|
265
|
+
this.results.forEach((r) => {
|
|
266
|
+
r.status = "error"
|
|
267
|
+
r.message = error instanceof Error ? error.message : "Unknown error"
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.currentStep = "done"
|
|
272
|
+
this.refreshContent()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private refreshContent(): void {
|
|
276
|
+
this.contentBox.getChildren().forEach((child) => child.destroy())
|
|
277
|
+
|
|
278
|
+
if (this.currentStep === "menu") {
|
|
279
|
+
this.renderMenu()
|
|
280
|
+
} else {
|
|
281
|
+
this.renderResults()
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private renderMenu(): void {
|
|
286
|
+
if (!this.prowlarrClient) {
|
|
287
|
+
this.contentBox.add(
|
|
288
|
+
new TextRenderable(this.cliRenderer, {
|
|
289
|
+
content: "⚠️ Prowlarr API key not found!\nRun 'Extract API Keys' first.\n\n",
|
|
290
|
+
fg: "#ff5555",
|
|
291
|
+
})
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
this.contentBox.add(
|
|
296
|
+
new TextRenderable(this.cliRenderer, {
|
|
297
|
+
content: "Select an action:\n\n",
|
|
298
|
+
fg: "#aaaaaa",
|
|
299
|
+
})
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
this.getMenuItems().forEach((item, idx) => {
|
|
303
|
+
const pointer = idx === this.menuIndex ? "→ " : " "
|
|
304
|
+
const fg = idx === this.menuIndex ? "#50fa7b" : "#8be9fd"
|
|
305
|
+
|
|
306
|
+
this.contentBox.add(
|
|
307
|
+
new TextRenderable(this.cliRenderer, {
|
|
308
|
+
content: `${pointer}${item.name}\n`,
|
|
309
|
+
fg,
|
|
310
|
+
})
|
|
311
|
+
)
|
|
312
|
+
this.contentBox.add(
|
|
313
|
+
new TextRenderable(this.cliRenderer, {
|
|
314
|
+
content: ` ${item.description}\n\n`,
|
|
315
|
+
fg: "#6272a4",
|
|
316
|
+
})
|
|
317
|
+
)
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private renderResults(): void {
|
|
322
|
+
const headerText = this.currentStep === "done" ? "Results:\n\n" : "Configuring...\n\n"
|
|
323
|
+
this.contentBox.add(
|
|
324
|
+
new TextRenderable(this.cliRenderer, {
|
|
325
|
+
content: headerText,
|
|
326
|
+
fg: this.currentStep === "done" ? "#50fa7b" : "#f1fa8c",
|
|
327
|
+
})
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
for (const result of this.results) {
|
|
331
|
+
let status = ""
|
|
332
|
+
let fg = "#aaaaaa"
|
|
333
|
+
switch (result.status) {
|
|
334
|
+
case "pending":
|
|
335
|
+
status = "⏳"
|
|
336
|
+
break
|
|
337
|
+
case "configuring":
|
|
338
|
+
status = "🔄"
|
|
339
|
+
fg = "#f1fa8c"
|
|
340
|
+
break
|
|
341
|
+
case "success":
|
|
342
|
+
status = "✓"
|
|
343
|
+
fg = "#50fa7b"
|
|
344
|
+
break
|
|
345
|
+
case "error":
|
|
346
|
+
status = "✗"
|
|
347
|
+
fg = "#ff5555"
|
|
348
|
+
break
|
|
349
|
+
case "skipped":
|
|
350
|
+
status = "⊘"
|
|
351
|
+
fg = "#6272a4"
|
|
352
|
+
break
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let content = `${status} ${result.name}`
|
|
356
|
+
if (result.message) {
|
|
357
|
+
content += ` - ${result.message}`
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
this.contentBox.add(new TextRenderable(this.cliRenderer, { content: content + "\n", fg }))
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (this.currentStep === "done") {
|
|
364
|
+
this.contentBox.add(
|
|
365
|
+
new TextRenderable(this.cliRenderer, {
|
|
366
|
+
content: "\nPress Enter or Esc to continue...",
|
|
367
|
+
fg: "#6272a4",
|
|
368
|
+
})
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private cleanup(): void {
|
|
374
|
+
this.cliRenderer.keyInput.off("keypress", this.keyHandler)
|
|
375
|
+
this.destroy()
|
|
376
|
+
this.onBack()
|
|
377
|
+
}
|
|
378
|
+
}
|