Advanced Stream Redirector

The educational technology and digital learning wiki
Jump to navigation Jump to search

Draft

Introduction

Note: With more recent Windows version, you rather should export to *.wpl (simpler XML format, but it would need a different style sheet of course)

Advanced Stream Redirector (ASX) files are based on the Extensible Markup Language (XML) syntax, and are made up of various elements with their associated tags and attributes. Each element in an ASX file defines a particular setting or action to the Microsoft Windows Media Player control. Some elements must be located in a specific position in the file relative to other elements. Some elements have required tags and attributes that must be defined in the ASX file.

Important (ASX is a typical MS standard):

  • Element names and attributes are not case-sensitive.
  • Contents may include illegal XML, e.g. a single &...

Media Player playlists

ASX may be used to print music playlists made with Media Player. It was a huge surprise to me that I couldn't just print a playlist in Windows Vista. Playlists are not representative of what ASX is being used for, but I did have just this specific need .... - Daniel K. Schneider 11:26, 30 December 2009 (UTC)

To simply print a playlist, one must either install alternative "music management programs" (and risk desktop pollution or worse) or export Media Player playlists to *.asx format and then transform the contents with XSLT.

Here is a how to for people who are familiar with Windows command files and XSLT. If you want to learn this technology read the XSLT Tutorial - Basics and the Shell script article.

(0) Install an XSLT processor, e.g. saxon

(1) Export the playlist from the Media Player with: Menu File-> Save current playlist

Below is the start of the *.asx file. As you can see there is a whole lot of information.

<Asx Version = "3.0" > 
  <Param Name = "AllowShuffle" Value = "yes" />
  <Author > </Author>
  <Title > latin-jazz A-Z</Title>
  <Entry> 
    <Duration value = "00:04:2.285" />
    <Param Name = "AcquisitionTime" Value = "24.12.2009 18:47:03" />
    <Param Name = "AcquisitionTimeDay" Value = "24" />
    <Param Name = "AcquisitionTimeMonth" Value = "12" />
    <Param Name = "AcquisitionTimeYear" Value = "2009" />
    <Param Name = "AcquisitionTimeYearMonth" Value = "24.12.2009" />
    <Param Name = "AcquisitionTimeYearMonthDay" Value = "24.12.2009" />
    <Param Name = "AlbumID" Value = "Eliane Elias Sings JobimEliane Elias" />
    <Param Name = "AlbumIDAlbumArtist" Value = "Eliane Elias Sings Jobim*;*Eliane Elias" />
    <Param Name = "AudioFormat" Value = "{00000055-0000-0010-8000-00AA00389B71}" />
    <Author > Eliane Elias</Author>
    <Param Name = "Bitrate" Value = "320000" />
    <Param Name = "CanonicalFileType" Value = "mp3" />
    <Copyright > (C) 1998 Somethin' Else Records under exclusive license to Blue Note
     (R) is a registered trademark of Capitol Records, Inc. (C) 1998 Capitol Records, Inc.</Copyright>
    <Param Name = "DefaultDate" Value = "02.01.1998 00:01:00" />
    <Param Name = "DisplayArtist" Value = "Eliane Elias" />
    <Param Name = "FileSize" Value = "7426233" />
    <Param Name = "FileType" Value = "mp3" />
    <Param Name = "Is_Protected" Value = "False" />
    <Param Name = "Is_Trusted" Value = "false" />
    <Param Name = "MediaType" Value = "audio" />
    <Param Name = "ReleaseDate" Value = "02.01.1998 00:01:00" />
    <Param Name = "ReleaseDateDay" Value = "2" />
    <Param Name = "ReleaseDateMonth" Value = "1" />
    <Param Name = "ReleaseDateYear" Value = "1998" />
    <Param Name = "ReleaseDateYearMonth" Value = "02.01.1998" />
    <Param Name = "ReleaseDateYearMonthDay" Value = "02.01.1998" />
    <Param Name = "RequestState" Value = "2" />
    <Param Name = "SourceURL" Value = "C:\Users\Kaspar\Music\latin-a-z\A Felicidade.mp3" />
    <Param Name = "Streams" Value = "audio" />
    <Title > A Felicidade</Title>
    <Param Name = "TrackingID" Value = "{89C8BECE-6CD4-4E61-807C-CFC000812229}" />
    <Param Name = "UserEffectiveRating" Value = "50" />
    <Param Name = "UserPlayCount" Value = "0" />
    <Param Name = "UserPlaycountAfternoon" Value = "0" />
    <Param Name = "UserPlaycountEvening" Value = "0" />
    <Param Name = "UserPlaycountMorning" Value = "0" />
    <Param Name = "UserPlaycountNight" Value = "0" />
    <Param Name = "UserPlaycountWeekday" Value = "0" />
    <Param Name = "UserPlaycountWeekend" Value = "0" />
    <Param Name = "UserRating" Value = "0" />
    <Param Name = "UserServiceRating" Value = "0" />
    <Param Name = "WM/AlbumArtist" Value = "Eliane Elias" />
    <Param Name = "WM/AlbumTitle" Value = "Eliane Elias Sings Jobim" />
    <Param Name = "WM/Composer" Value = "Spoken Word" />
    <Param Name = "WM/EncodingTime" Value = "24.12.2009 18:46:25" />
    <Param Name = "WM/Genre" Value = "Pop" />
    <Param Name = "WM/MediaClassPrimaryID" Value = "{D1607DBC-E323-4BE2-86A1-48A42A28441E}" />
    <Param Name = "WM/MediaClassSecondaryID" Value = "{00000000-0000-0000-0000-000000000000}" />
    <Param Name = "WM/PartOfSet" Value = "1/1" />
    <Param Name = "WM/Track" Value = "9/16" />
    <Param Name = "WM/TrackNumber" Value = "9" />
    <Param Name = "WM/Year" Value = "1998" />
    <Ref href = "..\Music\latin-a-z\A Felicidade.mp3"/>
  </Entry>
 ....
