Jump to content

PAL Script Editing...


bbqcentral

Recommended Posts

I subscribed to the CBS News Feed from SpacialNet. It gives hourly updates but I wanted to see how I might go about customizing it a little more to my times.

 

I want it to check for a new update at :35 after every hour and then insert the new content in to my queue at :55.

 

Here is the PAL Script:

 

{==========[ Configuration options ]==========}

const secret_token = 'SVC74263-f302bd5978cf784c558ab32c69273c3f';

const workdir = 'c:\CBSFeeds\';

const feedID = '1';

{=============================================}

 

function RndStr:String; forward;

 

var url : string;

var infoFile : string;

var stateFile : string;

var mediaFile : string;

var stateCRC : string = '';

var newCRC : string = '';

var feedInfo : TStringList;

 

var LoopA : Boolean = true;

var LoopB : Boolean = true;

 

 

{## Initialization ##}

CreateDir(workdir);

 

 

{## Phase1: Check if new feed is available ##}

//Get CRC/Date of last downloaded file

stateFile := workdir+feedID+'_'+secret_token+'.crc';

infoFile := workdir+feedID+'_'+secret_token+'.info';

 

if FileExists(stateFile) then

begin

stateCRC := LoadStringFromFile(stateFile);

WriteLn('OldCRC: '+stateCRC);

end;

 

//Download new instruction file

//url := 'http://localhost/streamads_api/feed.txt?feedID=' + feedID + '&=' + secret_token;

url := 'http://feed.spacialnet.com/feeds/pal.instruction.php?feedID=' + feedID + '&token=' + secret_token;

WebToFile(infoFile, url);

 

//Wait 5 seconds for file to download

PAL.WaitForTime('+00:00:05');

 

{## Phase2: Download feed ##}

while LoopA and FileExists(infoFile) do

begin

feedInfo := TStringList.Create;

feedInfo.LoadFromFile(infoFile);

DeleteFile(infoFile);

 

WriteLn('Status:'+feedInfo.Values['status']);

newCRC := feedInfo.Values['date_updated'];

WriteLn('New CRC: '+newCRC);

while (newCRC'') and (newCRCstateCRC) do

begin

stateCRC := newCRC;

 

url := feedInfo.Values['download'];

mediaFile := feedInfo.Values['filename'];

WriteLn('File:'+mediaFile);

 

mediaFile := workdir + RndStr + '_' + ExtractFileName(mediaFile);

WebToFile(mediaFile, url);

 

//Wait for file to download

PAL.WaitForTime('+00:00:05');

while FileExists(mediaFile) and LoopB do

begin

//Store current State CRC

SaveStringToFile(stateFile, stateCRC);

 

{## Phase3: Schedule for playback ##}

Queue.AddFile(mediaFile, ipTop);

ExecSQL('UPDATE songlist SET songtype=:songtype, album=:album WHERE filename = :filename', ['N','CBS-FEED-'+feedID,mediaFile]);

CAT['Play once and erase'].AddFile(mediaFile, ipTop);

 

//Wait for feed to play

WriteLn('Waiting for feed item to play');

PAL.WaitForPlayCount(1);

 

//Wait 30min before we start checking again

WriteLn('Waiting to start new polling cycle');

PAL.WaitForTime('+00:30:00');

 

//Exit loop

LoopB := false;

end;

end;

 

//Exit loop

LoopA := false;

feedInfo.Free;

end;

 

{## Phase4: Rinse and Repeat ##}

PAL.Loop := true;

PAL.WaitForTime('+00:05:00');

 

function RndStr:String;

var Hour, Min, Sec, MSec: Integer;

begin

DecodeTime(Now, Hour, Min, Sec, MSec);

Result := IntToStr(Hour)+IntToStr(Min)+IntToStr(Sec);

end;

 

 

THANKS FOR YOUR HELP IN ADVANCE!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...