Click here to Skip to main content
13,452,991 members (50,322 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 25 Sep 2009

Podcast (RSS) to Playlist

, 1 Oct 2009
Rate this:
Please Sign up or sign in to vote.
Convert podcast feeds into a variety of playlist formats on the fly by applying XSLT on RSS XML

Windows Media Player

Windows Media Player playing the Channel9 video podcasts as a playlist.


This article and its code provide a simple way to take a podcast feed and convert it to a playlist file/URL that Windows Media Player, Windows Media Center, Winamp or other players can play by applying XSLT on RSS XML.


I use Windows Media Player (WMP) to watch/listen to several video/audio podcasts. The problem is that it’s not the best player for podcasts and doesn't really have any built-in support for them. I've tried applications such as Juice and a few add-ins for Windows Media Center (such as TV Tonic), but they all seemed to always download the podcast files to a local directory and usually needed to be running in the background to keep the directories in sync with the latest episodes.

I wanted something to where I could just click on a link or plug in a URL in WMP and have it automatically start streaming the latest podcast episodes without waiting for anything to download. I also didn't want to ever have to clean up any directories by removing older files or install any other applications or plug-ins. I wanted to be able to click the next/previous buttons on my keyboard (or remote) and be able to skip to the next or previous episodes in the podcast, just like a playlist works.

The key here is that I wanted a RSS podcast feed, to behave just like a playlist in WMP. The problem is that WMP doesn't understand RSS XML, but it does understand the ASX (Advanced Stream Redirector) playlist XML (among other playlist formats). What I decided to do is create a C# script to take the RSS XML and convert it to ASX XML (or other playlist formats) using an XSLT transformation file.

A Solution

The solution here is just a single .ASPX file (RssToPL.aspx) along with whatever playlist format XSLT files you want to support. To keep this example simple, I just placed all the C# code into the single .ASPX file (no code behind). As long as your XSLT files (RssToAsx.xslt, etc.) are in the same directory as the .ASPX file, you should be set.

If you are utilizing this for your own personal use (like me), this can either be placed on your own personal web server (running on your local machine or elsewhere). If you are a content provider producing podcasts, this is a easy way to provide your users several different ways to access your content.


<%@ Page Language="C#" %>
<%@ OutputCache Duration="240" VaryByParam="*" %>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Linq"%>
<%@ Import Namespace="System.Xml.Linq"%>

<script language="C#" runat="server">

void Page_Load(object sender, EventArgs e)
    string sAsxFileName;
    string sRssUrl;
    //set the default xslt filename extension/type
    string sXslFileType = "ASX";
    //prepend the full path of the current directory
    string sXslFile = Path.GetDirectoryName(Request.PhysicalPath) +

    //if they provided the OutType QueryString param, lets use this transform file
    if (Request.QueryString["OutType"] != null)
        sXslFileType = Request.QueryString["OutType"];

    //format the xslt filename to use based on the out type
    sXslFile += String.Format("RssTo{0}.xslt", sXslFileType);

    //check to make sure they provided the RssUrl QueryString param
    if (Request.QueryString["RssUrl"] != null)
        sRssUrl = Request.QueryString["RssUrl"];

        //we'll try to use a formatted title of the feed for the asx filename
        sAsxFileName = FormatFileName(GetRssTitle(sRssUrl)) + "." + sXslFileType;
        throw new ApplicationException
	("No RSS Feed URL (RssUrl) QueryString parameter provided.");

    Response.Buffer = true;
    Response.ContentEncoding = Encoding.UTF8;

    //if they provided the "inline" QueryString param,
    //use it to determine how to send the asx file
    //inline sends the asx xml to the browser,
    //attachment prompts the user to download the file
    //attachment is the default
    if ((Request.QueryString["Inline"] != null) && 
	(Request.QueryString["Inline"].ToLower() == "true"))
    	//set Response.ContentType based on output method in xsl 
         //(this lets us switch between xml or text)
    	Response.ContentType = GetXslOutputMethod(sXslFile);
    	Response.AppendHeader("content-disposition", "inline;filename=" + sAsxFileName);
    	//we just use "text/x-unknown-content-type" 
         //because if we set to "text/plain" or "text/xml"
    	//some browsers sometimes change the file 
         //extension to .txt or .xml respectively.
    	Response.ContentType = "text/x-unknown-content-type";
			"attachment;filename=" + sAsxFileName);

    //send transformed xml
    Response.Write(TransformXML(sRssUrl, sXslFile));

/// <summary>
/// removed unwanted characters from filename
/// </summary>
/// <param name="fileName">unformatted filename</param>
/// <returns>formatted filename</returns>
private string FormatFileName(string fileName)
    string sReturn = fileName;
    sReturn = sReturn.Replace(" ", "");
    sReturn = sReturn.Replace(":", "");
    sReturn = sReturn.Replace("\\", "");
    sReturn = sReturn.Replace("/", "");
    sReturn = sReturn.Replace("@", "");
    sReturn = sReturn.Replace("$", "");
    sReturn = sReturn.Replace("+", "");
    sReturn = sReturn.Replace("%", "");
    sReturn = sReturn.Replace(">", "");
    sReturn = sReturn.Replace("<", "");
    sReturn = sReturn.Replace("?", "");
    sReturn = sReturn.Replace("\"", "");
    sReturn = sReturn.Replace("'", "");
    sReturn = sReturn.Replace(",", "");
    sReturn = sReturn.Replace("`", "");
    return sReturn;

/// <summary>
/// Transforms xml from url using an xslt file.
/// In this case, it will take a rss feed url and return the playlist file
/// </summary>
/// <param name="xmlUrl">rss feed url</param>
/// <param name="xslUrl">xslt filename</param>
/// <returns>asx xml</returns>
private string TransformXML(string xmlUrl, string xslUrl)
    MemoryStream ms = new MemoryStream();
    string sOutput;
        System.Xml.XPath.XPathDocument oXPath =
		new System.Xml.XPath.XPathDocument(xmlUrl);
        System.Xml.Xsl.XslTransform oXSLT = new System.Xml.Xsl.XslTransform();
        oXSLT.Transform(oXPath, null, ms);
        ms.Position = 0;
        StreamReader sr = new StreamReader(ms, Encoding.UTF8);
        sOutput = sr.ReadToEnd().ToString();
    catch (Exception ex)
        //Put in custom error handler here...
        sOutput = ex.ToString();

    return sOutput;

/// <summary>
/// Gets the title from an rss feed url
/// </summary>
/// <param name="xmlUrl">rss feed url</param>
/// <returns>return the title from an rss feed url</returns>
private string GetRssTitle(string xmlUrl)
    string sReturn;
        XDocument xmlDoc = XDocument.Load(xmlUrl);
        var qry = from r in xmlDoc.Descendants("channel")
        select (string)r.Element("title");
        sReturn = qry.First();
    catch (Exception)
        // there was a problem trying to get the title
        // we'll just use "rss"
        sReturn = "rss";

    return sReturn;

/// <summary>
/// Gets the output method (xsl:output method="xml" ...) from the given xsl file
/// </summary>
/// <param name="xslUrl">xsl url/filename</param>
/// <returns>returns "text/xml" or "text/plain"</returns>
private string GetXslOutputMethod(string xslUrl)
    string sReturn = "xml";  //default to xml

        XNamespace xsl = "";
        XDocument xmlDoc = XDocument.Load(xslUrl);

        var qry = from r in xmlDoc.Descendants(xsl + "stylesheet")
                  select r.Element(xsl + "output");

        XElement xslOutput = qry.First();
        if (xslOutput != null) { sReturn = xslOutput.Attribute("method").Value; }
    catch (Exception ex)
        // there was a problem trying to get the output method
        // we'll just use "xml"

    sReturn = sReturn == "text" ? "text/plain" : "text/xml";
    return sReturn;



<?xml version="1.0" encoding="utf-8"?>



    <!-- indicates what our output type is going to be -->
    <xsl:output method="xml" encoding="utf-8"

	indent="yes" omit-xml-declaration="yes" />

    <xsl:template match="rss/channel">
        <asx version="3.0">
                <xsl:value-of select="title"/>
                <xsl:value-of select="description" />
            <xsl:apply-templates select="item" />

    <xsl:template match="item">
        <xsl:variable name="item_enclosure" select="enclosure/@url"/>
            <xsl:if test="string-length(enclosure/@url) > 10">
                        <xsl:value-of select="title" />
                        <xsl:value-of select="author" />
                        <xsl:value-of select="description" />

                    <ref href="{$item_enclosure}"/>


This XSLT file will only return items with an enclosure, so you don’t have to worry about RSS feeds that mix in blog entries with the podcast.

To use this ASP.NET script, you just need to pass in the URL of the RSS feed and it will return the ASX file (as either inline XML or as a download). For example: http://[yourhost]/RssToPL.aspx?RssUrl= would return a playlist with the MSDN Channel 9 videos (in reverse chronological order).

