Last active
August 29, 2015 14:22
-
-
Save richardlehane/2e3125f134601e93d0b8 to your computer and use it in GitHub Desktop.
combine siegfried and archivematica extension matching
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
| from __future__ import print_function | |
| import os.path | |
| import json | |
| import subprocess | |
| import sys | |
| def file_tool(path): | |
| return subprocess.check_output(['file', path]).strip() | |
| def main(f): | |
| try: | |
| result = json.loads(subprocess.check_output(["sf", "-json", f])) | |
| except subprocess.CalledProcessError as e: | |
| print("Siegfried exited {} and no format was found.".format(e.returncode), file=sys.stderr) | |
| return 1 | |
| match = result['files'][0] | |
| if len(match['matches']) == 0 or match['matches'][0]['puid'] == 'UNKNOWN': | |
| if "text" in file_tool(f): | |
| print("x-fmt/111") | |
| else: | |
| (_, extension) = os.path.splitext(f) | |
| if extension: | |
| print extension.lower() | |
| else: | |
| print("Siegfried exited 0 but no format was found.", file=sys.stderr) | |
| return 1 | |
| else: | |
| print(match['matches'][0]['puid']) | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment