Reputation: 361
I've a xml that i extract some info needed.
And this is my code to obtain each value from nodes:
$CustomTypeColl = $XmlDocument.XIP.ContentObject.CustomType | Group-Object -NoElement
$ContentObjectColl = $XmlDocument.XIP.ContentObject.SecurityTag | Group-Object -NoElement
$BitstreamColl = [System.Collections.ArrayList]@($XmlDocument.XIP.Generation.Bitstreams.Bitstream)
$DurationColl = ($xmlDocument.XIP.Generation.Properties.Property | where {$_.PropertyName -eq "Duration"}).value
In this node - $CustomTypeColl variable i've got this values : Audio, Video, Document
In this node - $BitstreamColl mp3,mp3,mp3,mov,mov,pdf,pdf
How can i do something like this : Foreach Audio get mp3 format, Video get mov format and Document get pdf
Output needed : 'You have 3 audio in mp3 format'; 2 Videos in mov format and 2 documents in pdf.
I'm trying to do something, but with no success!
$XmlDocument.XIP.ContentObject.CustomType | % {$XmlDocument.XIP.Generation.Bitstreams.Bitstream}
Thanks for any Help!
This is my xml file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XIP xmlns="http://preservica.com/XIP/v6.0">
<InformationObject>
<Ref>de76f81d-18bd-4a0c-84d7-0a43e5385ec7</Ref>
<Title>AUT_cik02-RK-2018-10-08</Title>
<SecurityTag>U_UserAccess</SecurityTag>
<Parent>9615af72-e69b-45d1-b0f2-b04923765c21</Parent>
</InformationObject>
<Representation>
<InformationObject>de76f81d-18bd-4a0c-84d7-0a43e5385ec7</InformationObject>
<Name>Preservation-1</Name>
<Type>Preservation</Type>
<ContentObjects>
<ContentObject>1cdcc348-ab06-4938-99a9-7642edc2370c</ContentObject>
</ContentObjects>
</Representation>
<ContentObject>
<Ref>1cdcc348-ab06-4938-99a9-7642edc2370c</Ref>
<Title>AUT_cik02-RK-2018-10-08</Title>
<SecurityTag>U_UserAccess</SecurityTag>
<CustomType>video</CustomType>
<Parent>de76f81d-18bd-4a0c-84d7-0a43e5385ec7</Parent>
</ContentObject>
<Generation original="true" active="true">
<ContentObject>1cdcc348-ab06-4938-99a9-7642edc2370c</ContentObject>
<FormatGroup>mpeg-video</FormatGroup>
<EffectiveDate>2020-05-13T10:38:47Z</EffectiveDate>
<Bitstreams>
<Bitstream>Representation_Preservation_1/AUT_cik02-RK-2018-10-08/Generation/AUT_cik02-RK-2018-10-08.mp4</Bitstream>
</Bitstreams>
<Formats>
<Format valid="false">
<PUID>fmt/199</PUID>
<Priority>1</Priority>
<IdentificationMethod>Signature</IdentificationMethod>
<FormatName>MPEG-4 Media File</FormatName>
<FormatVersion> </FormatVersion>
</Format>
</Formats>
<Properties>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/10011</PUID>
<PropertyName>Vertical Aspect Ratio</PropertyName>
<Value>9</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/10005</PUID>
<PropertyName>Video Bitrate</PropertyName>
<Value>1910425</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/10006</PUID>
<PropertyName>Encoding Type</PropertyName>
<Value>Main@L4</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>TSS-prp/10</PUID>
<PropertyName>Codec Name</PropertyName>
<Value>AVC</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/19</PUID>
<PropertyName>Creating Application</PropertyName>
<Value>x264 core 155 r2901 7d0ff22</Value>
</Property>
<Property>
<Group>Audio Stream 0</Group>
<PUID>prp/10003</PUID>
<PropertyName>Number of Audio Channels</PropertyName>
<Value>2</Value>
</Property>
<Property>
<PUID>prp/10008</PUID>
<PropertyName>Number Of Video Streams</PropertyName>
<Value>1</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/10009</PUID>
<PropertyName>Frame Rate</PropertyName>
<Value>25</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/10011</PUID>
<PropertyName>Horizontal Aspect Ratio</PropertyName>
<Value>16</Value>
</Property>
<Property>
<Group>Audio Stream 0</Group>
<PUID>prp/10005</PUID>
<PropertyName>Audio Bitrate</PropertyName>
<Value>160362</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/3</PUID>
<PropertyName>Video Width</PropertyName>
<Value>1920</Value>
</Property>
<Property>
<Group>Audio Stream 0</Group>
<PUID>TSS-prp/10</PUID>
<PropertyName>Codec Name</PropertyName>
<Value>AAC</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/4</PUID>
<PropertyName>Video Height</PropertyName>
<Value>1080</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>TSS-prp/40</PUID>
<PropertyName>Scan Type</PropertyName>
<Value>progressive</Value>
</Property>
<Property>
<PUID>prp/19</PUID>
<PropertyName>Creating Application</PropertyName>
<Value>HandBrake 1.1.1 2018061800</Value>
</Property>
<Property>
<PUID>prp/10008</PUID>
<PropertyName>Number Of Audio Streams</PropertyName>
<Value>1</Value>
</Property>
<Property>
<Group>Audio Stream 0</Group>
<PUID>prp/12</PUID>
<PropertyName>Sampling Frequency</PropertyName>
<Value>48000</Value>
</Property>
<Property>
<PUID>prp/10002</PUID>
<PropertyName>Duration</PropertyName>
<Value>2M9.686S</Value>
</Property>
<Property>
<Group>Video Stream 0</Group>
<PUID>prp/5</PUID>
<PropertyName>Colour Space</PropertyName>
<Value>YUV</Value>
</Property>
</Properties>
</Generation>
<Bitstream>
<Filename>AUT_cik02-RK-2018-10-08.mp4</Filename>
<FileSize>33653548</FileSize>
<PhysicalLocation>Representation_Preservation_1/AUT_cik02- RK-2018-10-08/Generation</PhysicalLocation>
<Fixities>
<Fixity>
<FixityAlgorithmRef>SHA1</FixityAlgorithmRef>
<FixityValue>8872b97b619e967fceba3b36e8ee02aca940dfba</FixityValue>
</Fixity>
</Fixities>
</Bitstream>
</XIP>
Upvotes: 1
Views: 63
Reputation: 1184
In your example their is only one xml i asumed that all your xmls are in one folder or subfolder of this "root" folder so you can get all of them with:
Get-ChildItem -Path PATHTOYOURROOTFOLDER -Filter "*.xml" -Recurse
(leave out the recurse if you dont want it to search subfolders) and dont forget to change PATHTOYOURROOTFOLDER
$allMediaFiles = Get-ChildItem -Path PATHTOYOURROOTFOLDER -Filter "*.xml" -Recurse | % {
$content = get-content -Path $_ -Raw
$xml = [xml]$content
#this will generate a new object with only the properties you are intrested in. The advantage of this is that you dont hav nested properies wich are easier to handle and also easier to visualize
[pscustomobject]@{
title = $xml.XIP.ContentObject.Title
video_audio = $xml.XIP.ContentObject.CustomType # video of audio
SecurityTag = $xml.XIP.ContentObject.SecurityTag
length = ($xml.XIP.Generation.Properties.Property | where {$_.PropertyName -eq "Duration"}).value
formatname = $xml.XIP.Generation.Formats.Format.FormatName
filename = $xml.XIP.Bitstream.Filename
extention = $xml.XIP.Bitstream.Filename -replace ".*\.", ""
}
}
#run this to visualize the result of above
$allMediaFiles | ft
# i just copied your xml 3 times and changed one of them to mov format instead of mp4 for demo purpose
# the above line should output this:
# title video_audio SecurityTag length formatname filename extention
# ----- ----------- ----------- ------ ---------- -------- ---------
# AUT_cik02-RK-2018-10-08 video U_UserAccess 2M9.686S MPEG-4 Media File AUT_cik02-RK-2018-10-08.mp4 mp4
# AUT_cik02-RK-2018-10-08 video U_UserAccess 2M9.686S MOV Media File AUT_cik02-RK-2018-10-08.mov mov
# AUT_cik02-RK-2018-10-08 video U_UserAccess 2M9.686S MPEG-4 Media File AUT_cik02-RK-2018-10-08.mp4 mp4
$allMediaFiles | ? {$_.video_audio -eq "video"} | Group-Object -Property extention | select name, count
# this should output the results for the videos:
# Name Count
# ---- -----
# mp4 2
# mov 1
$allMediaFiles | ? {$_.video_audio -eq "audio"} | Group-Object -Property extention | select name, count
# this should output a similar result for audio
Total seconds:
$allMediaFiles = $allMediaFiles | select *, totalseconds | % {
# calculate the total seconds, u will need to use following code:
$_.length.Split("(H|M|S)")
[float]"2.45"
# set the new totalseconds field
$_.totalseconds = (New-TimeSpan -Minutes 5 -Seconds 5.254).TotalSeconds
#return $_ because this $_ will have the totalseconds filled
$_
}
$allMediaFiles | Measure-Object -Property totalseconds -sum
Upvotes: 1