diff --git a/openlibrary/catalog/get_ia.py b/openlibrary/catalog/get_ia.py index ced24114040..1aa87e32e63 100644 --- a/openlibrary/catalog/get_ia.py +++ b/openlibrary/catalog/get_ia.py @@ -27,14 +27,20 @@ def urlopen_keep_trying(url: str, headers=None, **kwargs): sleep(2) -def get_marc_record_from_ia(identifier: str) -> MarcBinary | MarcXml | None: +def get_marc_record_from_ia( + identifier: str, ia_metadata: dict | None = None +) -> MarcBinary | MarcXml | None: """ - Takes IA identifiers and returns MARC record instance. + Takes IA identifiers and optional IA metadata and returns MARC record instance. 08/2018: currently called by openlibrary/plugins/importapi/code.py when the /api/import/ia endpoint is POSTed to. + + :param ia_metadata: The full ia metadata; e.g. https://archive.org/metadata/goody, + not https://archive.org/metadata/goody/metadata """ - metadata = ia.get_metadata(identifier) - filenames = metadata['_filenames'] + if ia_metadata is None: + ia_metadata = ia.get_metadata(identifier) + filenames = ia_metadata['_filenames'] # type: ignore[index] marc_xml_filename = identifier + '_marc.xml' marc_bin_filename = identifier + '_meta.mrc' diff --git a/openlibrary/plugins/importapi/code.py b/openlibrary/plugins/importapi/code.py index 8d885bcc0ba..2f6a5ee91cd 100644 --- a/openlibrary/plugins/importapi/code.py +++ b/openlibrary/plugins/importapi/code.py @@ -230,7 +230,9 @@ def ia_import( raise BookImportError(status, 'Prohibited Item %s' % identifier) # Case 4 - Does this item have a marc record? - marc_record = get_marc_record_from_ia(identifier) + marc_record = get_marc_record_from_ia( + identifier=identifier, ia_metadata=metadata + ) if require_marc and not marc_record: raise BookImportError('no-marc-record') if marc_record: