ppn2ocr: Support TIFF in the BEST group

pull/27/head
Gerber, Mike 5 years ago
parent 4e37a52899
commit f7b43bbefa

@ -39,7 +39,7 @@ def oai_mets(ppn):
return mets return mets
def iiif_url_for_dms_url(dms_url, ppn, size): def iiif_url_for_dms_url(dms_url, ppn, size, format):
""" """
Construct an IIIF URL from a dms URL. Construct an IIIF URL from a dms URL.
@ -53,7 +53,8 @@ def iiif_url_for_dms_url(dms_url, ppn, size):
else: else:
raise ValueError(f"Unexpected URL {dms_url}") raise ValueError(f"Unexpected URL {dms_url}")
iiif_identifier = f'{ppn}-{page_num}' iiif_identifier = f'{ppn}-{page_num}'
iiif_url = f'https://content.staatsbibliothek-berlin.de/dc/{iiif_identifier}/full/{size}/0/default.jpg' iiif_quality = 'default'
iiif_url = f'https://content.staatsbibliothek-berlin.de/dc/{iiif_identifier}/full/{size}/0/{iiif_quality}.{format}'
return iiif_url return iiif_url
@ -66,6 +67,17 @@ def remove_file_grp(mets, use):
bad.getparent().remove(bad) bad.getparent().remove(bad)
def mime_type_for_format(format_):
if format_ == 'tif':
mime_type = 'image/tiff'
elif format_ == 'jpg':
mime_type = 'image/jpg'
else:
raise ValueError()
return mime_type
def make_workspace(ppn, workspace): def make_workspace(ppn, workspace):
# Make workspace directory # Make workspace directory
os.mkdir(workspace) os.mkdir(workspace)
@ -81,6 +93,7 @@ def make_workspace(ppn, workspace):
# Duplicate DEFAULT file group into a new file group BEST # Duplicate DEFAULT file group into a new file group BEST
format_ = 'tif'
file_grp_default = mets.find('//mets:fileGrp[@USE="DEFAULT"]', namespaces=XMLNS) file_grp_default = mets.find('//mets:fileGrp[@USE="DEFAULT"]', namespaces=XMLNS)
file_grp_best = deepcopy(file_grp_default) file_grp_best = deepcopy(file_grp_default)
@ -89,6 +102,7 @@ def make_workspace(ppn, workspace):
old_id = f.attrib['ID'] old_id = f.attrib['ID']
new_id = re.sub('DEFAULT', 'BEST', old_id) new_id = re.sub('DEFAULT', 'BEST', old_id)
f.attrib['ID'] = new_id f.attrib['ID'] = new_id
f.attrib['MIMETYPE'] = mime_type_for_format(format_)
for fptr in mets.findall(f'//mets:fptr[@FILEID="{old_id}"]', namespaces=XMLNS): for fptr in mets.findall(f'//mets:fptr[@FILEID="{old_id}"]', namespaces=XMLNS):
new_fptr = deepcopy(fptr) new_fptr = deepcopy(fptr)
@ -98,7 +112,7 @@ def make_workspace(ppn, workspace):
# XXX Need to fumble around with the URL for now # XXX Need to fumble around with the URL for now
flocat = f.find(f".//{{{XMLNS['mets']}}}FLocat") flocat = f.find(f".//{{{XMLNS['mets']}}}FLocat")
old_url = flocat.attrib[f"{{{XMLNS['xlink']}}}href"] old_url = flocat.attrib[f"{{{XMLNS['xlink']}}}href"]
url_iiif_full = iiif_url_for_dms_url(old_url, ppn, 'full') url_iiif_full = iiif_url_for_dms_url(old_url, ppn, 'full', format_)
flocat.attrib[f"{{{XMLNS['xlink']}}}href"] = url_iiif_full flocat.attrib[f"{{{XMLNS['xlink']}}}href"] = url_iiif_full
mets.find('//mets:fileSec', namespaces=XMLNS).append(file_grp_best) mets.find('//mets:fileSec', namespaces=XMLNS).append(file_grp_best)

Loading…
Cancel
Save