<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell.nu &#187; Media-Player</title>
	<atom:link href="http://www.powershell.nu/tag/media-player/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershell.nu</link>
	<description></description>
	<lastBuildDate>Wed, 14 Jul 2010 22:17:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Scripting Mp3 Tags through PowerShell</title>
		<link>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/</link>
		<comments>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 20:24:56 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Media]]></category>
		<category><![CDATA[Media-Player]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=787</guid>
		<description><![CDATA[Structuring up you Music Library can be a rather time consuming task. You can however script this rather easily through PowerShell using the taglib-sharp library. Let&#8217;s start off by downloading the Tag-Lib Library Next, We have to Load the Assembly from PowerShell in order to access the Classes. PS > $TagLib = "C:\taglib\Libraries\taglib-sharp.dll" PS > [...]]]></description>
			<content:encoded><![CDATA[<p>Structuring up you Music Library can be a rather time consuming task. You can however script this rather easily through PowerShell using the <a href="http://developer.novell.com/wiki/index.php/TagLib_Sharp">taglib-sharp</a> library.</p>
<p />
Let&#8217;s start off by downloading the <a href="http://developer.novell.com/wiki/index.php/TagLib_Sharp">Tag-Lib Library</a><br />
Next, We have to Load the Assembly from PowerShell in order to access the Classes.</p>
<p />
<pre>
<strong>
PS > $TagLib = "C:\taglib\Libraries\taglib-sharp.dll"

PS > [System.Reflection.Assembly]::LoadFile($TagLib)
</strong>

GAC    Version        Location
---    -------        --------
False  v2.0.50727     C:\taglib\Libraries\taglib-sharp.dll
</pre>
<p />
Now that we&#8217;ve loaded the dll, we need a music file that we want to set properties on, in this example I&#8217;m going to use a mp3 file. If we check out the properties on the mp3 file, we can see that nothing is set.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/09/taglib01.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/09/taglib01.jpg" alt="taglib01" title="taglib01" width="377" height="515" class="alignnone size-full wp-image-788" /></a></p>
<p />
Let&#8217;s change this through PowerShell. We have to create a variable using the [Taglib.File] Class and use the filepath as an argument to the Create() method.</p>
<p />
<pre>
<strong>
PS > $Media  =  [TagLib.File]::Create("C:\Music\My Song.mp3")
</strong>
</pre>
<p />
The object contains a couple of Properties.</p>
<p />
<pre>
<strong>
PS > $Media
</strong>

Tag                    : TagLib.NonContainer.Tag
Properties             : TagLib.Properties
TagTypesOnDisk         : Id3v1, Id3v2
TagTypes               : Id3v1, Id3v2
Name                   : C:\temp\My Song.mp3
MimeType               : taglib/mp3
Tell                   : 0
Length                 : 0
InvariantStartPosition : 4608
InvariantEndPosition   : 7109078
Mode                   : Closed
</pre>
<p />
The one that We&#8217;re interested in is the Tag property, which contains additional underlaying properties and methods. Let&#8217;s check it out:</p>
<p />
<pre>
<strong>
PS > $Media.Tag
</strong>

StartTag             : TagLib.NonContainer.StartTag
EndTag               : TagLib.NonContainer.EndTag
TagTypes             : Id3v1, Id3v2
Tags                 : {Audiograbber 1.83.01, LAME d
                       v2.PrivateFrame TagLib.Id3v2.
Title                :
Performers           : {}
PerformersSort       : {}
AlbumArtistsSort     : {}
AlbumArtists         : {}
Composers            : {}
ComposersSort        : {}
TitleSort            :
AlbumSort            :
Album                :
Comment              :
Genres               : {}
Year                 : 0
Track                : 0
TrackCount           : 0
Disc                 : 0
DiscCount            : 0
Lyrics               :
Grouping             :
BeatsPerMinute       : 0
Conductor            :
Copyright            :
Pictures             : {}
IsEmpty              : True
Artists              : {}
FirstArtist          :
FirstAlbumArtist     :
FirstAlbumArtistSort :
FirstPerformer       :
FirstPerformerSort   :
FirstComposerSort    :
FirstComposer        :
FirstGenre           :
JoinedArtists        :
JoinedAlbumArtists   :
JoinedPerformers     :
JoinedPerformersSort :
JoinedComposers      :
JoinedGenres         :
</pre>
<p />
Let&#8217;s go ahead and set a couple of Values.</p>
<p />
<pre>
<strong>
PS > $Media.Tag.Performers = "Goude"
PS > $Media.Tag.AlbumArtists = "Goude"
PS > $Media.Tag.Artists = "Goude"
PS > $Media.Tag.Album = "My Album"
PS > $Media.Tag.Genres = "Rock"
PS > $Media.Tag.Track = "1"
PS > $Media.Tag.Title = "My Song"
PS > $Media.Tag.Year = "2009"
PS > $Media.Tag.Comment = "PowerShell Demo"
PS > $Media.Save()
</strong>
</pre>
<p />
If we check out the file properties through Explorer we&#8217;ll see that the properties are set on the file.</p>
<p />
<a href="http://www.powershell.nu/wp-content/uploads/2009/09/taglib02.jpg"><img src="http://www.powershell.nu/wp-content/uploads/2009/09/taglib02.jpg" alt="taglib02" title="taglib02" width="377" height="515" class="alignnone size-full wp-image-789" /></a></p>
<p />
So, editing one file is easy, but what if you want to edit a couple of thousand files..</p>
<p />
When I did this on my Media Files i used the Folder and File Names as reference. The folder and file structure was set up accordingly:</p>
<p />
<strong><br />
C:\Music\Rock\Artist1 &#8211; Album\01 &#8211; First Song.mp3<br />
C:\Music\Rock\Artist1 &#8211; Album\02 &#8211; Second Song.mp3<br />
C:\Music\Rock\Artist2 &#8211; Album\01 &#8211; First Song.mp3<br />
</strong></p>
<p />
So with this information i could make a script that Used this information in order to set the Tags. The script uses the &#8220;Rock&#8221; folder name as Genre, Then it Splits the &#8220;Artist &#8211; Album&#8221; folder and sets Artist = Artist and Album = Album, finally it splits the file name &#8220;01 &#8211; First Song.mp3&#8243; and sets Track = 01 and Title = First Song. I&#8217;ve also error handling in the script so that You can follow up on files that didn&#8217;t pass through the script.</p>
<p />
<a href = "http://www.powershell.nu/wp-content/uploads/2009/09/set-media.ps1">Click Here to download the Script</a></p>
<p />
Examples on Running the script:</p>
<p />
<pre>
<strong>
PS > Set-Media.ps1 -Folder C:\MyMusic\Rock -LogFile C:\Log\SetMediaLog.txt
</strong>
</pre>
<p />
Note! You can always modify the script to fit your own environment and folder structure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/09/04/scripting-mp3-metadata-through-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows Media Player, MP3 and PowerShell</title>
		<link>http://www.powershell.nu/2009/01/20/windows-media-player-mp3-and-powershell/</link>
		<comments>http://www.powershell.nu/2009/01/20/windows-media-player-mp3-and-powershell/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 23:13:22 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[Media]]></category>
		<category><![CDATA[Media-Player]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=361</guid>
		<description><![CDATA[Let&#8217;s have some fun with MediaPlayer and MP3 Files. In this example, we&#8217;ll look at setting Attributes on MP3 files. First off, Let&#8217;s look at the files we want to set Attributes on: PS > ls &#124; select Name Name ---- 01 - The Wicker Man.mp3 02 - Ghost Of The Navigator.mp3 03 - Brave [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s have some fun with MediaPlayer and MP3 Files. In this example, we&#8217;ll look at setting Attributes on MP3 files. First off, Let&#8217;s look at the files we want to set Attributes on:</p>
<p />
<pre>
<strong>
PS > ls | select Name
</strong>

Name
----
01 - The Wicker Man.mp3
02 - Ghost Of The Navigator.mp3
03 - Brave New World.mp3
04 - Blood Brothers.mp3
05 - The Mercenary.mp3
06 - Dream Of Mirrors.mp3
07 - The Fallen Angel.mp3
08 - The Nomad.mp3
09 - Out Of The Silent Planet.mp3
10 - The Thin Line Between Love And Hate.mp3
</pre>
<p />
If we look at the files through Explorer, we see that they are missing their attributes. This is rather annoying if you copy them to your MP3 player and try to sort on Artist or Album. Since they don&#8217;t have any Attributes set, they will be classed as unknown. Let&#8217;s change this through PowerShell.</p>
<p />
<img src="http://www.powershell.nu/wp-content/uploads/2009/01/mediaplayer-01-500x308.jpg" alt="mediaplayer-01" title="mediaplayer-01" width="500" height="308" class="alignnone size-large wp-image-362" /></p>
<p />
Let&#8217;s start with One file. First we need to Get information about the Item. We can do this through the Get-Item CmdLet. Get-Item Displays some, but not all information we wnat to access. To solve this, we will use the Object with the WMPlayer ComObject.</p>
<p />
<pre>
<strong>
PS > $TheWickerMan = Get-Item '01 - The Wicker Man.mp3'
PS > $MediaPlayer = New-Object -Com WMPlayer.OCX
PS > $GetAttributes = $MediaPlayer.mediaCollection.add($TheWickerMan)
PS > $GetAttributes
</strong>

sourceURL         : C:UsersnigoMusicIron Maiden - Brave New World�1 - The Wicker Man.mp3
name              : 01 - The Wicker Man
imageSourceWidth  : 0
imageSourceHeight : 0
markerCount       : 0
duration          : 275,539
durationString    : 04:36
attributeCount    : 98
Error             :
</pre>
<p />
This Shows Some, but not all available Attributes, to get a complete List of available Attributes we can Loop through the AttributeNames with a for Loop. We use the AttributesCount to get the amount of Attributes. Note that the for Loop starts at Zero.</p>
<p />
<pre>
<strong>
PS > $Attributes = $GetAttributes.attributeCount

PS > for ($i = 0; $i -lt $Attributes; $i++) { $GetAttributes.getAttributeName($i) }
</strong>
</pre>
<p />
Let&#8217;s get on to business and start setting Atrributes. We do this with a little help from MediaPlayer.</p>
<p />
<pre>
<strong>
PS > $TheWickerMan = Get-Item '01 - The Wicker Man.mp3'
PS > $MediaPlayer = New-Object -Com WMPlayer.OCX

PS > $SetItemInfo = $MediaPlayer.mediaCollection.add($TheWickerMan)
PS > $SetItemInfo.setItemInfo('Title', "The Wicker Man")
PS > $SetItemInfo.setItemInfo('Artist', "Iron Maiden")
PS > $SetItemInfo.setItemInfo('Composer', "Iron Maiden")
PS > $SetItemInfo.setItemInfo('Album', "Brave New World")
PS > $SetItemInfo.setItemInfo("WM/TrackNumber", "01")
PS > $SetItemInfo.setItemInfo("WM/Genre", "Heavy Metal")
PS > $SetItemInfo.setItemInfo("UserRating", 100)
</strong>
</pre>
<p />
If we look at the File now, the Attributes are updated.</p>
<p />
<img src="http://www.powershell.nu/wp-content/uploads/2009/01/mediaplayer-02.jpg" alt="mediaplayer-02" title="mediaplayer-02" width="403" height="537" class="alignnone size-full wp-image-363" /></p>
<p />
Doing this on every single file can be a rather time consuming job. so here&#8217;s a function that does it for us. Note that in this example I use the replace operator based on the naming of my files. If you have a different way of naming your music files you might want to modify the function. I added the Start-Sleep CmdLet because i had some issues with the update, if you experience issues you can increase the Start-Sleep Seconds.</p>
<p >
<pre>
<strong>
PS > function Set-MusicProperties {

param (
	[string]$Artist = $(throw "Enter Artist Name"),
	[string]$Composer = $(throw "Enter Composer"),
	[string]$Album = $(throw "Enter Album Name"),
	[string]$Genre = $(throw "Enter Genre"),
	[int]$Rating = $(throw "Enter Rating 0-100")
)

	$CurrentPath = (Get-Location).Path
	$Items = Get-ChildItem -path $CurrentPath | Select Name

	$MediaPlayer = New-Object -Com WMPlayer.OCX

	$Items | ForEach-Object {

		Write-Host "Waiting For Files To Update"
		Start-Sleep -s 3

		$AddItem = Get-Item $_.Name

		$TrackNumber = $_.Name -replace " - .*",""
		$Title = $_.Name -replace ".* - ",""

		$SetItemInfo = $MediaPlayer.mediaCollection.add($AddItem)
		$SetItemInfo.setItemInfo('Title', $Title)
		$SetItemInfo.setItemInfo('Artist', $Artist)
		$SetItemInfo.setItemInfo('Composer', $Composer)
		$SetItemInfo.setItemInfo('Album', $Album)
		$SetItemInfo.setItemInfo("WM/TrackNumber", $TrackNumber)
		$SetItemInfo.setItemInfo("WM/Genre", $Genre)
		$SetItemInfo.setItemInfo("UserRating", $Rating)

		Write-Host "$Title Updated"
	}
}
</strong>
</pre>
<p />
Now all we got to do is set the location to the folder containing the files and call on the function and providing the arguments we wnat to set.</p>
<p />
<pre>
<strong>
PS > Set-MusicProperties "Iron Maiden" "Iron Maiden" "Brave New World" "Heavy Metal" 100
</strong>
</pre>
<p />
Open Explorer and your MP3 Files Attributes should be updated</p>
<p />
<img src="http://www.powershell.nu/wp-content/uploads/2009/01/mediaplayer-03-500x316.jpg" alt="mediaplayer-03" title="mediaplayer-03" width="500" height="316" class="alignnone size-large wp-image-364" /></p>
<p />
Below is the Code USed in this Example</p>
<p />
<pre>
<strong>
$TheWickerMan = Get-Item '01 - The Wicker Man.mp3'
$MediaPlayer = New-Object -Com WMPlayer.OCX
$GetAttributes = $MediaPlayer.mediaCollection.add($TheWickerMan)

$Attributes = $GetAttributes.attributeCount

for ($i = 0; $i -lt $Attributes; $i++) { $GetAttributes.getAttributeName($i) }

$TheWickerMan = Get-Item '01 - The Wicker Man.mp3'
$MediaPlayer = New-Object -Com WMPlayer.OCX

$SetItemInfo = $MediaPlayer.mediaCollection.add($TheWickerMan)
$SetItemInfo.setItemInfo('Title', "The Wicker Man")
$SetItemInfo.setItemInfo('Artist', "Iron Maiden")
$SetItemInfo.setItemInfo('Composer', "Iron Maiden")
$SetItemInfo.setItemInfo('Album', "Brave New World")
$SetItemInfo.setItemInfo("WM/TrackNumber", "01")
$SetItemInfo.setItemInfo("WM/Genre", "Heavy Metal")
$SetItemInfo.setItemInfo("UserRating", 100)

function Set-MusicProperties {

param (
	[string]$Artist = $(throw "Enter Artist Name"),
	[string]$Composer = $(throw "Enter Composer"),
	[string]$Album = $(throw "Enter Album Name"),
	[string]$Genre = $(throw "Enter Genre"),
	[int]$Rating = $(throw "Enter Rating 0-100")
)

	$CurrentPath = (Get-Location).Path
	$Items = Get-ChildItem -path $CurrentPath | Select Name

	$MediaPlayer = New-Object -Com WMPlayer.OCX

	$Items | ForEach-Object {

		Write-Host "Waiting For Files To Update"
		Start-Sleep -s 3

		$AddItem = Get-Item $_.Name

		$TrackNumber = $_.Name -replace " - .*",""
		$Title = $_.Name -replace ".* - ",""

		$SetItemInfo = $MediaPlayer.mediaCollection.add($AddItem)
		$SetItemInfo.setItemInfo('Title', $Title)
		$SetItemInfo.setItemInfo('Artist', $Artist)
		$SetItemInfo.setItemInfo('Composer', $Composer)
		$SetItemInfo.setItemInfo('Album', $Album)
		$SetItemInfo.setItemInfo("WM/TrackNumber", $TrackNumber)
		$SetItemInfo.setItemInfo("WM/Genre", $Genre)
		$SetItemInfo.setItemInfo("UserRating", $Rating)

		Write-Host "$Title Updated"
	}
}

Set-MusicProperties "Iron Maiden" "Iron Maiden" "Brave New World" "Heavy Metal" 100
</strong>
</pre>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/01/20/windows-media-player-mp3-and-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
