Note that this Wiki is a work in progress, items may not be updated or may disappear entirely as the pages are updated.
Podcasts in PAL
From SpacialAudio
When we were starting up our Shouting Fire [1] stream and very much wanted to be able to air podcasts that other people were already producing. Usually this involves syndicated content that they want us to fetch via an RSS fed podcast, with dynamic (changing) URLs for their current shows. I searched for a PAL script to do it and couldn't find one even vaguely close. So, I took today to figure out a solution. And did!
Basically, the problem is: we want to parse out the first episode of a podcast, fed by an RSS feed.
Now, there's good news, and bad news. I'll start with the good: here's a PAL script that starts with the URL for an RSS podcast feed and outputs the URL of the first (and only the first) episode of the feed. It does this ONLY with PAL; no external PHP or other standalone programs required!
Some details and a disclaimer: I'm not intimate with RSS structure or podcast/XML syntax. This script works by seeking the first instance of the tag "enclosure url=" and extracting the URL of the MP3 from within the following quotes. It ONLY gets the first listed episode (presumably the most recent). It only works for MP3s, and it doesn't have a lot of error handling if I've guessed wrong on all of this. But, it's worked reliably for the 3 podcasts we currently air weekly.
You'll need to change the three "???File_Local" constants at the top. The File_Remote constant is the link for the podcast; it's currently set for the Some Assembly Required radio show, which I highly recommend to you. [2]
{
PodcastPlayer -- Gets a podcast by parsing its XML file and
grabbing the first MP3 in it. Rewritten a bit after SF's
server crash. Run this early on the morning of the show's
air date. It will download the podcast file, then wait
until the show's air time to play it.
This script WILL NOT WORK unless you also create a Windows
Scheduled Task that runs a few minutes after this script starts.
The task should run this command:
wget -iDJNAME.url -ODJNAME.mp3
...where DJNAME is replaced by the DJName set below.
v1.1: Looks at the Wordpress blog file which seems to work just as
well if not better than the feedburner XML file. Also reads
the file as a single string, rather than a list.
- TradeMark G.
06/25/2008
}
// Configurables -- Change these to fit:
const File_Remote = 'http://some-assembly-required.net/blog/';
const DJName = 'SAR';
const LocalPath = 'D:\Shows Archive\' + DJName + '\';
var AirTime : DateTime = T['12:00:00'];
// End of configurables -- Don't change anything below here!
PAL.Loop := False; {Default value}
const XMLFile_Local = LocalPath + DJName + '.xml';
const WGETFile_Local = LocalPath + DJName + '.mp3';
const URLFile_Local = LocalPath + DJName + '.url';
var List : TStringList;
var TempStr,MP3File_Local : String;
var URLstart : Integer;
var URLend : Integer;
If FileExists(URLFile_Local) then
begin
DeleteFile(URLFile_Local);
end;
WebToFile(XMLFile_Local,File_Remote);
if FileExists(XMLFile_Local) then
TempStr := LoadStringFromFile(XMLFile_Local)
else
WriteLn(DJName + '.xml does not exist!: ');
URLStart := Pos('<enclosure url="',TempStr);
If URLstart > 0 then
begin
Delete(TempStr,1,URLstart+15);
URLEnd := Pos('"',TempStr);
If URLend > 0 then
begin
Delete(TempStr,URLend,9999999);
WriteLn('Extracted URL: ');
WriteLn(TempStr);
MP3File_Local := URLDecode(TempStr);
URLEnd := Pos('/',MP3File_Local);
repeat
Delete(MP3File_Local,1,URLEnd);
URLEnd := Pos('/',MP3File_Local);
until URLEnd = 0;
WriteLn('URL filename only: ');
WriteLn(MP3File_Local);
end;
end;
SaveStringToFile(URLFile_Local, TempStr);
PAL.WaitForTime(AirTime); {Wait to air the show}
If not FileExists(LocalPath + MP3File_Local) then
If FileExists(WGETFile_Local) then
RenameFile(WGETFile_Local, LocalPath + MP3File_Local)
else
WriteLn(WGETFile_Local + ' does not exist!: ')
else
WriteLn(MP3File_Local + ' already exists!: ');
CAT[DJName].AddFile(LocalPath + MP3File_Local, ipTop);
Queue.AddFile(LocalPath + MP3File_Local, ipTop);
ActivePlayer.FadeToNext;
And now, the bad news I promised above: From the "SaveStringToFile" line down, I was expecting to use something like this simple line of the script:
WebToFile(MP3File_Local,TempStr); // Get the current podcast
...but I encountered two problems: 1) podcast links from the popular podcast host libsyn.com often redirect to another URL, and SAM doesn't follow the redirect...dang! 2) Even if it doesn't, the WebToFile hangs SAM for us, presumably because it's busy grabbing this 40 meg file.
That means the solution will have to be outside of SAM, and since SAM won't allow PAL to execute or shell an external program, we have to get slightly tricky.
Windows Scheduled Tasks can help us here. Presumably we're doing this at about the same time weekly, so we can coordinate the scheduled PAL run with a Windows Scheduled Task (look under the Control Panel) scheduled for a time soon after. The task is pretty easy if you get the WGET utility ( Google "Windows WGET"). Just schedule this command:
wget -iFILENAME_IN_URLFile_Local -OFILENAME_IN_MP3File_Local
...where FILENAME_IN_URLFile_Local and FILENAME_IN_MP3File_Local have been replaced by the filename you put into the respective constants. The PAL script above ends with code that creates the file WGET will look for.
Finally, the timing: you'll need to make sure everything above runs with enough time to download the complete podcast for your airing of it. The PAL script will delay until the broadcast time and queue up the program that WGET downloaded earlier.
That's it! Good luck all,
- TradeMark G.
- .e.c.c.: / BMIR / Shouting Fire
