Skip to content

Fix Audible regional search and links#637

Open
therobbiedavis wants to merge 7 commits into
canaryfrom
bugfix/audible-region
Open

Fix Audible regional search and links#637
therobbiedavis wants to merge 7 commits into
canaryfrom
bugfix/audible-region

Conversation

@therobbiedavis

@therobbiedavis therobbiedavis commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix Audible region handling so Add New/search uses the configured or ad-hoc region consistently, requests regional metadata, and emits regional Audible/Amazon links.

Fixes #530
Fixes #526

Changes

Added

  • Add Add New region selectors, region-primary language fallback, and saved default-language preservation.
  • Add regression coverage for configured default region fallback, locale headers, regional links, and region preservation in add-library metadata.
  • Add a shared backend market-domain resolver for Amazon/Audible regional product URLs.

Changed

  • Thread region/language through Add New search, advanced ASIN lookup, metadata conversion, add-library metadata, and product/source URL generation.
  • Resolve omitted SearchController request regions from ApplicationSettings.DefaultSearchRegion while preserving explicit ad-hoc request regions.
  • Preserve/regionalize Audible URLs even when upstream metadata does not include an ASIN.

Fixed

  • Audible product/search API calls now send regional locale headers.
  • Audible and Amazon product links now use the selected/result region instead of always using .com domains.
  • Vitest localStorage/esbuild warnings are removed from the local unit-test path.
  • Test-created HTTP resources are disposed deterministically.

Testing

  • dotnet test Listenarr\listenarr.slnx --filter "FullyQualifiedName~SearchControllerUnifiedTests|FullyQualifiedName~AudibleServiceTests|FullyQualifiedName~SearchServiceFixesTests|FullyQualifiedName~LibraryController_AddToLibraryTests"
  • npm run type-check
  • npm run test:unit -- --run src\__tests__\AddNewView.spec.ts src\__tests__\languageMapping.spec.ts src\__tests__\AddLibraryModal.editableMetadata.spec.ts
  • .husky/pre-commit
  • git push -u origin bugfix/audible-region hook: version sync, backend format, frontend type-check, full frontend tests (71 passed | 1 skipped, 364 passed)

Notes

  • Backend test restore still reports the existing SharpCompress NU1902 warning.

@therobbiedavis therobbiedavis changed the title [codex] Fix Audible regional search and links Fix Audible regional search and links Jun 1, 2026
@therobbiedavis therobbiedavis added patch patch version bump - backward compatible bug fixes minor minor version bump - add functionality in a backward compatible manner and removed patch patch version bump - backward compatible bug fixes labels Jun 1, 2026
Comment thread listenarr.api/Controllers/SearchController.cs Fixed
Comment thread listenarr.api/Controllers/SearchController.cs Fixed
Comment thread tests/Features/Api/Services/AudibleServiceTests.cs Fixed
Comment thread tests/Features/Api/Services/SearchServiceFixesTests.cs Fixed
Comment thread listenarr.api/Controllers/SearchController.cs Fixed
@therobbiedavis

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e90b32a4e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread fe/src/views/content/AddNewView.vue Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Audible region/locale handling end-to-end so searches and metadata lookups consistently use the configured/ad-hoc region, send regional locale headers to Audible’s API, and generate region-correct Audible/Amazon product/source links across the API and SPA.

Changes:

  • Thread region + language through backend search flows (controller → search service → ASIN handler → metadata conversion) and persist ASIN region when adding to library.
  • Ensure Audible API calls include regional locale headers, and normalize emitted product/source URLs to regional domains.
  • Add/adjust backend + frontend regression tests, plus Add New UI region selectors and language defaulting based on selected region.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Features/Api/Services/SearchServiceFixesTests.cs Adds regression test ensuring ASIN search uses requested region for Audible source/product links.
