Implement Feature Request from Reddit.
https://old.reddit.com/r/Lidarr/comments/1099fe3/tool_release_see_which_singles_appear_on_albums/j5vixx4/?context=0
This commit is contained in:
parent
51201a6245
commit
614d61854b
|
@ -1,3 +1,4 @@
|
|||
LIDARR_URL="https://lidarr.domain.tld"
|
||||
LIDARR_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
UNMONITOR="false"
|
||||
OUTPUT_UNMONITORED="false"
|
||||
|
|
12
README.md
12
README.md
|
@ -18,14 +18,16 @@ docker run --rm \
|
|||
-e LIDARR_URL=http://localhost:8686 \
|
||||
-e LIDARR_API_KEY=your_api_key \
|
||||
-e UNMONITOR=false \
|
||||
-e OUTPUT_UNMONITORED=false \
|
||||
ghcr.io/chxseh/lidarr-true-singles:latest
|
||||
```
|
||||
|
||||
| Environment Variable | Description | Default |
|
||||
| -------------------- | -------------------------------------- | --------------------- |
|
||||
| LIDARR_URL | The URL to your Lidarr instance | http://localhost:8686 |
|
||||
| LIDARR_API_KEY | Your Lidarr API Key | |
|
||||
| UNMONITOR | Whether to unmonitor the tracks or not | false |
|
||||
| Environment Variable | Description | Default |
|
||||
| -------------------- | ----------------------------------------------------------------------------------------------- | --------------------- |
|
||||
| LIDARR_URL | The URL to your Lidarr instance | http://localhost:8686 |
|
||||
| LIDARR_API_KEY | Your Lidarr API Key | |
|
||||
| UNMONITOR | Whether to unmonitor the tracks or not | false |
|
||||
| OUTPUT_UNMONITORED | Print unmonitored singles that are downloaded. Note that this overrides the `UNMONITOR` option. | false |
|
||||
|
||||
## Development
|
||||
```bash
|
||||
|
|
58
src/app.js
58
src/app.js
|
@ -9,6 +9,7 @@ if (lidarrUrl.endsWith(`/`))
|
|||
|
||||
const apiKey = process.env.LIDARR_API_KEY;
|
||||
const unmonitor = process.env.UNMONITOR || `false`;
|
||||
const printUnmonitored = process.env.OUTPUT_UNMONITORED || `false`;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -33,7 +34,7 @@ for (const artistId of artistIdsObject)
|
|||
let albums = await fetch(`${ lidarrUrl }/api/v1/album?artistId=${ artistId }&includeAllArtistAlbums=true&apikey=${ apiKey }`);
|
||||
albums = await albums.json();
|
||||
let singles = albums.filter((album) => album.albumType === `Single`);
|
||||
singles = singles.filter((album) => album.monitored === true);
|
||||
singles = printUnmonitored === `true` ? singles.filter((album) => album.monitored === false) : singles.filter((album) => album.monitored === true);
|
||||
|
||||
let everythingElse = albums.filter((album) => album.albumType !== `Single`);
|
||||
everythingElse = everythingElse.filter((album) => album.monitored === true);
|
||||
|
@ -48,32 +49,45 @@ for (const artistId of artistIdsObject)
|
|||
singleIds.push(single.id);
|
||||
}
|
||||
|
||||
for (const album of everythingElse)
|
||||
if (printUnmonitored === `true`)
|
||||
{
|
||||
let trackList = await fetch(`${ lidarrUrl }/api/v1/track?artistId=${ artistId }&albumId=${ album.id }&apikey=${ apiKey }`);
|
||||
trackList = await trackList.json();
|
||||
|
||||
if (trackList.some((track) => singleNamesLower.includes(track.title.toLowerCase())))
|
||||
for (const singleId of singleIds)
|
||||
{
|
||||
const trackName = trackList.find((track) => singleNamesLower.includes(track.title.toLowerCase())).title;
|
||||
const singleId = singleIds[singleNamesLower.indexOf(trackName.toLowerCase())];
|
||||
const artistName = artists.find((artist) => artist.id === artistId).artistName;
|
||||
if (unmonitor === `true`)
|
||||
const single = singles.find((album) => album.id === singleId);
|
||||
if (single.statistics.trackFileCount > 0)
|
||||
console.log(`"${ singleNames[singleIds.indexOf(singleId)] }" by ${ artistName } is downloaded but unmonitored, consider deleting it. ${ lidarrUrl }/album/${ single.foreignAlbumId }`);
|
||||
}
|
||||
}
|
||||
else if (printUnmonitored === `false`)
|
||||
{
|
||||
for (const album of everythingElse)
|
||||
{
|
||||
let trackList = await fetch(`${ lidarrUrl }/api/v1/track?artistId=${ artistId }&albumId=${ album.id }&apikey=${ apiKey }`);
|
||||
trackList = await trackList.json();
|
||||
|
||||
if (trackList.some((track) => singleNamesLower.includes(track.title.toLowerCase())))
|
||||
{
|
||||
await fetch(`${ lidarrUrl }/api/v1/album/monitor?apikey=${ apiKey }`, {
|
||||
method: `PUT`,
|
||||
headers: {
|
||||
"Content-Type": `application/json`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
albumIds: [singleId],
|
||||
monitored: false
|
||||
})
|
||||
});
|
||||
console.log(`Unmonitored "${ singleNames[singleIds.indexOf(singleId)] }" by ${ artistName }`);
|
||||
const trackName = trackList.find((track) => singleNamesLower.includes(track.title.toLowerCase())).title;
|
||||
const singleId = singleIds[singleNamesLower.indexOf(trackName.toLowerCase())];
|
||||
const artistName = artists.find((artist) => artist.id === artistId).artistName;
|
||||
if (unmonitor === `true`)
|
||||
{
|
||||
await fetch(`${ lidarrUrl }/api/v1/album/monitor?apikey=${ apiKey }`, {
|
||||
method: `PUT`,
|
||||
headers: {
|
||||
"Content-Type": `application/json`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
albumIds: [singleId],
|
||||
monitored: false
|
||||
})
|
||||
});
|
||||
console.log(`Unmonitored "${ singleNames[singleIds.indexOf(singleId)] }" by ${ artistName }`);
|
||||
}
|
||||
else
|
||||
console.log(`"${ singleNames[singleIds.indexOf(singleId)] }" is also found on ${ album.title } by ${ artistName }`);
|
||||
}
|
||||
else
|
||||
console.log(`"${ singleNames[singleIds.indexOf(singleId)] }" is also found on ${ album.title } by ${ artistName }`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue