Last active
December 23, 2015 00:29
-
-
Save ryanfb/6553866 to your computer and use it in GitHub Desktop.
e-codices downloader - http://www.e-codices.unifr.ch/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'nokogiri' | |
| require 'open-uri' | |
| def download_pages(uri, id) | |
| doc = Nokogiri::HTML(open(uri)) | |
| doc.xpath('//select[@id = "page_select"]/option/@value').each do |value| | |
| page = value.to_s.split('/').last | |
| page_uri = "#{uri}/#{page}/x-large" | |
| page_doc = Nokogiri::HTML(open(page_uri)) | |
| page_doc.xpath('//img[@id = "msImage"]/@src').each do |image| | |
| `wget "#{image.to_s}"` | |
| end | |
| end | |
| end | |
| # e.g. 10.5076/e-codices-kba-Ms-FZ-0018 | |
| doi = ARGV[0] | |
| # kba-Ms-FZ-0018 | |
| id = doi[/e-codices-(.*)/,1] | |
| # kba | |
| collection = id.split('-').first | |
| # Ms-FZ-0018 | |
| document = id[/#{collection}-(.*)/,1] | |
| prefix = "http://www.e-codices.unifr.ch/en/" | |
| pages_uri = prefix + "#{collection}/#{document}" | |
| binding_uri = prefix + "binding/#{collection}/#{document}" | |
| `wget "http://www.e-codices.unifr.ch/xml_descriptions/#{id}.xml"` | |
| [binding_uri, pages_uri].each {|uri| download_pages(uri, id)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment