Skip to content

Commit 77b8ed1

Browse files
committed
improve handling of hidden/merged fields
1 parent fbce279 commit 77b8ed1

File tree

16 files changed

+158
-114
lines changed

16 files changed

+158
-114
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ Inspectarr uses [FilterQL](https://github.com/adamhl8/filterql) to filter/transf
9191
inspectarr radarr 'source == bluray && resolution ^= 1920'
9292

9393
# display media from specific release groups
94-
inspectarr sonarr 'releaseGroup == AMZN || releaseGroup == NF'
94+
inspectarr sonarr 'releaseGroup == NTb || releaseGroup == FLUX'
9595

9696
# display media where the title contains 'star wars' (case-insensitive)
9797
inspectarr sonarr 'title i*= "star wars"'
9898

99+
# display media where the title does *not* contain 'star wars'
100+
inspectarr sonarr '!title i*= "star wars"'
101+
99102
# display media released after 1990, then sort by title
100-
inspectarr radarr 'title *= "(1990)" | SORT title'
103+
inspectarr radarr 'year > 1990 | SORT title'
101104

102105
# display media where monitored is true and where the video codec is x265 (contains '265')
103106
inspectarr radarr 'monitored && videoCodec *= 265'
@@ -108,11 +111,13 @@ inspectarr radarr 'monitored && videoCodec *= 265'
108111
**General fields:**
109112

110113
- `title` (alias: `t`) - Media title
114+
- `year` (alias: `y`) - Release year
111115
- `monitored` (alias: `m`) - Whether the media is monitored
112116
- `releaseGroup` (alias: `rg`) - Release group name
113117
- `source` (alias: `src`) - Media source (bluray, webdl, etc.)
114118
- `videoCodec` (alias: `vc`) - Video codec (x264, x265, etc.)
115-
- `audioCodec` (alias: `ac`) - Audio codec with audio channel info
119+
- `audioCodec` (alias: `ac`) - Audio codec (AAC, EAC3, etc.)
120+
- `audioChannels` (alias: `ach`) - Audio channels (2, 5.1, etc.)
116121
- `resolution` (alias: `rs`) - Video resolution
117122
- `size` (alias: `sz`) - File size
118123

assets/demo.gif

-4.31 KB
Loading

bun.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo.tape

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Set Theme "Catppuccin Macchiato"
44
Set WindowBar Colorful
55
Set FontFamily "JetBrainsMono Nerd Font"
66
Set Width 1250
7-
Set Height 425
7+
Set Height 400
88
Set Padding 25
99

1010
Set Shell bash

src/arr-client/arr-client.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import ky from "ky"
22
import type { Result } from "ts-explicit-errors"
33
import { attempt, err, isErr } from "ts-explicit-errors"
4-
import type { Entries, JsonPrimitive } from "type-fest"
4+
import type { Entries } from "type-fest"
55

6-
import type { JsonifiableMediaData, JsonifiableMediaDataObject, MediaData } from "~/cli/types.ts"
6+
import type { JsonifiableMediaData, MediaData } from "~/cli/types.ts"
77

88
export abstract class ArrClient {
9+
public name: string
910
readonly #baseUrl: string
1011
readonly #apiKey: string
1112

12-
public constructor(baseUrl: string, apiKey: string) {
13+
public constructor(name: string, baseUrl: string, apiKey: string) {
14+
this.name = name
1315
this.#baseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl
1416
this.#apiKey = apiKey
1517
}
@@ -40,24 +42,20 @@ export abstract class ArrClient {
4042

4143
const unique = (arr: unknown[] | undefined) => [...new Set(arr)].join(",").trim()
4244

43-
const normalizedMediaData: JsonifiableMediaData = []
44-
45-
for (const entry of mediaData) {
46-
const mediaDataObject: JsonifiableMediaDataObject = {}
47-
for (const [key, value] of Object.entries(entry) as Entries<typeof entry>) {
48-
let normalizedValue: JsonPrimitive
49-
45+
const normalizedMediaData: JsonifiableMediaData = mediaData.map((dataObject) => {
46+
const dataObjectEntries = Object.entries(dataObject) as Entries<typeof dataObject>
47+
const normalizedDataObjectEntries = dataObjectEntries.map(([key, value]) => {
5048
if (Array.isArray(value)) {
5149
const uniqueString = unique(value)
52-
normalizedValue = uniqueString || null // empty arrays should be null
53-
} else if (typeof value === "string") normalizedValue = value.trim()
54-
else if (value === undefined) normalizedValue = null
55-
else normalizedValue = value
56-
57-
mediaDataObject[key] = normalizedValue
58-
}
59-
normalizedMediaData.push(mediaDataObject)
60-
}
50+
return [key, uniqueString || null] // empty arrays should be null
51+
}
52+
if (typeof value === "string") return [key, value.trim()]
53+
if (value === undefined) return [key, null]
54+
return [key, value]
55+
})
56+
57+
return Object.fromEntries(normalizedDataObjectEntries)
58+
})
6159

6260
return normalizedMediaData
6361
}

src/arr-client/radarr-client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import type { Result } from "ts-explicit-errors"
22
import { err, isErr } from "ts-explicit-errors"
33

44
import { ArrClient } from "~/arr-client/arr-client.ts"
5-
import { formatQualifiedValue, formatSize, getRawResolution } from "~/arr-client/utils.ts"
65
import type { RadarrMediaData } from "~/cli/radarr.ts"
76
import type { paths } from "~/generated/radarr-schema.ts"
7+
import { formatSize, getRawResolution } from "~/utils.ts"
88

99
type RadarrAllMedia = paths["/api/v3/movie"]["get"]["responses"]["200"]["content"]["application/json"][number]
1010

1111
export class RadarrClient extends ArrClient {
12+
public constructor(baseUrl: string, apiKey: string) {
13+
super("Radarr", baseUrl, apiKey)
14+
}
15+
1216
public getAllMedia(): Promise<Result<RadarrAllMedia[]>> {
1317
return this.makeRequest<RadarrAllMedia[]>("movie")
1418
}
@@ -25,12 +29,14 @@ export class RadarrClient extends ArrClient {
2529
const mediaDetails = movieFile?.mediaInfo
2630

2731
data.push({
28-
title: formatQualifiedValue(movie.title, movie.year),
32+
title: movie.title,
33+
year: movie.year,
2934
monitored: movie.monitored,
3035
releaseGroup: movieFile?.releaseGroup,
3136
source: movieFile?.quality?.quality?.source,
3237
videoCodec: mediaDetails?.videoCodec,
33-
audioCodec: formatQualifiedValue(mediaDetails?.audioCodec, mediaDetails?.audioChannels),
38+
audioCodec: mediaDetails?.audioCodec,
39+
audioChannels: mediaDetails?.audioChannels,
3440
resolution: mediaDetails?.resolution,
3541
rawResolution: getRawResolution(mediaDetails?.resolution),
3642
size: formatSize(movieFile?.size),

0 commit comments

Comments
 (0)