To take this a step further, I also wanted to be able to have multiple podcasts show up in the same playlist. For example, I wanted both the ".NET Rocks" and "Hansel minutes" podcasts to show up interwoven together in one playlist, sorted by date (not all the ".NET Rocks" first and then all "Hansel minutes" last).

To do this, I decided to use Yahoo Pipes rather than write my own code. Yahoo Pipes is an awesome tool that basically lets you create custom RSS feeds (among other things) based off multiple sources and be able to manipulate them in many different ways. Yahoo Pipes does a lot more than that, but I won't get into it here. Also, if Yahoo Pipes seems a bit complicated for you, you could also use something like RSS Mix.

Using the Code

On the web server, place the RssToPL.aspx and RssToAsx.xslt into the same directory on your ASP.NET web server. The following table lists the QueryString parameters:

RssUrlThe URL of the podcast RSS feed.
Inline (optional)True or false. If set to true, the XML will show up in the browser window, otherwise the browser will prompt to download the ASX file.
OutType (optional)The output file type of the playlist to return (M3U, WPL, ZPL, WVX, SMIL, PLS, etc.) and define the XSLT file to use. If this parameter is left out, it will default to ASX.

On the client machine (the computer you are using to watch/listen to the podcasts), there are two ways I have effectively used this. One is just by creating a shortcut on your desktop (or some other folder) to the script URL. This way, if you double click the shortcut, it will open Internet Explorer then just prompt you to open the ASX file in Windows Media Player (or your default ASX player), then Internet Explorer automatically closes. I've found this works best with WMP, because it lists all the episodes in the "Now Playing" pane.

The other solution is just to create a hard coded ASX file on your computer that just has a reference to the script URL. For example, place either of the following entries in your ASX file:

<entry><ref href="http://[yourhost]/RssToPL.aspx?RssUrl=[RSSURL]" /></entry>


<entryref href="http://[yourhost]/RssToPL.aspx?RssUrl=[RSSURL]" />

I’ve found this solution works best if you are using Windows Media Center.


  1. I chose the ASX format as the default because I have worked with it before, but outputting to other formats, such as .M3U, .WPL, .ZPL (Zune), .WVX, .SMIL, .PLS, etc., for other players should be as easy as adding another XSLT template file and changing the OutType QueryString parameter. I've included ASX, M3U, WPL XSLT files in the example. Also, I believe ASX playlists will work with other players such as RealPlayer, Winamp, Media Player Classic, Windows Media Player Mobile, VLC, etc., but it isn't something I've extensively tested.
  2. For complex feed URLs (especially URLs with other QueryString parameters in them, you'll probably need to encode the URL (Server.URLEncode) for this script to work properly.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

William Grubbs
Team Leader Kendle
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralScript Observations [modified] Pin
ramjam5030-Jan-10 22:43
memberramjam5030-Jan-10 22:43 
GeneralRe: Script Observations Pin
William Grubbs1-Feb-10 18:29
memberWilliam Grubbs1-Feb-10 18:29 
Hi ramjam,

Below are my responses to your questions…

1. Yes, if you put Server.URLEncode inside of this script, it will not work. When I said use “Server.URLEncode”, I meant when you create the link to this script, you may have to encode the RSS URL using something like Server.URLEncode or a service like In most cases, you won’t need to encode the RSS URL, but I have noticed when the RSS URL contains ampersands (“&”), it can cause problems. Sorry, I wasn’t very clear about this.

2. Yes, I agree, adding a parameter to shuffle or sort by date ascending or descending would be nice. Maybe I’ll add this in the future.

3. I’ve only ran this script on a Windows 2003 server with just .Net 3.5 installed (without changing any configuration) and I haven’t had any problems, so I’m not sure why you are experiencing issues…?

4. That is what the “<%@ OutputCache Duration="240" VaryByParam="*" %>” at the top of the page is for. This essentially caches any RSS feed for 4 minutes. Arguably, you’ll want to increase this number to be a few hours. I could have done something in the code, but this works just as well.

5. Try setting the “Inline” querystring parameter to either “true” or “false”.

Thanks for your feedback!
- Bill
GeneralRe: Script Observations Pin
ramjam502-Feb-10 16:13
memberramjam502-Feb-10 16:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180318.3 | Last Updated 1 Oct 2009
Article Copyright 2009 by William Grubbs
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid