-
Notifications
You must be signed in to change notification settings - Fork 27
/
makemets
executable file
·133 lines (131 loc) · 6.02 KB
/
makemets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# drop an xsl to use
echo "<?xml version=\"1.0\"?>
<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns=\"http://www.loc.gov/METS/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:mi=\"https://mediaarea.net/mediainfo\" xmlns:premis=\"http://www.loc.gov/premis/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\" extension-element-prefixes=\"xsi\">
<xsl:output encoding=\"UTF-8\" method=\"xml\" version=\"1.0\" indent=\"yes\"/>
<xsl:template match=\"/\">
<mets>
<xsl:for-each select=\"/tree/directory[1]//file\">
<xsl:variable name=\"RELATIVE_PATH\">
<xsl:for-each select=\"ancestor-or-self::directory\">
<xsl:if test=\"name(parent::*)!='tree'\">
<xsl:value-of select=\"@name\"/>
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select=\"@name\"/>
</xsl:variable>
<xsl:if test=\"not(contains(\$RELATIVE_PATH,'metadata/')) and not(contains(\$RELATIVE_PATH,'/images/'))\">
<xsl:if test=\"document(concat(\$root,'/metadata/fileMeta/',\$RELATIVE_PATH,'_mediainfo.xml'))/mi:MediaInfo/mi:media/mi:track[@type='General']/mi:Format\">
<amdSec>
<xsl:attribute name=\"ID\">
<xsl:value-of select=\"concat('amdSec-',generate-id())\"/>
</xsl:attribute>
<techMD>
<xsl:attribute name=\"ID\">
<xsl:value-of select=\"concat('techMD-',generate-id())\"/>
</xsl:attribute>
<mdWrap MDTYPE=\"PREMIS:OBJECT\">
<xsl:attribute name=\"MDTYPE\">
<xsl:text>PREMIS:OBJECT</xsl:text>
</xsl:attribute>
<xmlData>
<premis:object xmlns=\"http://www.loc.gov/premis/v3\" xsi:type=\"file\" xsi:schemaLocation=\"info:lc/xmlns/premis-v3 http://www.loc.gov/standards/premis/v2/premis-3-0-draft.xsd\" version=\"3.0\">
<objectIdentifier>
<objectIdentifierType>Relative AIP path</objectIdentifierType>
<objectIdentifierValue>
<xsl:value-of select=\"\$RELATIVE_PATH\"/>
</objectIdentifierValue>
</objectIdentifier>
<objectCharacteristics>
<format>
<formatDesignation>
<formatName>
<xsl:value-of select=\"document(concat(\$root,'/metadata/fileMeta/',\$RELATIVE_PATH,'_mediainfo.xml'))/mi:MediaInfo/mi:media/mi:track[@type='General']/mi:Format\"/>
</formatName>
<xsl:if test=\"document(concat(\$root,'/metadata/fileMeta/',\$RELATIVE_PATH,'_mediainfo.xml'))/mi:MediaInfo/mi:media/mi:track[@type='General']/mi:Format_Version\">
<formatVersion>
<xsl:value-of select=\"document(concat(\$root,'/metadata/fileMeta/',\$RELATIVE_PATH,'_mediainfo.xml'))/mi:MediaInfo/mi:media/mi:track[@type='General']/mi:Format_Version\"/>
</formatVersion>
</xsl:if>
</formatDesignation>
</format>
<objectCharacteristicsExtension>
<xsl:copy-of select=\"document(concat(\$root,'/metadata/fileMeta/',\$RELATIVE_PATH,'_mediainfo.xml'))\"/>
</objectCharacteristicsExtension>
</objectCharacteristics>
</premis:object>
</xmlData>
</mdWrap>
</techMD>
</amdSec>
</xsl:if>
</xsl:if>
</xsl:for-each>
<fileSec>
<fileGrp>
<xsl:for-each select=\"/tree/directory[1]//file\">
<file>
<xsl:attribute name=\"ID\">
<xsl:value-of select=\"generate-id()\"/>
</xsl:attribute>
<FLocat>
<xsl:attribute name=\"xlink:href\">
<xsl:for-each select=\"ancestor-or-self::directory\">
<xsl:if test=\"name(parent::*)!='tree'\">
<xsl:value-of select=\"@name\"/>
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select=\"@name\"/>
</xsl:attribute>
<xsl:attribute name=\"LOCTYPE\">
<xsl:text>OTHER</xsl:text>
</xsl:attribute>
<xsl:attribute name=\"OTHERLOCTYPE\">
<xsl:text>SYSTEM</xsl:text>
</xsl:attribute>
</FLocat>
</file>
</xsl:for-each>
</fileGrp>
</fileSec>
<structMap>
<xsl:apply-templates select=\"/tree/directory[1]\"/>
</structMap>
</mets>
</xsl:template>
<xsl:template match=\"directory\">
<div>
<xsl:attribute name=\"TYPE\">
<xsl:text>directory</xsl:text>
</xsl:attribute>
<xsl:attribute name=\"LABEL\">
<xsl:value-of select=\"@name\"/>
</xsl:attribute>
<xsl:apply-templates select=\"file\"/>
<xsl:apply-templates select=\"directory\"/>
</div>
</xsl:template>
<xsl:template match=\"file\">
<div>
<xsl:attribute name=\"TYPE\">
<xsl:text>Item</xsl:text>
</xsl:attribute>
<fptr>
<xsl:attribute name=\"FILEID\">
<xsl:value-of select=\"generate-id()\"/>
</xsl:attribute>
</fptr>
</div>
</xsl:template>
</xsl:stylesheet>
" > /tmp/makemets.xsl
PWD=$(pwd)
cd "${1}"
#create directory structure of AIP using tree, excluding tree file itself
removeDSStore .
tree -DaNXs --du --timefmt "%Y-%m-%dT%H:%M:%SZ" -I "tree.xml" -I "mets.xml" . > /tmp/tree.xml
#use xslt to create mets document from tree.xml
xsltproc --stringparam root "$(pwd)" /tmp/makemets.xsl /tmp/tree.xml | xmlstarlet fo > "${1}/metadata/mets.xml"
cd "${PWD}"