Commit 2237bd6
Add live-channel engine primitives + franchise-match preview endpoint (slice 2)
Builds the resolution/update layer the live-channel scheduler will sit on top of,
plus the author-time preview endpoint. No scheduler yet (slice 3) and no UI yet
(slice 4) — this is the engine + one endpoint, all behind no behavior change to
existing flows.
channel_engine.py additions:
- match_titles(value, movie_map, show_map, order, exclude): the franchise matcher
for {"match": "title_contains"} content refs. Matches on WORD BOUNDARIES, not
raw substring, so "It" matches "It Follows" but never "Little Women". order=
"release_date" sorts movies by the Tunarr program releaseDate (epoch ms; recon
confirmed Tunarr programs carry releaseDate/year natively, so no plex CSV
fallback is needed). exclude is a case-insensitive title drop-list — the
per-recipe false-positive escape hatch. Returns (resolved_items, preview) where
preview is [{title, year}] for the confirm UI.
- resolve_content extended to handle {"match": ...} refs alongside the existing
plain-title and {"collection": ...} entries. Collection/plain behavior is byte
-identical to slice 1 (verified: create.py --probe still "Done: 80 created").
- find_channel_by_number, read_channel_programming, update_channel_in_place: the
in-place update primitives. read_channel_programming returns the set of program
IDs currently scheduled (the `programs` dict keys from GET .../programming,
which recon confirmed is the same id-space as build_library_index) — the
"current" side of the scheduler's change-detection diff. update_channel_in_place
looks the channel up by number and POSTs new programming WITHOUT delete/recreate,
preserving the Tunarr id and the Plex DVR mapping.
backend/routers/recipes_router.py (new) + main.py:
- POST /api/recipes/preview — runs match_titles against the live library and
returns the matched titles (release-ordered, with years) so the user can confirm
a rule before saving it. This is the FIRST in-process import of channel_engine
by the backend (the pipeline router shells out to scripts instead), so it also
establishes the sys.path wiring (add PROGRAMMARR_SCRIPTS) the scheduler reuses.
Verified locally in Docker against live Plex/Tunarr:
- POST /api/recipes/preview {"value":"Bad Boys","order":"release_date"} -> the 4
films in release order with years; adding exclude:["Bad Boys II"] -> 3 films.
- In-container engine check: find_channel_by_number(10)=Cheers Marathon,
read_channel_programming -> 273 ids (matches the show's episode count).
- Adversarial match test: "It" -> only real word matches (As Good as It Gets,
It's Always Sunny, ...), zero substring garbage.
- In-process channel_engine import works inside the image (the /app vs
/app/backend path-layout risk) via the PROGRAMMARR_SCRIPTS sys.path insert.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent fac90ef commit 2237bd6
3 files changed
Lines changed: 196 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
135 | 136 | | |
136 | 137 | | |
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 | + | |
138 | 203 | | |
139 | 204 | | |
140 | 205 | | |
| |||
194 | 259 | | |
195 | 260 | | |
196 | 261 | | |
197 | | - | |
| 262 | + | |
198 | 263 | | |
| 264 | + | |
199 | 265 | | |
200 | 266 | | |
201 | 267 | | |
| |||
207 | 273 | | |
208 | 274 | | |
209 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
210 | 290 | | |
211 | 291 | | |
212 | 292 | | |
| |||
218 | 298 | | |
219 | 299 | | |
220 | 300 | | |
| 301 | + | |
221 | 302 | | |
222 | 303 | | |
223 | 304 | | |
| |||
277 | 358 | | |
278 | 359 | | |
279 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
0 commit comments