PoshCode Archive  Artifact [15d72ff2f3]

Artifact 15d72ff2f33f46d414c83e9c9b60e9f1153ccb84aa8499fa5d1321be6b7e2f10:

  • File out-playlist.ps1 — part of check-in [4ff0292815] at 2018-06-10 13:21:22 on branch trunk — Aaron Nelson asked via twitter: “hey beefarino or JeffHicks is there a way to GCI -Recurse on a directory and basically do an Out-WindowsMediaPlayer? #PoorMansPlayList” (user: beefarino size: 1322)

# encoding: ascii
# api: powershell
# title: out-playlist.ps1
# description: Aaron Nelson asked via twitter: “hey beefarino or JeffHicks is there a way to GCI -Recurse on a directory and basically do an Out-WindowsMediaPlayer? #PoorMansPlayList”
# version: 1.0
# type: script
# author: beefarino
# license: CC0
# x-poshcode-id: 3159
# x-archived: 2012-01-15T04:25:38
# x-published: 2012-01-09T11:53:00
#
# Good idea!  Here it is!
#

param( 
	[parameter(Mandatory=$true)]
	[string]
	$name,
	
	[parameter(Mandatory=$true,ValueFromPipeline=$true)]
	$file
)

begin
{
	$script:files = @();
}
process
{
	$script:files += $file.fullname;
}
end
{
	$count = $script:files.length;
	$mediaElements = $script:files | foreach{
		"<media src='$_' />"
	};
	
[xml]$playlist = @"
<?wpl version="1.0"?>
<smil>
    <head>
        <meta name="Generator" content="out-playlist.ps1"/>
        <meta name="IsNetworkFeed" content="0"/>
        <meta name="ItemCount" content="$count"/>
        <title>$name</title>
    </head>
    <body>
        <seq>
			$mediaElements
        </seq>
    </body>
</smil>
"@;
	new-item "~\documents\my music\playlists\$name.wpl" -value '' -type file -force | out-null;
	$playlist.save( ("~\documents\my music\playlists\$name.wpl" | resolve-path) );
}