tests/Features/Api/Services/AudibleServiceTests.cs Adds tests verifying locale headers are sent for search + single/batch product lookups.
tests/Features/Api/Controllers/SearchControllerUnifiedTests.cs Adds coverage for configured default region fallback and region/language threading into metadata calls + links.
tests/Features/Api/Controllers/LibraryController_AddToLibraryTests.cs Verifies ASIN identifier region is persisted when adding to library.
listenarr.domain/Models/AudibleBookMetadata.cs Adds Region to metadata payload model.
listenarr.application/Search/SearchService.cs Passes region/language into ASIN search handler from intelligent search.
listenarr.application/Search/MetadataConverters.cs Propagates region into metadata and builds region-aware Amazon/Audible product URLs.
listenarr.application/Search/AsinSearchHandler.cs Uses requested region for metadata lookups and emits region-aware source links for ASIN searches.
listenarr.application/Metadata/AudibleService.cs Enables locale headers for product endpoints and emits Audible (not Amazon) product link for ASIN direct lookups.
listenarr.application/Audiobooks/LibraryAddService.cs Preserves ASIN region when backfilling imported identifiers during add-to-library.
listenarr.api/Controllers/SearchController.cs Resolves missing regions from configured defaults, threads language into ASIN lookup, and normalizes Audible links to regional domains.
listenarr.api/Controllers/LibraryController.cs Preserves ASIN region when syncing/backfilling imported identifiers.
fe/vite.config.ts Cleans up config structure/formatting and limits esbuild “drop” config to production.
fe/src/views/library/AudiobookDetailView.vue Builds Audible links using ASIN identifier region (when available).
fe/src/views/content/AddNewView.vue Adds region selectors, defaults language from selected region, and uses regional Audible links throughout results + add flows.
fe/src/utils/languageMapping.ts Adds helper to derive primary preferred language from a region.
fe/src/types/index.ts Adds region to AudibleBookMetadata type.
fe/src/components/domain/audiobook/AudiobookModal.vue Uses region-aware Audible product/source URL builder.
fe/src/components/domain/audiobook/AudiobookDetailsModal.vue Uses region-aware Audible product/source URL builder.
fe/src/components/domain/audiobook/AddLibraryModal.vue Preserves region in metadata payload and uses it for Audible metadata lookup + links.
fe/src/tests/test-setup.ts Reworks localStorage polyfill to avoid Node localStorage warnings by defining test storage directly.
fe/src/tests/languageMapping.spec.ts Adds tests for region→primary-language mapping helper.
fe/src/tests/AddNewView.spec.ts Updates/adds tests for region selector UI, language defaulting, and regional Audible links in results.
fe/src/tests/AddLibraryModal.editableMetadata.spec.ts Ensures region is passed to Audible metadata lookup and preserved in metadata updates.

Comment thread listenarr.api/Controllers/SearchController.cs
Comment thread listenarr.api/Controllers/SearchController.cs
Comment thread listenarr.application/Search/MetadataConverters.cs Outdated
@therobbiedavis therobbiedavis marked this pull request as ready for review June 2, 2026 00:39
@therobbiedavis therobbiedavis requested a review from a team June 2, 2026 00:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 446a8a6f64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread fe/src/views/content/AddNewView.vue Outdated
Introduce region-aware Audible/Amazon product URLs and search region handling across frontend and backend. Frontend: add region select UI, persist/derive preferred language from region, thread region through search results and metadata, use buildAudibleProductUrl util, and add region to Audible metadata types. Backend: normalize Audible/Amazon domains, build product links using region, treat Audible URLs/hosts robustly, and include locale headers for Audible API calls. Also propagate region into ASIN searches and metadata converters. Tests were updated/added to reflect region-specific behavior and URL generation.
Make SearchController's region parameter nullable and resolve it via ResolveSearchRegionAsync, then use the resolved region when building the Audible sourceUrl. Replace AudibleService's hardcoded region-to-URL switch with MarketDomainResolver.GetAudibleDomain and add the necessary using. Centralizes region/domain logic and ensures consistent Audible base URLs.
Introduce caching and normalization for search results, add test builders and update docs.

- SearchController / SettingsController: accept optional IMemoryCache, cache resolved default search region for 60s and remove cache when settings are saved.
- Extract NormalizeMetadataSearchResultImagesAsync to centralize image normalization/caching (serve local /api images when possible) and replace duplicated code paths.
- Frontend AddNewView: add region field to TitleSearchResult, extract normalizeResultRegionAndProductUrl helper, and add small test interaction (language select) in AddNewView.spec.ts.
- Application: MarketDomainResolver now uses a single dictionary of markets; AsinSearchHandler signature allows nullable region.
- Tests: add MetadataSearchResultBuilder and refactor SearchControllerUnifiedTests to use BaseTests/DI helpers; add new tests verifying default region fallbacks and regional sourceUrl behavior.
- Docs: extend .github guidance files with pre-commit/pre-push rules, layering and async conventions, backend test conventions, and formatting quick-fix steps.

These changes reduce duplication, improve regional URL handling, enable short-lived caching of default region, and add test helpers + docs to standardize test patterns.
Introduce reusable test builders (AudibleBookResponse, AudibleSearchResponse, AudibleSearchResult, SeriesLookupItem) and extend ApplicationSettingsBuilder. Refactor Listenarr.Application.Search to centralize Audible->AudibleBookResponse mapping (ToAudibleBookResponse) and ensure Region is populated. Update Listenarr.Api.SearchController to determine metadata source base URLs (Amazon vs Audible), move image normalization into NormalizeMetadataSearchResultImagesAsync and add safe background caching with logged failures. Update many tests to use the new builders and add SearchService integration tests. Frontend: ensure Amazon product links include region and add a unit test for Amazon metadata badge. Update repository docs (.github) to clarify formatting, layering and backend test conventions.
@therobbiedavis therobbiedavis force-pushed the bugfix/audible-region branch from 446a8a6 to 8e75aeb Compare June 2, 2026 00:47
clearAdvancedSearch now checks applicationSettings.defaultSearchLanguage and uses it (after normalizePreferredSearchLanguage) when present; only if no saved default exists does it fall back to the region primary via getPrimaryPreferredSearchLanguageForRegion(searchLanguage.value). This mirrors the onMounted behavior and preserves existing reset logic for errors and paging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor minor version bump - add functionality in a backward compatible manner

Projects

None yet

3 participants