Last active
April 6, 2017 08:55
-
-
Save bdelacretaz/039bbfb88a7458034fe2a3f1b8dbd9dd to your computer and use it in GitHub Desktop.
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
// Read a JSON message from ActiveMQ, get a filename from it, | |
// use exiftool to get file metadata and encode in JSON | |
import groovy.json.StreamingJsonBuilder | |
def writer = new java.io.OutputStreamWriter(System.out) | |
def builder = new StreamingJsonBuilder(writer) | |
// Get JSON message from queue | |
// TODO should not ACK it if this script fails | |
def qUrl = new URL("http://admin:admin@localhost:8161/api/message/ap.metadata?type=queue&clientId=mac") | |
def basicAuth = "Basic " + qUrl.getUserInfo().bytes.encodeBase64().toString() | |
def connection = qUrl.openConnection() as HttpURLConnection | |
connection.setRequestProperty("Authorization", basicAuth); | |
def jsonInput = connection.inputStream.text | |
// Get asset URI from JSON input | |
def input = new groovy.json.JsonSlurper().parseText(jsonInput) | |
def assetUri = input.url | |
// TODO accept other types of URIs | |
def prefix = "file://" | |
def filePath = assetUri - prefix | |
// Get metadata | |
def cmd = "exiftool ${filePath}" | |
def exifProcess = cmd.execute() | |
// Build JSON output | |
builder . "asset" { | |
"request" { | |
"asset_id" assetUri | |
"operation" "ingest" | |
"processor" System.getenv("PROCESSOR") | |
"processor_role" "exiftool" | |
} | |
"metadata" { | |
exifProcess.text.eachLine { line -> | |
parts = line.split(":") | |
"${parts[0].trim()}" parts[1].trim() | |
} | |
} | |
} | |
writer.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment