Index: /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt	(revision 33010)
@@ -0,0 +1,29 @@
+INSTRUCTIONS
+TEST CORPUS GENERATION
+(java-gen-corpus/..):
+
+  "make" has presets compiling and generating datasets.
+  See makefile for commands and details
+
+
+
+DOWNLOADING SET OF PNG'S
+(COMPX520-DOWNLOADER-PNG.txt , COMPX520-RUN-PNG.sh , ddapiclient2-extended.pl)
+
+  "./COMPX520-DOWNLOADER-PNG.txt <java-gen-corpus/filename> <page_num>"
+
+
+
+
+DOWNLOADING SET OF ZIP'S
+(COMPX520-DOWNLOADER-ZIP.txt , COMPX520-RUN-XIP.sh , ddapiclient2-extended-ZIP.pl):
+
+  "./COMPX520-DOWNLOADER-ZIP.txt <java-gen-corpus/filename>"
+
+
+
+
+
+
+
+
Index: /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/-COMPX520-README.txt~	(revision 33010)
@@ -0,0 +1,27 @@
+INSTRUCTIONS
+TEST CORPUS GENERATION
+(java-gen-corpus/..):
+
+
+
+
+DOWNLOADING SET OF PNG'S
+(COMPX520-DOWNLOADER-PNG.txt , COMPX520-RUN-PNG.sh , ddapiclient2-extended.pl):
+
+./COMPX520-DOWNLOADER-PNG.txt <java-gen-corpus/filename> <page_num>
+
+
+
+
+DOWNLOADING SET OF ZIP'S
+(COMPX520-DOWNLOADER-ZIP.txt , COMPX520-RUN-XIP.sh , ddapiclient2-extended-ZIP.pl)
+
+./COMPX520-DOWNLOADER-ZIP.txt <java-gen-corpus/filename>
+
+
+
+
+
+
+
+
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt	(revision 33010)
@@ -0,0 +1,11 @@
+#!/bin/bash
+file_name=$1
+page_num=$2
+
+for id in `cat $file_name` ; do
+   
+    echo "id: $id  page_num: $page_num"
+    echo ""
+    ./COMPX520-RUN-PNG.sh $id $page_num
+  sleep 2  
+done
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-PNG.txt~	(revision 33010)
@@ -0,0 +1,11 @@
+#!/bin/bash
+file_name=$1
+page_num=$2
+
+for id in `cat $file_name` ; do
+   
+    echo "id: $id  page_num: $page_num"
+    echo ""
+    ./RUN.sh $id $page_num
+  sleep 2  
+done
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt	(revision 33010)
@@ -0,0 +1,9 @@
+#!/bin/bash
+file_name=$1
+
+for id in `cat $file_name` ; do
+    echo "DOWNLOADING ZIP OF: $id"
+    echo ""
+    ./COMPX520-RUN-ZIP.sh $id
+  sleep 2  
+done
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-DOWNLOADER-ZIP.txt~	(revision 33010)
@@ -0,0 +1,11 @@
+#!/bin/bash
+file_name=$1
+page_num=$2
+
+for id in `cat $file_name` ; do
+   
+    echo "id: $id  page_num: $page_num"
+    echo ""
+    ./RUN.sh $id $page_num
+  sleep 2  
+done
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh	(revision 33010)
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+if [ $# != 2 ] ; then 
+  echo "Usage: ./COMPX520-RUN-PNG.sh doc_id page" 1>&2
+  exit 1
+fi
+
+doc_id=$1
+page_num=$2
+
+output_file="download-images/$doc_id-$page_num.png"
+echo "Retrieving doc-id-page: $doc_id-$page_num -> $output_file"
+echo ""
+
+./dapiclient2-extended.pl "$doc_id/$page_num" > "$output_file"
+
+
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-PNG.sh~	(revision 33010)
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+if [ $# != 2 ] ; then 
+  echo "Usage: ./COMPX520-RUN-PNG.sh doc_id page" 1>&2
+  exit 1
+fi
+
+doc_id=$1
+page_num=$2
+
+output_file="download-images/page-$page_num/$doc_id-$page_num.png"
+echo "Retrieving doc-id-page: $doc_id-$page_num -> $output_file"
+echo ""
+
+./dapiclient2-extended.pl "$doc_id/$page_num" > "$output_file"
+
+
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh	(revision 33010)
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+if [ $# != 1 ] ; then 
+  echo "Usage: ./COMPX520-RUN-ZIP.sh doc_id" 1>&2
+  exit 1
+fi
+
+doc_id=$1
+
+output_file="download-zips/$doc_id.zip"
+echo "Retrieving doc-id: $doc_id -> $output_file"
+echo ""
+
+./dapiclient2-extended-ZIP.pl "$doc_id" > "$output_file"
+
+
Index: /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/COMPX520-RUN-ZIP.sh~	(revision 33010)
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+if [ $# != 1 ] ; then 
+  echo "Usage: ./RUN-ZIP.sh doc_id" 1>&2
+  exit 1
+fi
+
+doc_id=$1
+
+output_file="download-zips/$doc_id.zip"
+echo "Retrieving doc-id: $doc_id -> $output_file"
+echo ""
+
+./dapiclient2-extended-ZIP.pl "$doc_id" > "$output_file"
+
+
Index: /other-projects/is-sheet-music-encore/trunk/dapiclient2-extended-ZIP.pl
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/dapiclient2-extended-ZIP.pl	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/dapiclient2-extended-ZIP.pl	(revision 33010)
@@ -0,0 +1,157 @@
+#!/usr/bin/env perl
+
+=head1 NAME
+
+dapiclient_2
+
+=head1 DESCRIPTION
+
+This is an example perl 2-legged oauth client that makes a request to
+the full Data API. Replace OAUTH_CONSUMER_SECRET and
+OAUTH_CONSUMER_KEY (below) with the keys you received from
+http://babel.hathitrust.org/cgi/kgs and MY_IP_ADDRESS by the IP
+address of workstation or server running this script.
+
+It uses a hardcoded URL to request a single page image for a public domain item.
+
+It is intended to aid development of a fully function Data API client
+in Perl or other languages that implement HMAC_SHA1 OAuth libraries.
+
+=head1 SYNOPSIS
+
+At the Unix command line:
+
+  % cd /path/to/dapiclient_2/directory
+  % chmod u+x dapiclient_2
+
+then:
+
+  % curl 'http://yourhost/path_to_client/dapiclient_2' > mdp.39015000000128.png
+
+If your png is corrupt, run without i/o redirection to see the error code:
+
+  % curl 'http://yourhost/path_to_client/dapiclient_2'
+
+or paste the URL to your browser.
+
+=head1 OUTPUT
+
+Stream of data for the above mentioned page image file or error code.
+
+=cut
+
+use strict;
+use warnings;
+
+use CGI;
+use OAuth::Lite::Consumer;
+use OAuth::Lite::AuthMethod;
+
+# read_file()
+# Derived from:
+#   https://stackoverflow.com/questions/953707/in-perl-how-can-i-read-an-entire-file-into-a-string
+sub read_file
+{
+    my ($file) = @_;
+ 
+    my $text = do {
+	local $/ = undef;
+	open my $fh, "<", $file
+	    || die "could not open $file: $!";
+	<$fh>;
+    };
+
+    chomp($text);
+    return $text;
+}
+
+my $DEBUG=1;
+my $WEB_DISPLAY=0;
+
+my $access_key = 'OAUTH_CONSUMER_KEY';    # replace with your access_key
+my $secret_key = 'OAUTH_CONSUMER_SECRET'; # replace with your secret_key
+my $ip_address = 'MY_IP_ADDRESS';         # replace with the IP address of your workstation or server
+
+if (-f "my_access_key.txt") {
+    $access_key = read_file("my_access_key.txt");
+}
+
+if (-f "my_secret_key.txt") {
+    $secret_key = read_file("my_secret_key.txt");
+}
+
+if (-f "my_ip_address.txt") {
+    $ip_address = read_file("my_ip_address.txt");
+}
+    
+my $base_request_url = "https://babel.hathitrust.org/cgi/htd/aggregate/";
+
+my $request_url;
+if (defined $ARGV[0]) {
+    $request_url = $base_request_url.$ARGV[0];
+}
+else {
+    # The following ID is to the example given in the Data API documentation 
+    # $request_url = $base_request_url."mdp.39015000000128/1";
+    
+    # The following is an example of a 'open-open' sheet music doc
+    $request_url = $base_request_url."mdp.39015070661841/1";
+}
+    
+my $consumer = OAuth::Lite::Consumer->new
+  (
+   consumer_key    => $access_key,
+   consumer_secret => $secret_key,
+   auth_method     => OAuth::Lite::AuthMethod::URL_QUERY,
+  );
+
+if ($DEBUG) {
+    my $params = $consumer->gen_auth_params('GET', $request_url);
+    print STDERR "(Info) Resolved URL for retrieval:\n";
+    print STDERR "$request_url?v=2&";
+    print STDERR "oauth_consumer_key=$params->{'oauth_consumer_key'}&";
+    print STDERR "oauth_timestamp=$params->{'oauth_timestamp'}&";
+    print STDERR "oauth_nonce=$params->{'oauth_nonce'}&";
+    print STDERR "oauth_signature_method=$params->{'oauth_signature_method'}&";
+    print STDERR "oauth_signature=$params->{'oauth_signature'}&";
+    print STDERR "oauth_version=$params->{'oauth_version'}\n";
+}
+
+my $response = $consumer->request
+  (
+   method  => 'GET',
+   url     => $request_url,
+   params  => {
+               v => '2',
+               #cformat => 'png',
+               ip => $ip_address,
+              },
+  );
+
+my $success = $response->is_success;
+my $content_type = 'image/png';
+
+unless ($success) {
+    $content_type = 'text/html';
+}
+
+if ($WEB_DISPLAY) {
+    print CGI::header(
+                      Content_type => $content_type,
+                      Status => $response->status_line,
+                     );
+
+    unless ($success) {
+        print "<p><b>Error: " . $response->content . "</b><br/>";
+    }
+    else {
+        print $response->content;
+    }
+}
+else {
+    print $response->content;
+}
+exit $success;
+
+
+
Index: /other-projects/is-sheet-music-encore/trunk/my_access_key.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_access_key.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_access_key.txt	(revision 33010)
@@ -0,0 +1,1 @@
+f59865da76
Index: /other-projects/is-sheet-music-encore/trunk/my_access_key.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_access_key.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_access_key.txt~	(revision 33010)
@@ -0,0 +1,1 @@
+OAUTH_CONSUMER_KEY
Index: /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt	(revision 33010)
@@ -0,0 +1,1 @@
+130.217.244.16
Index: /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_ip_address.txt~	(revision 33010)
@@ -0,0 +1,1 @@
+MY_IP_ADDRESS
Index: /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt	(revision 33010)
@@ -0,0 +1,1 @@
+c2079b0810c5deda12b61552cf4d
Index: /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt~
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt~	(revision 33010)
+++ /other-projects/is-sheet-music-encore/trunk/my_secret_key.txt~	(revision 33010)
@@ -0,0 +1,1 @@
+OAUTH_CONSUMER_SECRET
