Fix ABS metadata matching to respect Audible region

Updated Audiobookshelf metadata matching to use the user's configured Audible region instead of always defaulting to 'audible' (US). Introduced mapRegionToABSProvider to map region codes to the correct provider value, and added tests for all supported regions (US, CA, UK, AU, IN).
This commit is contained in:
kikootwo
2026-01-28 13:06:41 -05:00
parent 7a9f158320
commit 12c0305a4b
3 changed files with 113 additions and 3 deletions
+15 -1
View File
@@ -5,9 +5,18 @@
import { getConfigService } from '../config.service';
import { RMABLogger } from '@/lib/utils/logger';
import { AudibleRegion } from '@/lib/types/audible';
const logger = RMABLogger.create('Audiobookshelf');
/**
* Map RMAB Audible region to Audiobookshelf provider value
*/
function mapRegionToABSProvider(region: AudibleRegion): string {
// US uses 'audible' (audible.com), all others use 'audible.{region}'
return region === 'us' ? 'audible' : `audible.${region}`;
}
interface ABSRequestOptions {
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
body?: any;
@@ -133,8 +142,13 @@ export async function triggerABSScan(libraryId: string) {
*/
export async function triggerABSItemMatch(itemId: string, asin?: string) {
try {
// Get configured Audible region to use correct ABS provider
const configService = getConfigService();
const region = await configService.getAudibleRegion();
const provider = mapRegionToABSProvider(region);
const body: any = {
provider: 'audible', // Use Audible as the metadata provider
provider, // Use region-specific Audible provider (e.g., 'audible.ca' for Canada)
};
// If we have an ASIN, we can do a direct match with 100% confidence