import type { ConnectorMeta, CrawlContext } from '@rareindex/connectors'; import type { ExtractionResult } from '@rareindex/shared'; import { parseDrouotCatalogue, parseDrouotIndex } from '../_g8-auctions-eu-apac-lib/drouot-platform.js'; import { SaleResultsConnector, type HouseConfig, type ParsedSalePage, type SaleRef } from '../_g8-auctions-eu-apac-lib/sale-results.js'; /** * Osenat (Fontainebleau / Versailles / Paris — Napoleonic & military history, watches, wine, cars) — same Drouot * "site générique" platform as Ader. Index /resultats-ventes-passees?year=YYYY; lots /catalogue/?offset=N&max=50. * Osenat pages say "Résultats sans frais" → hammer prices (read per page). */ const BASE = 'https://www.osenat.com'; const HOUSE = { base: BASE, currency: 'EUR' as const }; const PAGE = 50; export class OsenatConnector extends SaleResultsConnector { readonly version = '1.0.0'; readonly house: HouseConfig = { houseName: 'Osenat', defaultCurrency: 'EUR', location: 'Fontainebleau, France', idKey: 'osenat_lot', premiumIncluded: null, fallbackSlug: 'antiques', minIntervalMs: 2500, maxPagesPerSale: 30 }; protected override minIntervalMs = 2500; async listSales(ctx: CrawlContext): Promise { const years = (this.meta.config.years as number[] | undefined) ?? [new Date().getUTCFullYear()]; const start = Number(this.meta.config.backfillFromYear ?? 2005); const now = new Date().getUTCFullYear(); const list = ctx.options.mode === 'backfill' ? Array.from({ length: now - start + 1 }, (_, i) => start + i) : years; const all: SaleRef[] = []; for (const y of list) { const url = `${BASE}/resultats-ventes-passees?year=${y}`; await this.throttle(url); const res = await ctx.fetch(url, { engines: ['api'], responseType: 'text', minQuality: 0, timeoutMs: 60_000 }); if (!res.success || !res.html) { ctx.anomaly('past_list_failed', `${url}: ${res.error ?? res.httpStatus}`); continue; } all.push(...parseDrouotIndex(res.html, HOUSE)); } return all; } salePageUrl(sale: SaleRef, page: number): string { return page > 1 ? `${sale.url.replace(/\/catalogue\/(\d+)[^?]*/, '/catalogue/$1')}?lang=fr&search=&offset=${(page - 1) * PAGE}&max=${PAGE}` : sale.url; } parseSalePage(res: ExtractionResult, sale: SaleRef): ParsedSalePage | null { return res.html ? parseDrouotCatalogue(res.html, sale, HOUSE, PAGE) : null; } } export default function createConnector(meta: ConnectorMeta) { return new OsenatConnector(meta); }