Hey guys,
I've just started getting into podcasting and wanted an easy way to
upload my mp3 files and have a script put in the information.
Naturally, I found a
PHP script but nothing in ASP. Then I found
this script
that uses Stream Object, which helped me out tremendously, but the
problem is that it reads IDv1.x tags. While that is not a huge deal, it
would be even better if someone knew how to read IDv2.x tags. Any ideas?
I'm about to start building a site at
www.podcastgeek.com,
although my mp3's will be hosted under rexpage.com (more bandwidth).
You can see my script in action (which is also the podcast feed for my
tech podcasts) at:
http://www.rexpage.com/podcasts/tech
Also, here is the code for the podcast script. Any updates will be
found on my forum at www.rexpage.com/forum and I'll have information at
www.podcastgeek.com once it is live.
Zip file for Code
[code]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library"
-->
<%
'#####################
'This code is released freely for use
'by the podcasting community. Parts of
'the code are from other sources as credited.
'Please check out my podcast site at www.podcastgeek.com
'and make a donation if this script helps you out.
'
'xxxIMPORTANTxxxxx
'This script will support ID3v1.x and ID3v2.x tags but
'the positions are not correct from several in ID3v2.x format
'
'If you know how to use Stream Object to read
'ID3v2 tags then let me know.
'
'xxxNOTICE ABOUT AUDIOSHELL 1.0xxx
'For some reason, if you use AudioShell 1.0 under Windows
'to edit your ID3 tags, this script will not read them.
'I recommend that you use iTunes or the tags generated from
'Audacity.
'
'Apple's iTunes works fine using ID3v1.x and ID3v2.x
'
'xxxHOW TO USE THIS SCRIPTxxx
'FTP this script in the same folder as your mp3 files.
'It should automatically find the files and create the
'RSS feed.
'
'You can modify this script to find other audio formats
'such as oog vorbis, etc. To do this edit the If Then statement
'or replace it with a Select Case in the appropriate lines.
'
'EDITABLE Information - BEGIN
'#####################
'Specify the folder to look through, displaying all the MP3s
folder = Server.MapPath(".") 'This is the easy way to map to this folder
'folder = "c:\yourwebfolder\yourmp3folder" 'Uncomment this one if you like the physical path
'Set the RSS Feed Information
strTitle = "PodcastGeek.com Tech Podcast Feed"
strWebsiteURL = "http://www.podcastgeek.com"
strFeedURL =
"http://www.rexpage.com/podcasts/tech" 'Do not put a
trailing / here
strDescription = "Rex's Podcasts"
strGenerator = "PodcastGeek.com Podcasting ASP Script"
'#####################
'END OF EDITABLE (unless you know what you are doing)
'#####################
'Lets set the date of the publication
strDate = fncFmtDate(Now(), "%a, %d %b %Y %H:%N:%S CST")
'Start RSS
'The RSS syntax is VERY precise so be careful!
Response.ContentType = "text/xml"
Response.Write("<rss
version=""2.0"">") 'If you get any XML errors then
comment out this line
Response.Write("<channel>")
Response.Write("<title>"& strTitle &"</title>")
Response.Write("<link>"& strWebsiteURL &"</link>")
Response.Write("<description>"& strDescription &"</description>")
Response.Write("<language>en-us</language>")
Response.Write("<copyright>Copyright 2004
"& strTitle &" - All Rights Reserved.</copyright>")
Response.Write("<generator>"& strGenerator &"</generator>")
Response.Write("<pubDate>"& strDate &"</pubDate>")
Response.Write("<ttl>60</ttl>")
'##############################
'Start of reading mp3 ID tags
'Credit: http://www.4guysfromrolla.com/webtech/tips/t041701-1.shtml
'##############################
Function ConvertBin(Binary)
'This function converts a binary byte into an ASCII byte.
for i = 1 to LenB(Binary)
strChar = chr(AscB(MidB(Binary,i,1)))
ConvertBin = ConvertBin & strChar
Next
End Function
dim objStream
dim strTag, strSongName, strArtist, strAlbum, strYear, _
strComment, strGenre, strFile
'Grab the folder information
'For more information on this technique below, check out this FAQ:
' http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=90
Dim objFSO, objFolder, objFile
Set objFSO = Server.CreateObject("Scripting.FileSYstemObject")
Set objFolder = objFSO.GetFolder(folder)
'Create the Stream object
set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
'Loop through the files in the folder
For Each objFile in objFolder.Files
'Get the file extension for each object
Extension = objFSO.GetExtensionName(objFile)
'Loop only through the mp3 files and get the tag information
If Extension = "mp3" Then
'Open the stream
objStream.Open
objStream.LoadFromFile objFile.Path
'Read the last 128 bytes
objStream.Position = objStream.size - 128
'Read the ID3 v1 tag info
strTag = ConvertBin(objStream.Read(3))
if ucase(strTag) = "TAG" then
strSongName = ApplyXMLFormatting(ConvertBin(objStream.Read(30)))
strArtist = ApplyXMLFormatting(ConvertBin(objStream.Read(30)))
strAlbum = ApplyXMLFormatting(ConvertBin(objStream.Read(30)))
strYear = ApplyXMLFormatting(ConvertBin(objStream.Read(4)))
strComment = ApplyXMLFormatting(ConvertBin(objStream.Read(30)))
end if
'Create the enclosure URL for the audio file
strEncl