|
1 | 1 | import { LidarrClient } from '../../clients/lidarr.js'; |
| 2 | +import { promptConfirm, promptSelect } from '../prompt.js'; |
2 | 3 | import type { ResourceDef } from './service.js'; |
3 | 4 | import { buildServiceCommand } from './service.js'; |
4 | 5 |
|
@@ -26,6 +27,93 @@ const resources: ResourceDef[] = [ |
26 | 27 | columns: ['foreignArtistId', 'artistName', 'overview'], |
27 | 28 | run: (c: LidarrClient, a) => c.searchArtists(a.term), |
28 | 29 | }, |
| 30 | + { |
| 31 | + name: 'add', |
| 32 | + description: 'Search and add an artist', |
| 33 | + args: [{ name: 'term', description: 'Search term', required: true }], |
| 34 | + run: async (c: LidarrClient, a) => { |
| 35 | + const searchResult = await c.searchArtists(a.term); |
| 36 | + const results = searchResult?.data ?? searchResult; |
| 37 | + if (!Array.isArray(results) || results.length === 0) { |
| 38 | + throw new Error('No artists found.'); |
| 39 | + } |
| 40 | + const artistId = await promptSelect( |
| 41 | + 'Select an artist:', |
| 42 | + results.map((ar: any) => ({ |
| 43 | + label: ar.artistName, |
| 44 | + value: String(ar.foreignArtistId), |
| 45 | + })) |
| 46 | + ); |
| 47 | + const artist = results.find((ar: any) => String(ar.foreignArtistId) === artistId); |
| 48 | + if (!artist) { |
| 49 | + throw new Error('Selected artist was not found in the search results.'); |
| 50 | + } |
| 51 | + |
| 52 | + const profilesResult = await c.getQualityProfiles(); |
| 53 | + const profiles = profilesResult?.data ?? profilesResult; |
| 54 | + if (!Array.isArray(profiles) || profiles.length === 0) { |
| 55 | + throw new Error('No quality profiles found. Configure one in Lidarr first.'); |
| 56 | + } |
| 57 | + const profileId = await promptSelect( |
| 58 | + 'Select quality profile:', |
| 59 | + profiles.map((p: any) => ({ label: p.name, value: String(p.id) })) |
| 60 | + ); |
| 61 | + |
| 62 | + const foldersResult = await c.getRootFolders(); |
| 63 | + const folders = foldersResult?.data ?? foldersResult; |
| 64 | + if (!Array.isArray(folders) || folders.length === 0) { |
| 65 | + throw new Error('No root folders found. Configure one in Lidarr first.'); |
| 66 | + } |
| 67 | + const rootFolderPath = await promptSelect( |
| 68 | + 'Select root folder:', |
| 69 | + folders.map((f: any) => ({ label: f.path, value: f.path })) |
| 70 | + ); |
| 71 | + |
| 72 | + const confirmed = await promptConfirm(`Add "${artist.artistName}"?`, !!a.yes); |
| 73 | + if (!confirmed) throw new Error('Cancelled.'); |
| 74 | + |
| 75 | + return c.addArtist({ |
| 76 | + ...artist, |
| 77 | + qualityProfileId: Number(profileId), |
| 78 | + rootFolderPath, |
| 79 | + monitored: true, |
| 80 | + addOptions: { searchForMissingAlbums: true }, |
| 81 | + }); |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + name: 'edit', |
| 86 | + description: 'Edit an artist', |
| 87 | + args: [ |
| 88 | + { name: 'id', description: 'Artist ID', required: true, type: 'number' }, |
| 89 | + { name: 'monitored', description: 'Set monitored (true/false)' }, |
| 90 | + { name: 'quality-profile-id', description: 'Quality profile ID', type: 'number' }, |
| 91 | + { name: 'tags', description: 'Comma-separated tag IDs' }, |
| 92 | + ], |
| 93 | + run: async (c: LidarrClient, a) => { |
| 94 | + const result = await c.getArtist(a.id); |
| 95 | + const artist = result?.data ?? result; |
| 96 | + const updates: any = { ...artist }; |
| 97 | + if (a.monitored !== undefined) updates.monitored = a.monitored === 'true'; |
| 98 | + if (a['quality-profile-id'] !== undefined) |
| 99 | + updates.qualityProfileId = Number(a['quality-profile-id']); |
| 100 | + if (a.tags !== undefined) |
| 101 | + updates.tags = a.tags.split(',').map((t: string) => Number(t.trim())); |
| 102 | + return c.updateArtist(a.id, updates); |
| 103 | + }, |
| 104 | + }, |
| 105 | + { |
| 106 | + name: 'refresh', |
| 107 | + description: 'Refresh artist metadata', |
| 108 | + args: [{ name: 'id', description: 'Artist ID', required: true, type: 'number' }], |
| 109 | + run: (c: LidarrClient, a) => c.runCommand({ name: 'RefreshArtist', artistId: a.id } as any), |
| 110 | + }, |
| 111 | + { |
| 112 | + name: 'manual-search', |
| 113 | + description: 'Trigger a manual search for releases', |
| 114 | + args: [{ name: 'id', description: 'Artist ID', required: true, type: 'number' }], |
| 115 | + run: (c: LidarrClient, a) => c.runCommand({ name: 'ArtistSearch', artistId: a.id } as any), |
| 116 | + }, |
29 | 117 | { |
30 | 118 | name: 'delete', |
31 | 119 | description: 'Delete an artist', |
|
0 commit comments