</Asx>

As you can see, most entries are not needed.

(2) Write the xsl. Open the *.asx file and look at the tags. Here is my working version for the above kind of *.asx. Not sure if MS keeps a stable version of this, or if the "Name" attributes can change.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>

<xsl:template match="Asx">
  <html>
    <head>
      <title> <xsl:value-of select="Title"/></title>
      <style type="text/css">
        body {font-family:Cambria; font-size:8px; margin-left:1cm; margin-right:0cm;}
	table {border-style: dotted;}
	td {border-bottom: dotted;}
	td {border-right: dotted;}
	th {text-align:left}
      </style>
    </head>
    <body>
      <h1><xsl:value-of select="Title"/></h1>

      <table>
	<tr>
	  <th>No</th>
	  <th>Title</th>
	  <th>Artist<br/>(Album)</th>
	  <th>Artist</th>
	  <th>Album Title</th>
	  <th>Year</th>
	  <th>Duration</th>
	</tr>
	<xsl:apply-templates select="Entry"/>
      </table>

    </body>
  </html>

</xsl:template>

<xsl:template match="Entry">
  <tr>
    <td><xsl:value-of select="position()"/></td>
    <td><xsl:value-of select="Title"/></td>
    <td><xsl:value-of select="Param[@Name='DisplayArtist']/@Value"/></td>
    <td><xsl:value-of select="Author"/></td>
    <td><xsl:value-of select="Param[@Name='WM/AlbumTitle']/@Value"/></td>
    <td><xsl:value-of select="Param[@Name='ReleaseDateYear']/@Value"/></td>
    <!-- <td><xsl:value-of select="substring-after(Duration/@value,'00:')"/></td> -->
    <td><xsl:value-of select="substring(Duration/@value,4,5)"/></td>
  </tr>
</xsl:template>
  
</xsl:stylesheet>

(3) Clean up The playlist may include illegal XML characters (thank you MS). E.g. I had to replace & by &amp;.

(4) You finally may write a batch file to produce HTML files. E.g. the following works with my saxon installation.

Contents of asx2html.cmd:

@ECHO OFF
REM Check there is a parameter
IF "%1" == "" GOTO MISSING_PARAMETERS
:START
SET file=%1
IF NOT EXIST %file%.asx GOTO MISSING_FILE
:MAIN
ECHO Creating HTML...
java -jar c:\soft\saxon\saxon9.jar %file%.asx c:\bin\asx2html.xsl > %file%.html
ECHO Done
GOTO END
:MISSING_PARAMETERS
ECHO Usage: "asx2html myplaylist" to process "myplaylist.asx" and create "myplaylist.html"
GOTO END
:MISSING_FILE
ECHO Error: '%file%.asx' not found
GOTO END
:END
@ECHO ON

Acknowledgement:

  • I found the original batch script on the web, but can't remember where.
  • I created this entry just because I made an MP3 CD with 70 titles for my wife and just wanted to print the details .... - Daniel K. Schneider 11:26, 30 December 2009 (UTC).

(5) Open a Windows shell, go to the directory if you like and type:

asx2html playlist

Links