RoughDraft.types.ps1xml
<!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> <Types> <Type> <Name>RoughDraft.Media</Name> <Members> <AliasProperty> <Name>FilePath</Name> <ReferencedMemberName>InputPath</ReferencedMemberName> </AliasProperty> <ScriptProperty> <Name>Album</Name> <GetScriptBlock> <# .SYNOPSIS Gets Album Metadata .DESCRIPTION Gets the Album Metadata, if present. #> param() return $this.'.Metadata'.Album </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Album Metadata .DESCRIPTION Changes the Album metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{Album="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Album = $propertyToSet.album Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>AlbumArtist</Name> <GetScriptBlock> <# .SYNOPSIS Gets Album Artist Metadata .DESCRIPTION Gets the Album Artist Metadata, if present. #> param() return $( if ($this.'.Metadata'.AlbumArtist) { $this.'.Metadata'.AlbumArtist } elseif ($this.'.Metadata'.album_artist) { $this.'.Metadata'.album_artist } ) </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Album Artist Metadata .DESCRIPTION Changes the Album Artist metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{album_artist="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.AlbumArtist = $propertyToSet.album_artist Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Artist</Name> <GetScriptBlock> <# .SYNOPSIS Gets Artist Metadata .DESCRIPTION Gets the Artist Metadata, if present. #> param() return $( if ($this.'.Metadata'.Artist) { $this.'.Metadata'.Artist } else { $null } ) </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Artist Metadata .DESCRIPTION Changes the Artist metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{artist="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.AlbumArtist = $propertyToSet.artist Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>AspectRatio</Name> <GetScriptBlock> <# .SYNOPSIS Gets a Video or Image Aspect Ratio .DESCRIPTION Gets the aspect ratio of the first video or image stream. #> foreach ($streamInfo in $this.Streams) { if ($streamInfo.codec_type -ne 'video') { continue } if ($streamInfo.display_aspect_ratio) { return $streamInfo.display_aspect_ratio } } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>AudioBitrate</Name> <GetScriptBlock> <# .SYNOPSIS Gets Audio Bitrate .DESCRIPTION Gets an Audio's Bitrate, if the information is available in any Audio stream. #> foreach ($streamInfo in $this.Streams) { if ($streamInfo.codec_type -ne 'audio') { continue } if ($streamInfo.bit_rate) { return ($streamInfo.bit_rate -as [int]) } } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>BPM</Name> <GetScriptBlock> <# .SYNOPSIS Gets BPM Metadata .DESCRIPTION Gets the BPM Metadata, if present. #> param() if ($this.'.Metadata'.BPM) { return ($this.'.Metadata'.BPM -as [double]) } elseif ($this.'.Metadata'.TBPM) { return ($this.'.Metadata'.TBPM -as [double]) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the BPM Metadata .DESCRIPTION Changes the BPM metadata for a media file (persistently, if possible) .NOTES BPM is stored within the ID3 tag `TBPM`. #> param() $propertyToSet = @{TBPM="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.BPM = $propertyToSet.TBPM Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Comment</Name> <GetScriptBlock> <# .SYNOPSIS Gets Comment Metadata .DESCRIPTION Gets the Comment Metadata, if present. #> param() return $this.'.Metadata'.Comment </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Comment Metadata .DESCRIPTION Changes the Comment metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{comment="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Comment = $propertyToSet.comment Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Composer</Name> <GetScriptBlock> <# .SYNOPSIS Gets Composer Metadata .DESCRIPTION Gets the Composer Metadata, if present. #> param() return $this.'.Metadata'.Composer -split '[\;\\/]' </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Composer Metadata .DESCRIPTION Changes the Composer metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{composer=$args -join '/'} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Composer = $propertyToSet.Composer Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Copyright</Name> <GetScriptBlock> <# .SYNOPSIS Gets Copyright Metadata .DESCRIPTION Gets the Copyright Metadata, if present. #> param() return $this.'.Metadata'.Copyright </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Copyright Metadata .DESCRIPTION Changes the Copyright metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{copyright="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Copyright = $propertyToSet.copyright Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>CreationTime</Name> <GetScriptBlock> <# .SYNOPSIS Gets Creation Time Metadata .DESCRIPTION Gets the Creation Time Metadata, if present. #> param() if ($this.'.Metadata'.CreationTime) { return ($this.'.Metadata'.CreationTime -as [DateTime]) } elseif ($this.'.Metadata'.creation_time) { return ($this.'.Metadata'.creation_time -as [DateTime]) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Creation Time Metadata .DESCRIPTION Changes the Creation Time metadata for a media file (persistently, if possible) #> param() $dateTimeArgs = [DateTime]$($args[0]) $datePortion = @($dateTimeArgs.ToString('s') -split '-', 2)[0] $propertyToSet = @{creation_time="$datePortion"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.CreationTime = $propertyToSet.creation_time Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Date</Name> <GetScriptBlock> <# .SYNOPSIS Gets Date Metadata .DESCRIPTION Gets the Date Metadata, if present. #> param() $dateInfo = if ($this.'.Metadata'.date) { $this.'.Metadata'.date } elseif ($this.'.Metadata'.year) { $this.'.Metadata'.year } if ($dateInfo -match '^\d{4}$') { return ([datetime]::ParseExact($dateInfo, "yyyy", $null)) } elseif ($dateInfo -as [DateTime]) { return ($dateInfo -as [DateTime]) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Date Metadata .DESCRIPTION Changes the Date metadata for a media file (persistently, if possible) #> param( [ValidateScript({ if ($_ -match '^\d{4}$') { return $true } elseif ($_ -is [DateTime]) { return $true } else { throw "Year must be a 4-digit number or a DateTime object" } })] [PSObject] $Date ) $propertyToSet = [Ordered]@{date="$Date"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } if ($Date -is [DateTime]) { $propertyToSet.date = $Date.ToString('yyyy-MM-dd') if (-not $this.'.Metadata'.year) { $propertyToSet.year = $Date.Year $this.'.Metadata'.year = $propertyToSet.year } } $this.'.Metadata'.date = $propertyToSet.date Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Description</Name> <GetScriptBlock> <# .SYNOPSIS Gets Description Metadata .DESCRIPTION Gets the Description Metadata, if present. #> param() if ($this.'.Metadata'.Description) { return $this.'.Metadata'.Description } elseif ($this.'.Metadata'.desc) { return $this.'.Metadata'.desc } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Description Metadata .DESCRIPTION Changes the Description metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{desc="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Description = $propertyToSet.desc Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Disc</Name> <GetScriptBlock> <# .SYNOPSIS Gets Disc Metadata .DESCRIPTION Gets the Disc Metadata, if present. #> param() if ($this.'.Metadata'.disc) { return $this.'.Metadata'.disc } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Disc Metadata .DESCRIPTION Changes the Disc metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{disc="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Disc = $propertyToSet.disc Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>EpisodeId</Name> <GetScriptBlock> <# .SYNOPSIS Gets EpisodeID Metadata .DESCRIPTION Gets the EpisodeID Metadata, if present. #> param() if ($this.'.Metadata'.EpisodeID) { return $this.'.Metadata'.EpisodeID } elseif ($this.'.Metadata'.episode_id) { return $this.'.Metadata'.episode_id } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the EpisodeID Metadata .DESCRIPTION Changes the EpisodeID metadata for a media file (persistently, if possible) .NOTES EpisodeID is stored within the ID3 tag `TVEN`. #> param() $propertyToSet = @{"episode_id"="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.EpisodeID = $propertyToSet.episode_id Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>FileName</Name> <GetScriptBlock> <# .SYNOPSIS Gets a media file name .DESCRIPTION Gets the name of a media file #> $this.InputPath | Split-Path -Leaf </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Genre</Name> <GetScriptBlock> <# .SYNOPSIS Gets Genre Metadata .DESCRIPTION Gets the Genre Metadata, if present. #> param() return $this.'.Metadata'.genre </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Genre Metadata .DESCRIPTION Changes the Genre metadata for a media file (persistently, if possible) #> param() $unrolledArgs = $args | . { process { $_ } } $propertyToSet = @{genre=$unrolledArgs -join ' ; '} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.genre = $propertyToSet.genre Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Grouping</Name> <GetScriptBlock> <# .SYNOPSIS Gets Grouping Metadata .DESCRIPTION Gets the Grouping Metadata, if present. #> param() return @($this.'.Metadata'.Grouping -split '[\;/]') -as [string[]] </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Grouping Metadata .DESCRIPTION Changes the Grouping metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{grouping=$args -join '/'} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Grouping = $propertyToSet.grouping Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>InitialKey</Name> <GetScriptBlock> <# .SYNOPSIS Gets InitialKey Metadata .DESCRIPTION Gets the InitialKey Metadata, if present. #> param() if ($this.'.Metadata'.InitialKey) { return ($this.'.Metadata'.InitialKey) } elseif ($this.'.Metadata'.TKEY) { return ($this.'.Metadata'.TKEY) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the InitialKey Metadata .DESCRIPTION Changes the InitialKey metadata for a media file (persistently, if possible) .NOTES InitialKey is stored within the ID3 tag `TKEY`. #> param() $propertyToSet = @{TKEY="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.InitialKey = $propertyToSet.TKEY Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Location</Name> <GetScriptBlock> <# .SYNOPSIS Gets Location Metadata .DESCRIPTION Gets the Location Metadata, if present. #> param() return $this.'.Metadata'.location </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Location Metadata .DESCRIPTION Changes the Location metadata for a media file (persistently, if possible) Location should be a pair of coordinates (without space), followed by a slash. Location _can_ include additional coordinates or a description, followed by an additional slash. #> param() $unrolledArgs = $args | . { process { $_ } } $propertyToSet = @{location=$args} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.location = $propertyToSet.location Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Lyric</Name> <GetScriptBlock> <# .SYNOPSIS Gets InitialKey Metadata .DESCRIPTION Gets the InitialKey Metadata, if present. #> param() # If we already have lyrics if ($this.'.Metadata'.Lyrics) { # return them return ($this.'.Metadata'.Lyrics) } # Otherwise, if lyrics exist for the current UI culture elseif ($this.'.Metadata'."lyrics-$([cultureinfo]::CurrentUICulture.ThreeLetterISOLanguageName)") { # return them return ($this.'.Metadata'."lyrics-$([cultureinfo]::CurrentUICulture.ThreeLetterISOLanguageName)") } # Otherwise, if English lyrics exist elseif ($this.'.Metadata'.'lyrics-eng') { # return them. return $this.'.Metadata'.'lyrics-eng' } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Lyric Metadata .DESCRIPTION Changes the Lyric metadata for a media file (persistently, if possible) .NOTES Lyric is stored within a localized ID3 tag `lyrics-locale` (for example `lyrics-eng`). #> param() $lyricCulture = [cultureinfo]::CurrentUICulture $lyricLines = @(foreach ($arg in $args) { if ($arg -is [cultureinfo]) { $lyricCulture = $arg } elseif ($arg -as [cultureinfo]) { $lyricCulture = $arg -as [cultureinfo] } else { "$arg" } }) $lyricProperty = "lyrics-$($lyricCulture.ThreeLetterISOLanguageName)" $propertyToSet = @{"lyrics-$($lyricCulture.ThreeLetterISOLanguageName)"=$lyricLines -join [Environment]::NewLine} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Lyrics = $propertyToSet.TKEY Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>MediaType</Name> <GetScriptBlock> <# .SYNOPSIS Gets the Media Type .DESCRIPTION Gets the Media Type of a file discovered by Get-Media. .NOTES Getting the Media Type also decorates the object as that media type, so that extended Audio, Video, and Image functionality are available. .EXAMPLE Get-Media -InputPath .\a.mp4 | Select-Object -ExpandProperty MediaType #> param() $allCodecTypes = $this.CodecTypes -join ' ' $thisMediaType = if ($allCodecTypes -eq 'audio') { 'Audio' } elseif ($allCodecTypes -match '^video') { if ($this.Duration -and $this.Duration.TotalMilliseconds -gt 50) { 'Video' } else { 'Image' } } if ($this.pstypenames -notcontains "RoughDraft.$thisMediaType") { $this.pstypenames.add("RoughDraft.$thisMediaType") } $thisMediaType </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Mood</Name> <GetScriptBlock> <# .SYNOPSIS Gets Mood Metadata .DESCRIPTION Gets the Mood Metadata, if present. #> param() if ($this.'.Metadata'.Mood) { return ($this.'.Metadata'.Mood) } elseif ($this.'.Metadata'.'WM/MOOD') { return ($this.'.Metadata'.'WM/MOOD') } elseif ($this.'.Metadata'.'id3v2_priv.WM/MOOD') { return ($this.'.Metadata'.'id3v2_priv.WM/MOOD') } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Mood Metadata .DESCRIPTION Changes the Mood metadata for a media file (persistently, if possible) .NOTES Mood is stored within the ID3 tag `WM/MOOD`. #> param() $propertyToSet = @{"id3v2_priv.WM/MOOD"="$args";mood="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Mood = $propertyToSet."id3v2_priv.WM/MOOD" Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Network</Name> <GetScriptBlock> <# .SYNOPSIS Gets Network Metadata .DESCRIPTION Gets the Network Metadata, if present. #> param() if ($this.'.Metadata'.Network) { return ($this.'.Metadata'.Network) } elseif ($this.'.Metadata'.tvnn) { return ($this.'.Metadata'.tvnn) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Network Metadata .DESCRIPTION Changes the Network metadata for a media file (persistently, if possible) .NOTES Network is stored within the ID3 tag `tvnn`. #> param() $propertyToSet = @{network="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Network = $propertyToSet.tvnn Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>PixelFormat</Name> <GetScriptBlock> <# .SYNOPSIS Gets a Video or Image PixelFormat .DESCRIPTION Gets the pixel format the first video or image stream. #> foreach ($streamInfo in $this.Streams) { if ($streamInfo.codec_type -ne 'video') { continue } if ($streamInfo.pix_fmt) { return $streamInfo.pix_fmt } } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Producer</Name> <GetScriptBlock> <# .SYNOPSIS Gets Producer Metadata .DESCRIPTION Gets the Producer Metadata, if present. #> param() return $this.'.Metadata'.Producer </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Producer Metadata .DESCRIPTION Changes the Producer metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{producer=$args -join '/'} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Producer = $propertyToSet.producer Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Publisher</Name> <GetScriptBlock> <# .SYNOPSIS Gets Publisher Metadata .DESCRIPTION Gets the Publisher Metadata, if present. #> param() return $this.'.Metadata'.Publisher </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Publisher Metadata .DESCRIPTION Changes the Publisher metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{"WM/Publisher"="$args";TPUB="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Publisher = $propertyToSet."WM/Publisher" Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Show</Name> <GetScriptBlock> <# .SYNOPSIS Gets Show Metadata .DESCRIPTION Gets the Show Metadata, if present. #> param() if ($this.'.Metadata'.Show) { return ($this.'.Metadata'.Show) } elseif ($this.'.Metadata'.TVSH) { return ($this.'.Metadata'.TVSH) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Show Metadata .DESCRIPTION Changes the Show metadata for a media file (persistently, if possible) .NOTES Show is stored within the ID3 tag `TVSH`. #> param() $propertyToSet = @{TVSH="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Show = $propertyToSet.TVSH Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Subtitle</Name> <GetScriptBlock> <# .SYNOPSIS Gets Subtitle Metadata .DESCRIPTION Gets the Subtitle Metadata, if present. .NOTES This refers to the Subtitle of a file, not the Subtitles for a file. #> param() if ($this.'.Metadata'.Subtitle) { return ($this.'.Metadata'.Subtitle) } elseif ($this.'.Metadata'.TIT3) { return ($this.'.Metadata'.TIT3) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Subtitle Metadata .DESCRIPTION Changes the Subtitle metadata for a media file (persistently, if possible) .NOTES Subtitle is stored within the ID3 tag `TIT3`. This refers to the subtitle of a file, not the subtitles _for_ a file. #> param() $propertyToSet = @{TIT3="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Show = $propertyToSet.TIT3 Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Synopsis</Name> <GetScriptBlock> <# .SYNOPSIS Gets Synopsis Metadata .DESCRIPTION Gets the Synopsis Metadata, if present. #> param() if ($this.'.Metadata'.Synopsis) { return ($this.'.Metadata'.Synopsis) } elseif ($this.'.Metadata'.ldes) { return ($this.'.Metadata'.ldes) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Synopsis Metadata .DESCRIPTION Changes the Synopsis metadata for a media file (persistently, if possible) .NOTES Synopsis is stored within the ID3 tag `ldes`. #> param() $propertyToSet = @{ldes="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Synopsis = $propertyToSet.ldes Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Title</Name> <GetScriptBlock> <# .SYNOPSIS Gets Title Metadata .DESCRIPTION Gets the Title Metadata, if present. #> param() return $this.'.Metadata'.Title </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Title Metadata .DESCRIPTION Changes the Title metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{title="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.title = $propertyToSet.title Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Track</Name> <GetScriptBlock> <# .SYNOPSIS Gets Track Metadata .DESCRIPTION Gets the Track Metadata, if present. #> param() $trackAsInt = $this.'.Metadata'.Track -as [int] if ($trackAsInt -gt 0) { return $trackAsInt } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Track Metadata .DESCRIPTION Changes the Track metadata for a media file (persistently, if possible) #> param() $propertyToSet = @{track="$args"} if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } $this.'.Metadata'.Track = $propertyToSet.track Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>VideoBitrate</Name> <GetScriptBlock> <# .SYNOPSIS Gets a Video's Bitrate .DESCRIPTION Gets a Video's Bitrate, if the information is available in any Video stream. #> foreach ($streamInfo in $this.Streams) { if ($streamInfo.codec_type -ne 'video') { continue } if ($streamInfo.bit_rate) { return ($streamInfo.bit_rate -as [int]) } } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Year</Name> <GetScriptBlock> <# .SYNOPSIS Gets Year Metadata .DESCRIPTION Gets the Year Metadata, if present. #> param() $yearInfo = if ($this.'.Metadata'.Year) { $this.'.Metadata'.Year } elseif ($this.'.Metadata'.date) { $this.'.Metadata'.date } if ($yearInfo -match '^\d{4}$') { return ($yearInfo -as [int]) } elseif ($yearInfo -as [DateTime]) { return ([int]($yearInfo -as [datetime]).Year) } </GetScriptBlock> <SetScriptBlock> <# .SYNOPSIS Sets the Year Metadata .DESCRIPTION Changes the Year metadata for a media file (persistently, if possible) #> param( [ValidateScript({ if ($_ -match '^\d{4}$') { return $true } elseif ($_ -is [DateTime]) { return $true } else { throw "Year must be a 4-digit number or a DateTime object" } })] [PSObject] $Year ) $propertyToSet = [Ordered]@{year=$year} if ($year -is [DateTime]) { $propertyToSet.year = $year.Year } # $yearPortion = @($datePortion -split '-')[0] if (-not $this.'.Metadata') { $this.'.Metadata' = [Ordered]@{} } if (-not $this.'.Metadata'.date) { $propertyToSet.date = $propertyToSet.year if ($year -is [DateTime]) { $propertyToSet.date = $year.ToString('yyyy-MM-dd') } $this.'.Metadata'.date = $propertyToSet.date } $this.'.Metadata'.Year = $propertyToSet.year Set-Media -InputPath $this.InputPath -Property $propertyToSet </SetScriptBlock> </ScriptProperty> </Members> </Type> </Types> |