Extract TMDb lookup helpers into modules/tmdb_lookup.py (PR H of quickstart.py refactor)#1328
Merged
Merged
Conversation
Moves the six TMDb (The Movie Database) lookup utilities out of quickstart.py into a focused module. These are pure HTTP helpers with no Flask app coupling, no global state -- textbook candidates for extraction. ## What moved Six small functions (166 lines total in quickstart.py): | Function (in module) | Originally on develop | Lines | |---------------------------------------|-----------------------|------:| | get_active_tmdb_api_key | quickstart.py:3020 | 15 | | lookup_tmdb_by_imdb_id | quickstart.py:3037 | 57 | | lookup_tmdb_external_ids | quickstart.py:3096 | 18 | | lookup_tmdb_numeric_id | quickstart.py:3116 | 53 | | normalize_tmdb_library_media_type | quickstart.py:3171 | 7 | | build_tmdb_library_type_warning | quickstart.py:3180 | 16 | Names lose their leading underscore in the new module (the module is the namespace now), but quickstart.py re-imports each one under its old _leading_underscore alias so the existing call sites in lookup_template_string_value (the /lookup_template_string_value POST route) and any future tests keep working unchanged. ## Why this PR is cheap * No tests patch any of these helpers via qs_module._foo today -- verified by grep across tests/. So no test-patch boundary concerns. * Only one caller (lookup_template_string_value) inside quickstart.py. * All six functions are pure utilities with a tiny, well-defined external API (requests, modules.database, flask.session). * AST-verified verbatim extraction (modulo the leading-underscore rename and the added module docstrings). ## Re-export hygiene Two of the six functions were only ever called by the *other* TMDb helpers (lookup_tmdb_external_ids, normalize_tmdb_library_media_type): both are now only referenced internally by modules/tmdb_lookup.py itself, and dropped from the quickstart.py re-export list. If a future caller needs them, the import is one-line away. ## Tests * 801 tests pass (no regressions). * ruff check clean on both touched files. * AST verification: all six functions byte-for-byte identical to develop after reverse-applying the leading-underscore rename and stripping the new module docstrings. ## Size impact * quickstart.py: 7,397 -> 7,225 lines (-172, -2.3%) * modules/tmdb_lookup.py: 238 lines (new, under 600) ## Cumulative refactor progress Starting baseline (post #1320): 11,087 lines in quickstart.py. After PR A (#1321): 9,831 (-1,256) After PR C (#1322): 9,227 (-1,860) After PR D (#1323): 8,709 (-2,378) After PR E (#1324): 7,397 (-3,690) After PR F (#1325, pending merge): 6,976 (-4,111) -- not in this branch **After PR H (this, off develop): 7,225 (-3,862 from baseline)** PR F and PR H are independent -- they touch different parts of the file. PR H is opened off develop so it is reviewable standalone; once PR F lands, PR H will fast-forward merge cleanly with no conflicts.
kometa-tokens Bot
pushed a commit
that referenced
this pull request
Jun 25, 2026
… quickstart.py refactor) (#1328)
kometa-tokens Bot
pushed a commit
that referenced
this pull request
Jun 25, 2026
… H of quickstart.py refactor) (#1328)
chazlarson
added a commit
that referenced
this pull request
Jun 25, 2026
Resolves trivial import-block conflict between PR G and merged PRs F (#1325) and H (#1328): both PR G and PR H added a new 'from modules.X import (...) as _foo' block right after the modules.assets import. Kept both blocks, ordered alphabetically by module path. * No code-logic conflicts (PR F and PR H touched disjoint regions of quickstart.py from PR G). * 801 tests pass post-merge. * ruff check clean. * quickstart.py: 6,845 -> 6,252 lines (-593 from PR G base; the F+H reductions land cleanly on top of the PR G reductions).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR H from the quickstart.py refactor sprint -- the smallest and lowest-risk of the remaining work. Moves the six TMDb (The Movie Database) lookup utilities out of
quickstart.pyinto a focused module.These are pure HTTP helpers with no Flask app coupling and no global state -- textbook candidates for extraction.
Builds on the merged stack #1321 (PR A), #1322 (PR C), #1323 (PR D), #1324 (PR E), and is independent of #1325 (PR F, still open) -- they touch different parts of the file and will merge cleanly in either order.
What moved
Six small functions (166 lines on develop):
get_active_tmdb_api_keyquickstart.py:3020lookup_tmdb_by_imdb_idquickstart.py:3037lookup_tmdb_external_idsquickstart.py:3096lookup_tmdb_numeric_idquickstart.py:3116normalize_tmdb_library_media_typequickstart.py:3171build_tmdb_library_type_warningquickstart.py:3180Names lose their leading underscore in the new module (the module is the namespace now), but
quickstart.pyre-imports each one under its old_leading_underscorealias so the lone caller (lookup_template_string_value, the/lookup_template_string_valuePOST route) and any future tests keep working unchanged.Why this PR is cheap
qs_module._footoday -- verified by grep acrosstests/. So no test-patch boundary concerns like PR F had.lookup_template_string_value) insidequickstart.py.requests,modules.database,flask.session.Re-export hygiene
Two of the six functions were only ever called by the other TMDb helpers in this cluster:
lookup_tmdb_external_ids-- only called bylookup_tmdb_numeric_idnormalize_tmdb_library_media_type-- only called bybuild_tmdb_library_type_warningBoth are now internal to
modules/tmdb_lookup.pyand dropped from thequickstart.pyre-export list. If a future caller needs them, a one-line import is all it takes.Verbatim extraction discipline
AST-verified -- all 6 functions byte-for-byte identical to develop after reverse-applying the leading-underscore rename and stripping the new module docstrings:
Tests
ruff checkclean on both touched files.conftest.pyfixture needed -- the helpers have no test surface that would benefit from one.Size impact
quickstart.pymodules/tmdb_lookup.pyThe new module is larger than the moved code (166 → 238) because of the added module docstring and per-function docstrings explaining intent, semantics, and what each return shape means. Worth the bytes for files that didn't have any inline documentation before.
Cumulative refactor progress (relative to develop)
When PR F and PR H both land,
quickstart.pywill be at ~6,800 lines (−39% from baseline).What this unlocks
Just one PR left from the audit sprint:
blueprints/download_routes.py+modules/bundle_artifacts.py(~800 lines, medium risk). Once landed, removes the 6 lazy_qsimports added in PR E for bundle/overlay-image helpers and bringsquickstart.pyclose to the audit target (~5,000 lines).Linked
download_routes+bundle_artifacts, the final piece)