Ever Wanted to Create a PodCast with Coldfusion. Here we will discuss the same technique of fetching the Podcast with Coldfusion. It works with Coldfusion 7 & above. The Technique uses the XML Tags of Coldfusion and all is shown in simple Lines. Here is the details how we can work with.

I have not used any database with it. I am just fetching the URL of the Feed using the cfhttp Tag:

Here is the working Example how we can do it:

<cfhttp url="#urlfeed#" method="GET" timeout="60"></cfhttp>

Now the URLFeed  can be like say:

http://www.doctorfloyd.com/blog/rss.xml

Now it is very simple. We just need to see what values are returned by the feed. The podcast feed mainly returns the ITunes related values and other some common values which are used by other feeds like RSS feeds, Atom Feeds.

So let's Start Building the Feed. I have wrapped the Whole bunch of Code around the <cftry>, <cfcatch> block so as to see if any error occurs it will automatically be handled by the catch block. So here is the listing what we have which will provide us the feed details of a PodCast.

 <cfsetting requesttimeout="15000">

I have set the Page timeout to be bigger as it sometimes take much time to fetch the relevant records, so you can try any time or can certainly remove the Tag.

<cftry>

<cfhttp url="#urlfeed#" method="GET" timeout="60">

The Timeout value is set to 60. if the Page did not succeed in getting the URL in the timeframe it will timeout, you can set it to 120, 180 whatever you would like to

</cfhttp>

<cfscript>

XMLContent = XMLParse(trim(cfhttp.filecontent));

Now here are fetching the contents of the http and parsing them using the XMLParse

XMLRoot = XMLContent.rss.channel;

arrItems = XMLRoot.item;

</cfscript>

<table align="left" width="550">

  <tr><td>

    <table align="left">

      <cfoutput>

        <tr>

          <td><strong>#XMLRoot.title.xmlText#</strong></td>

        </tr>

        <tr>

          <td><strong>#XMLRoot.description.xmlText#</strong></td>

        </tr>

      </cfoutput>

      <cfloop from="1" to="#ArrayLen(arrItems)#" index="idx">

        <cfif arrItems[idx].title.xmlText neq 'Presented By:'>

          <tr>

            <td><hr style="border:1px solid #fc9d03;" width="100%"></td>

          </tr>

          <cfoutput>

            <tr>

              <td class="backyard"><a href="#arrItems[idx].link.xmlText#" target="_blank">#arrItems[idx].title.xmlText#</a></td>

            </tr>

            <tr>

              <td>#ParagraphFormat(arrItems[idx].description.xmlText)#</td>

            </tr>

            <cfif structkeyexists(arrItems[idx], 'language')>

              <tr>

                <td><strong>Language:</strong> #arrItems[idx].language.xmltext#</td>

              </tr>

            </cfif>

            <cfif structkeyexists(arrItems[idx], 'category')>

              <tr>

                <td><strong>Category:</strong> #arrItems[idx].category.xmltext#</td>

              </tr>

            </cfif>

            <cfif structkeyexists(arrItems[idx], 'enclosure')>

                                <tr><td><strong>File:</strong> <a href="#arrItems[idx].enclosure.xmlattributes.url#" target="_blank">Get File</a>

                  <br />

                <strong>Type: </strong>(#arrItems[idx].enclosure.xmlattributes.type#)<br />

                <strong>Length:</strong> (#arrItems[idx].enclosure.xmlattributes.length#) bytes</td></tr>

                </cfif>

The above coloured Shows that it has a file related to it. i have just incuded the link, you can also provide the embed tag if you want to run the file from your own page like you can use the quicktime movie tag: in place of the link.

            <cfif structkeyexists(arrItems[idx], 'itunes:keywords')>

              <tr>

                <td><strong>Keywords:</strong> #arrItems[idx].keywords.xmltext#</td>

              </tr>

            </cfif>

            <cfif structkeyexists(arrItems[idx], 'pubDate')>

              <tr>

                <td><strong>Date:</strong> #arrItems[idx].pubDate.xmlText#</td>

              </tr>

            </cfif>

          </cfoutput>

        </cfif>

      </cfloop>

      <cfif structkeyexists(XMLRoot, 'copyright')>

        <tr>

          <td><hr style="border:1px solid #fc9d03;" width="100%"></td>

        </tr>

        <cfoutput>

          <tr>

            <td><div align="center">#XMLRoot.copyright.xmlText#</div></td>

          </tr>

        </cfoutput>

      </cfif>

    </table>

    </td>

  </tr>

</table>

<cfcatch>

<div style="padding-left:20px;">

<h1>Error Fetching Feed</h1>

<hr style="border:1px solid #fc9d03;" width="100%">

<p>THIS IS NOT A FEED ERROR.  This is caused by poorly formed XML.</P>

<b>Error Description:</b>

<br>

</div>

<cfoutput>

<div style="padding-left:20px;">

<i>#cfcatch.Detail# #cfcatch.Message#</i>

</div>

</cfoutput>

</cfcatch>

</cftry>

I have used the StructKeyExists Function everywhere just to make sure that if any value id not in XML it should skip that content and go and fetch the nect one. this way it does not displays errors. If the feed is improperly formattted, it will show errors in the last cftry catch block

This is all. We will have a working Podcast if the Podcast has some invalid XML or Errors, it will simply Display us the Error.

Cheers

 

About This Tutorial
Author: Gurpreet Singh Randhawa
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX,CF8,CF9,BlueDragon,Railo
Total Views: 72,113
Submission Date: October 22, 2009
Last Update Date: October 22, 2009
All Tutorials By This Autor: 9
Discuss This Tutorial
Advertisement

Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.