Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Last active June 24, 2023 06:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save PrateekKumarSingh/faafbfa53fcd753cf240f29deb769d87 to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/faafbfa53fcd753cf240f29deb769d87 to your computer and use it in GitHub Desktop.
Get MetaData from a .MP3 or .MP4 file
Function Get-MP3MetaData
{
[CmdletBinding()]
[Alias()]
[OutputType([Psobject])]
Param
(
[String] [Parameter(Mandatory=$true, ValueFromPipeline=$true)] $Directory
)
Begin
{
$shell = New-Object -ComObject "Shell.Application"
}
Process
{
Foreach($Dir in $Directory)
{
$ObjDir = $shell.NameSpace($Dir)
$Files = gci $Dir| ?{$_.Extension -in '.mp3','.mp4'}
Foreach($File in $Files)
{
$ObjFile = $ObjDir.parsename($File.Name)
$MetaData = @{}
$MP3 = ($ObjDir.Items()|?{$_.path -like "*.mp3" -or $_.path -like "*.mp4"})
$PropertArray = 0,1,2,12,13,14,15,16,17,18,19,20,21,22,27,28,36,220,223
Foreach($item in $PropertArray)
{
If($ObjDir.GetDetailsOf($ObjFile, $item)) #To avoid empty values
{
$MetaData[$($ObjDir.GetDetailsOf($MP3,$item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
}
}
New-Object psobject -Property $MetaData |select *, @{n="Directory";e={$Dir}}, @{n="Fullname";e={Join-Path $Dir $File.Name -Resolve}}, @{n="Extension";e={$File.Extension}}
}
}
}
End
{
}
}
#ForEach($item in ("D:\Powershell\Tutorials\4_DSC" |Get-MP3MetaData)){
# $NewName = [regex]::Replace($(($item.Title).Split(":")[1].Trim() + $item.extension),"[*(/)\\&#]",{''})
# $Oldname = $item.Fullname
# Rename-Item -LiteralPath $item.Fullname -NewName $NewName -Force
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment