Skip to content

Commit

Permalink
Merge pull request #32 from unt-libraries/add-wacz-dict
Browse files Browse the repository at this point in the history
Add WACZ info to the resource object
  • Loading branch information
ldko authored Mar 21, 2024
2 parents 29a8fcf + 5c2c259 commit 703c44d
Show file tree
Hide file tree
Showing 4 changed files with 1,580 additions and 0 deletions.
16 changes: 16 additions & 0 deletions aubreylib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ def get_fileSets(self, manifest, fileSec, file_index):
# See if the pdf dict has value already
if not getattr(self, 'pdf_dict', None):
self.pdf_dict = {}
# Create wacz_dict if needed
if not getattr(self, 'wacz_dict', None):
self.wacz_dict = {}
manifest_view_type = ''
for fileSet in manifest:
# Get the fileSet order number
Expand Down Expand Up @@ -486,6 +489,13 @@ def get_fileSets(self, manifest, fileSec, file_index):
# No single representative pdf exists, so empty the pdf dict
self.pdf_dict = {}
multiple_pdfs = True
if fileSet_data['wacz'] and not self.wacz_dict:
# Set the wacz info to the first one we find
self.wacz_dict = {
'manifestation': manifest_num,
'fileSet': fileSet_num,
'filename': fileSet_data['wacz'],
}
self.manifestation_view_types[manifest_num] = manifest_view_type
self.manifestation_labels[manifest_num] = manifest.get("LABEL", None)
return manifestation_dict
Expand Down Expand Up @@ -520,6 +530,7 @@ def get_file_pointers(self, fileset, fileSec, file_index=None):
fileSet_view_type = ''
zoom = False
pdf = None
wacz = None
for ptr_file in file_group:
file_dict = {}
ignore_ptr_field = [
Expand Down Expand Up @@ -556,6 +567,10 @@ def get_file_pointers(self, fileset, fileSec, file_index=None):
if 'pdf' in file_dict.get('MIMETYPE', '') and\
'pdf' in file_dict.get('flocat', ''):
pdf = os.path.basename(file_dict['flocat'])
# Determine if this is a wacz fileSet
elif 'zip' in file_dict.get('MIMETYPE', '') and\
file_dict.get('flocat', '').endswith('.wacz'):
wacz = os.path.basename(file_dict['flocat'])
# If the fileSet doesn't have a view type
# (return as a regular file)
if fileSet_view_type == '':
Expand All @@ -575,6 +590,7 @@ def get_file_pointers(self, fileset, fileSec, file_index=None):
'fileSet_view_type': fileSet_view_type,
'zoom': zoom,
'pdf': pdf,
'wacz': wacz,
}
return fileSet_dict

Expand Down
Loading

0 comments on commit 703c44d

Please sign in to comment.