def create_manifest(self, imgfiles): """create manifest""" # to be set in sysargs or via imagemagick imageWidth = int(self.width) imageHeight = int(self.height) identifier = "test file import" # setup factory factory = ManifestFactory() factory.set_base_metadata_uri("http://www.example.org/metadata/") factory.set_base_image_uri("http://www.example.org/iiif/") factory.set_iiif_image_info(version="2.0", lvl="2") # setup manifest mf = factory.manifest(label="Manifest") mf.viewingHint = "paged" mf.set_metadata({ "test label": "test value", "next label": "next value" }) mf.attribution = "Provided by Bodleian Library, Oxford, using ManifestFactory code from the Houghton Library, Harvard University" mf.viewingHint = "paged" mf.description = "Description of Manuscript Goes Here" seq = mf.sequence() # loop through images in path for img in imgfiles: # get path, full image name and extension imgPath, imgFullName = os.path.split(img) imgName, imgExt = os.path.splitext(imgFullName) # Mostly identity will come from incrementing number (f1r, f1v,...) # or the image's identity cvs = seq.canvas(ident="c%s" % imgName, label="Canvas %s" % imgName) cvs.set_hw(imageWidth, imageHeight) anno = cvs.annotation() al = cvs.annotationList("foo") # for demo purposes adds choices img = factory.image(imgFullName, iiif=True) img2 = factory.image(imgName + 'b' + imgExt, iiif=True) chc = anno.choice(img, [img2]) json = mf.toString(compact=False) # write to text file text_file = open(identifier.replace(" ", "") + ".json", "w") text_file.write(json) text_file.close() return json
import json from factory import ManifestFactory import urllib import os, sys baseq = "http://data.fitzmuseum.cam.ac.uk/api/?size=1000&query=" q = "Marlay%20AND%20cutting%20AND%20Category:illuminated*" destdir = "/path/to/images/fitzwilliam" fac = ManifestFactory() fac.set_base_image_uri("http://iiif-dev.localhost/services/2.0") fac.set_iiif_image_info(version="2.0") basemd = "http://localhost/prezi/fitz/" basedir = "/path/to/htdocs/prezi/fitz/" fac.set_base_metadata_uri(basemd) fac.set_base_metadata_dir(basedir) fh = urllib.urlopen(baseq+q) data = fh.read() fh.close() results = json.loads(data) mfst = fac.manifest(label="Marlay Cuttings") seq = mfst.sequence() for res in results['results']: if not res.has_key('image'): continue ident = res.get('identifier')
from factory import ManifestFactory from lxml import etree import os fh = file('web-view.html') html = fh.read() fh.close() dom = etree.HTML(html) subs = dom.xpath('//div[@class="related-records"]/dl[@class="return-art"]') fac = ManifestFactory() fac.set_base_metadata_uri("http://vm-imgrepo-tdp.nga.gov/public/manifests/") fac.set_base_image_uri("http://vm-imgrepo-tdp.nga.gov/public/objects/") fac.set_base_metadata_dir("/mnt/images/public/manifests") fac.set_iiif_image_info(2.0, 2) fac.set_debug("error") # warn will warn for recommendations, by default label = "Cézanne Sketchbook" mdhash = {"Dates": "c. 1877/1900", "Creator": "Cézanne, Paul (1839-1906)"} mdhash["Inscription"] = "Various notations overall" mdhash["Provenance"] = """ <div>Paul Cézanne (the artist's son), Paris; <br/>Paul Guillaume, Paris; <br/>Adrien Chappuis, Tresserve, Switzerland, 1933; <br/>Paul Mellon, Upperville, VA, 1967; <br/>gift to NGA, 1991 </div>""" mdhash["Exhibition History"] = """<div> <b>1991</b> NGA Anniversary 1991, 176.
import json from bottle import Bottle, route, run, request, response, abort, error import os, sys import factory from lxml import etree import uuid import urllib, urllib2, urlparse from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://showcase.iiif.io/shims/veridian/image") fac.set_iiif_image_info(version="2.0", lvl="1") fac.set_base_metadata_dir('/tmp/') fac.set_base_metadata_uri("http://showcase.iiif.io/shims/veridian/prezi/") fac.set_debug('error') PFX = "" INFO_CACHE = {} CACHEDIR = '/tmp/' VSERVER = "http://cdnc.ucr.edu/cgi-bin/cdnc" class ManifestShim(object): def __init__(self): pass def fetch(self, url, format="json"):
url = "https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=atom&language=en" fh = urllib.urlopen(url) data = fh.read() fh.close() nss = {"atom": "http://www.w3.org/2005/Atom"} dom = etree.XML(data) subs = dom.xpath('//atom:summary[@type="html"]/text()', namespaces=nss) fac = ManifestFactory() fac.set_base_metadata_uri("http://iiif-dev.localhost/prezi/mw/") fac.set_base_image_uri("http://dlss-dev-azaroth.stanford.edu/services/iiif/") fac.set_base_metadata_dir("/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/mw") fac.set_iiif_image_info(2.0, 2) fac.set_debug("error") # warn will warn for recommendations, by default label = "Wikimedia Pictures of the Day" mf = fac.manifest(ident="manifest", label=label) mf.viewingHint = "individuals" seq = mf.sequence(ident="normal", label="Normal Order") c = 0 for s in subs: hdom = etree.HTML(s) title = hdom.xpath("//span")[0] title = etree.tostring(title)
import json from bottle import Bottle, route, run, request, response, abort, error import os, sys import factory from lxml import etree import uuid import urllib, urllib2, urlparse from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://iiif-dev.localhost/services/chronam/") fac.set_iiif_image_info(version="2.0", lvl="1") fac.set_base_metadata_dir('/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/') fac.set_base_metadata_uri("http://localhost:8080/") # http://localhost:8080/list/lccn/sn99021999/1915-03-27/ed-1/seq-1.json fac.set_debug('error') PFX = "" INFO_CACHE = {} CACHEDIR = '/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/' class ChronAmManifestShim(object): def __init__(self): pass def fetch(self, url, format="json"):
import os, sys import urllib import json from factory import ManifestFactory baseq = "http://www.vam.ac.uk/api/json/museumobject/search?images=1&" baseo = "http://www.vam.ac.uk/api/json/museumobject/" # + O 123456 baseimg = "http://media.vam.ac.uk/media/thira/collection_images/" # + pid[:6] + / + pid .jpg destdir = "/path/to/images/vam" fac = ManifestFactory() fac.set_base_image_uri("http://localhost/iiif") fac.set_iiif_image_info(version="2.0") basemd = "http://localhost/prezi/vam/" basedir = "/path/to/htdocs/prezi/vam/" fac.set_base_metadata_uri(basemd) fac.set_base_metadata_dir(basedir) # before=date&after=date&q=term # offset=n q1 = baseq + "before=1200&after=1100&q=manuscript" # 126 objects def fetch(q, offset=0): if offset: q += "&offset=%s" % offset fh = urllib.urlopen(q) data = fh.read()
from factory import ManifestFactory import os # Example script to build a manifest out of all the images in a directory destdir = "/path/to/images" fac = ManifestFactory() fac.set_debug("error") fac.set_base_image_uri("http://localhost/iiif") fac.set_base_image_dir(destdir) fac.set_iiif_image_info() fac.set_base_metadata_uri("http://localhost/prezi/") fac.set_base_metadata_dir("/path/to/prezi/") mflbl = os.path.split(destdir)[1].replace("_", " ").title() mfst = fac.manifest(label=mflbl) seq = mfst.sequence() for fn in os.listdir(destdir): ident = fn[:-4] title = ident.replace("_", " ").title() cvs = seq.canvas(ident=ident, label=title) cvs.add_image_annotation(ident, True) mfst.toFile(compact=False)
def do_record(rec, rx, host, s, cxn, sequence, lastrec): deleted = rec.xpath('./o:header/@status', namespaces=ALLNS) if deleted: return format = rec.xpath('./o:metadata/odc:dc/dc:format/text()', namespaces=ALLNS) # Strip out non images skip = 0 for f in format: if f.find('/') > -1 and (not f.startswith('image/') or f.endswith('/pdf')): skip = 1 break if skip: return # request info to see if we're compound object (cpd) # if we are, then work backwards from current ID to find records for individual pages # Then reverse the order and call it a Manifest :) identifier = rec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] idx = int(identifier[identifier.rfind('/') + 1:]) ajaxinfo = get_json( 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx)) try: if not ajaxinfo['imageinfo'].has_key('type'): return except: print 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % ( host, s, idx) print ajaxinfo raise if ajaxinfo['imageinfo']['type'] == 'cpd': # Compound Object to process separately # Walk backwards through images until hit previous entry in OAI list # make a folder... print "--- Compound Object: %s" % idx sys.stdout.flush() if os.path.exists('%s/%s/manifest.json' % (s, idx)): return try: os.mkdir("%s/%s" % (s, idx)) except: pass os.chdir("%s/%s" % (s, idx)) if rx == 0: # Need to check last record of previous chunk if lastrec: previd = lastrec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/') + 1:]) + 1 else: start_image = 1 else: prev = recs[rx - 1] previd = prev.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/') + 1:]) + 1 pages = [] for imgid in range(start_image, idx): pinfo = {'id': imgid} # get H/W from ajax iajax = get_json( 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, imgid)) if not iajax['imageinfo'].has_key('height'): continue pinfo['h'] = iajax['imageinfo']['height'] pinfo['w'] = iajax['imageinfo']['width'] if (int(pinfo['h']) == 0 or int(pinfo['w']) == 0): continue try: pinfo['title'] = iajax['imageinfo']['title']['0'] except: pinfo['title'] = "Image %s" % imgid cxn.put("%s::%s::%s" % (host, s, imgid), "%s,%s" % (pinfo['w'], pinfo['h'])) pages.append(pinfo) if not pages: # back to host directory os.chdir('../..') return title = rec.xpath('./o:metadata/odc:dc/dc:title/text()', namespaces=ALLNS) creator = rec.xpath('./o:metadata/odc:dc/dc:creator/text()', namespaces=ALLNS) date = rec.xpath('./o:metadata/odc:dc/dc:date/text()', namespaces=ALLNS) description = rec.xpath('./o:metadata/odc:dc/dc:description/text()', namespaces=ALLNS) language = rec.xpath('./o:metadata/odc:dc/dc:language/text()', namespaces=ALLNS) # reinstantiate factory for subdir. not great but ... cfac = ManifestFactory() cfac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/%s/" % (host, s, idx)) cfac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) cfac.set_base_metadata_dir(os.getcwd()) cfac.set_iiif_image_info("2.0", "1") fac.set_debug('error') cmanifest = cfac.manifest(label=title[0]) try: cmanifest.set_metadata({"Creator": creator[0]}) except: pass try: cmanifest.set_metadata({"Date": date[0]}) except: pass try: cmanifest.set_metadata({"Language": language[0]}) except: pass try: cmanifest.description = description[0] except: pass cmanifest.viewingHint = "paged" cseq = cmanifest.sequence() for p in pages: cvs = cseq.canvas(ident="p%s" % p['id'], label=p['title']) cvs.set_hw(int(p['h']), int(p['w'])) anno = cvs.annotation() img = anno.image(str(p['id']), iiif=True) img.height = p['h'] img.width = p['w'] try: cmanifest.toFile(compact=False) except: print "FAILED TO WRITE %s/%s/manifest.json" % (s, idx) # back to host directory os.chdir('../..') else: # We're just a collection of images h = ajaxinfo['imageinfo']['height'] w = ajaxinfo['imageinfo']['width'] if int(h) == 0 or int(w) == 0: return ttl = ajaxinfo['imageinfo']['title']['0'] cxn.put("%s::%s::%s" % (host, s, idx), "%s,%s" % (w, h)) cvs = sequence.canvas(ident="p%s" % idx, label=ttl) cvs.set_hw(int(h), int(w)) anno = cvs.annotation() img = anno.image(str(idx), iiif=True) img.height = h img.width = w
continue try: print "Processing Set: %s" % sinfo['name'] except: print "Processing Set: %s" % s sys.stdout.flush() if os.path.exists(s): continue os.mkdir(s) fac = ManifestFactory() fac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/" % (host, s)) fac.set_base_metadata_dir(os.path.join(os.getcwd(), s)) fac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) fac.set_iiif_image_info("2.0", "1") fac.set_debug('error') manifest = fac.manifest(label=sinfo['name']) if sinfo['desc']: manifest.description = str(sinfo['desc']) manifest.attribution = "Converted from http://%s/" % host manifest.viewingHint = "individuals" sequence = manifest.sequence() dom = get_xml( 'http://%s/oai/oai.php?verb=ListRecords&set=%s&metadataPrefix=oai_dc' % (host, s)) recs = dom.xpath('/o:OAI-PMH/o:ListRecords/o:record', namespaces=ALLNS) lastrec = None for rx in range(len(recs)):
def do_record(rec, rx, host, s, cxn, sequence, lastrec): deleted = rec.xpath('./o:header/@status', namespaces=ALLNS) if deleted: return format = rec.xpath('./o:metadata/odc:dc/dc:format/text()', namespaces=ALLNS) # Strip out non images skip = 0 for f in format: if f.find('/') > -1 and (not f.startswith('image/') or f.endswith('/pdf')): skip = 1 break if skip: return # request info to see if we're compound object (cpd) # if we are, then work backwards from current ID to find records for individual pages # Then reverse the order and call it a Manifest :) identifier = rec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] idx = int(identifier[identifier.rfind('/')+1:]) ajaxinfo = get_json('http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx)) try: if not ajaxinfo['imageinfo'].has_key('type'): return except: print 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx) print ajaxinfo raise if ajaxinfo['imageinfo']['type'] == 'cpd': # Compound Object to process separately # Walk backwards through images until hit previous entry in OAI list # make a folder... print "--- Compound Object: %s" % idx sys.stdout.flush() if os.path.exists('%s/%s/manifest.json' % (s,idx)): return try: os.mkdir("%s/%s" % (s, idx)) except: pass os.chdir("%s/%s" % (s, idx)) if rx == 0: # Need to check last record of previous chunk if lastrec: previd = lastrec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/')+1:])+1 else: start_image = 1 else: prev = recs[rx-1] previd = prev.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/')+1:])+1 pages = [] for imgid in range(start_image, idx): pinfo = {'id': imgid} # get H/W from ajax iajax = get_json('http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, imgid)) if not iajax['imageinfo'].has_key('height'): continue pinfo['h'] = iajax['imageinfo']['height'] pinfo['w'] = iajax['imageinfo']['width'] if (int(pinfo['h']) == 0 or int(pinfo['w']) == 0): continue try: pinfo['title'] = iajax['imageinfo']['title']['0'] except: pinfo['title'] = "Image %s" % imgid cxn.put("%s::%s::%s" % (host, s, imgid), "%s,%s" % (pinfo['w'], pinfo['h'])) pages.append(pinfo) if not pages: # back to host directory os.chdir('../..') return title = rec.xpath('./o:metadata/odc:dc/dc:title/text()', namespaces=ALLNS) creator = rec.xpath('./o:metadata/odc:dc/dc:creator/text()', namespaces=ALLNS) date = rec.xpath('./o:metadata/odc:dc/dc:date/text()', namespaces=ALLNS) description = rec.xpath('./o:metadata/odc:dc/dc:description/text()', namespaces=ALLNS) language = rec.xpath('./o:metadata/odc:dc/dc:language/text()', namespaces=ALLNS) # reinstantiate factory for subdir. not great but ... cfac = ManifestFactory() cfac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/%s/" % (host, s, idx)) cfac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) cfac.set_base_metadata_dir(os.getcwd()) cfac.set_iiif_image_info("2.0", "1") fac.set_debug('error') cmanifest = cfac.manifest(label=title[0]) try: cmanifest.set_metadata({"Creator": creator[0]}) except: pass try: cmanifest.set_metadata({"Date": date[0]}) except: pass try: cmanifest.set_metadata({"Language": language[0]}) except: pass try: cmanifest.description = description[0] except: pass cmanifest.viewingHint = "paged" cseq = cmanifest.sequence() for p in pages: cvs = cseq.canvas(ident="p%s" % p['id'], label=p['title']) cvs.set_hw(int(p['h']), int(p['w'])) anno = cvs.annotation() img = anno.image(str(p['id']), iiif=True) img.height = p['h'] img.width = p['w'] try: cmanifest.toFile(compact=False) except: print "FAILED TO WRITE %s/%s/manifest.json" % (s, idx) # back to host directory os.chdir('../..') else: # We're just a collection of images h = ajaxinfo['imageinfo']['height'] w = ajaxinfo['imageinfo']['width'] if int(h) == 0 or int(w) == 0: return ttl = ajaxinfo['imageinfo']['title']['0'] cxn.put("%s::%s::%s" % (host, s, idx), "%s,%s" % (w, h)) cvs = sequence.canvas(ident="p%s" % idx, label=ttl) cvs.set_hw(int(h), int(w)) anno = cvs.annotation() img = anno.image(str(idx), iiif=True) img.height = h img.width = w
continue try: print "Processing Set: %s" % sinfo['name'] except: print "Processing Set: %s" % s sys.stdout.flush() if os.path.exists(s): continue os.mkdir(s) fac = ManifestFactory() fac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/" % (host, s)) fac.set_base_metadata_dir(os.path.join(os.getcwd(), s)) fac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) fac.set_iiif_image_info("2.0", "1") fac.set_debug('error') manifest = fac.manifest(label=sinfo['name']) if sinfo['desc']: manifest.description = str(sinfo['desc']) manifest.attribution = "Converted from http://%s/" % host manifest.viewingHint = "individuals" sequence = manifest.sequence() dom = get_xml('http://%s/oai/oai.php?verb=ListRecords&set=%s&metadataPrefix=oai_dc' % (host, s)) recs = dom.xpath('/o:OAI-PMH/o:ListRecords/o:record', namespaces=ALLNS) lastrec = None for rx in range(len(recs)): rec = recs[rx] do_record(rec, rx, host, s, cxn, sequence, lastrec)