Exclude specially tagged items from publishing in 'now playing' script

Hi there.

With the script I have below (Written originally by Charlie Davy and the string replace function scripted by Cad), it works great for sweepers etc being excluded from publishing to a file of now playing information based on that anything less than 90 seconds is excluded.

But…a problem arises when playing the beds for the news! they are longer than 90 seconds. So if these were tagged in some way (also I need to know how I would go about that), is there script that could be used to exclude these tagged items from being logged/published, in a similar way to the current way of basing an item by it’s length?

[code]// StringReplace
// Written by Cad Delworth CEng MBCS CITP
// (Clearances Manager, Leith FM, Edinburgh, Scotland)

// A mAirList script function which replaces characters in a string.

// Copy the function below into any script which requires a string replace function.

function Replace(sSource: string; sFind: string; sReplace: string): String;

var
iLenFind, iPos: integer;
sString, sOutput: string;

begin

// Store the length of the ‘find’ string
iLenFind := Length(sFind);

// The default output string is the input string
// (in case no matches are present)
sString := sSource;

// Now search repeatedly for sFind until it isn’t there any more
repeat

// Are there any 'find' strings in sString?
iPos := Pos(sFind, sString);

if iPos > 0 then
begin

  // Yes, form a 'replaced' string by string slicing
  sOutput := Copy(sString, 1, iPos - 1) + sReplace;
  sOutput := sOutput + Copy(sString, iPos + Length(sFind), Length(sString) - iPos + Length(sFind));

  // Now copy sOutput back into sString for the next loop
  sString := sOutput;
end;

until iPos = 0;

// We’re finished, return the output string
Result := sString;

end;

// Intelligent Now Playing Script v2
// by Charlie Davy
// last modified 16th January 2009

// This script examines each audio item played via a Player and performs a task based upon the track’s length.
// The 3 settings below work for most situations, however you can fine-tune them if you wish.

// The last.fm links work for most artist/groups - it adds a nice touch, I think.

// Update: The OnAir switch is considered within this script, if you are “Off Air”, this script does nothing.
// If you are “On Air”, the script runs as normal. Useful in a multi-studio environment where pre-recorded
// shows may interfer with your live “now playing” display!

// IMPORTANT!! You MUST rename this file to .mls when adding it to mAirListConfig

const
IDENT = 900000000; // 90 seconds
MUSIC = 900000000; // 90 seconds
PRE_REC = 4200000000; // 7 minute

procedure OnPlayerStart(PlayerControl: IPlayerControl; Item: IPlaylistItem);
var sl: TStringList;

begin
if Engine.GetOnAir = False then begin
SystemLog(‘mAirList is in production mode, so no action taken…’);
sl := TStringList.Create;
sl.Add(‘LiveWire Radio’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;

// If the track is over 7 minutes, assume it’s a pre-recorded programme

end else if (Item.GetDuration > PRE_REC) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘This item is a pre-record or longer than 7 minutes…’);

// If the track is more than 90 seconds, assume it’s a song

end else if (Item.GetDuration > MUSIC) then begin

sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘ob_start();’);
sl.Add(‘echo rawurldecode("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=’ + Item.GetArtist + ‘&api_key=097a7ab0f5b56a894eb7a25e1c51b0da");’, ‘’’’, ‘%27’));
sl.Add(’$url = ob_get_clean();’);
sl.Add(‘if (!$xmlObj = simplexml_load_file($url)) {’);
sl.Add(‘echo “Error reading XML file”;}’);
sl.Add(‘foreach($xmlObj as $artist) {’);
sl.Add(‘ob_start();’);
sl.Add(‘echo $artist->name;’);
sl.Add(’$name = ob_get_clean();’);
sl.Add(‘ob_start();’);
sl.Add(‘echo $artist->image[2];’);
sl.Add(’$image = ob_get_clean();’);
sl.Add(‘ob_start();’);
sl.Add(‘echo $artist->bio->summary;’);
sl.Add(’$bio = ob_get_clean();’);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\artist.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’<?php’);
sl.Add(‘ob_start();’);
sl.Add(‘echo rawurldecode("http://ws.audioscrobbler.com/2.0/?method=track.getinfo&artist=’ + Item.GetArtist + ‘&track=’ + Item.GetTitle + ‘&api_key=097a7ab0f5b56a894eb7a25e1c51b0da");’, ‘’’’, ‘%27’));
sl.Add(’$url = ob_get_clean();’);
sl.Add(‘if (!$xmlObj = simplexml_load_file($url)) { ‘);
sl.Add(‘echo “Error reading XML file”;}’);
sl.Add(‘foreach($xmlObj as $track){’);
sl.Add(‘ob_start();’);
sl.Add(‘echo $track->name;’);
sl.Add(’$trackname = ob_get_clean();’);
sl.Add(‘ob_start();’);
sl.Add(‘echo $track->wiki->content;’);
sl.Add(’$trackwiki = ob_get_clean();’);
sl.Add(’}’);
sl.Add(’?>’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\track.php’);
sl.Free;

sl := TStringList.Create;
sl.Add(’’ + Item.GetArtist + ’ - ’ + Item.GetTitle + ‘’);
sl.SaveToFile(‘C:\Users\Ryan\Documents_RADIO\site\nowplaying\nowplaying.php’);
sl.Free;
SystemLog('Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle);

end;
end;
begin
end.[/code]

Cheers, Ryan.

Assuming your News Bed titles are consistent, you could easily change the condition:

if (Item.GetDuration > MUSIC)

to something which tests the TITLE as well. For example:

if ((Item.GetDuration > MUSIC) and (Item.GetTitle <> ‘NewsBed’))

Does that help?

BFN
CAD

Well the news beds are similar length to songs…about 3 mins. Also, they are called two different names, as there are two news beds, used one after another (the beds are changed after the first news story). They are called: ‘NEWS_BED_01’ and ‘NEWS_BED_02’.

I suppose it may be possible to implement:

if (Item.GetTitle <> ‘NEWS_BED_01’)

As well as another separate ‘if’ function for NEWS_BED_02.

Could you reply just to let me know if that would work?

Cheers Cad, Ryan.

EDIT- Also, is it possible to have these if functions at the start of the script and therefore everything would run through this first, hence the news beds would not get caught in the MUSIC function?

I’ve added the following to the script-

end else if ((Item.GetDuration > MUSIC) and (Item.GetTitle <> ‘01_NEWS_BED_01’)) then begin
sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\Users\Ryan\Documents\nowplaying\nowplaying.php’);
sl.Free;
SystemLog(‘Now Playing: News’);

BUT, every song is now being caught in this section (i can tell through the system log showing ‘Now Playing: News’). I have put this section of script BEFORE the main ‘MUSIC’ section.

I’m stumped how everything thinks it is a news bed! :wink:

Cheers. Ryan.

EDIT- All sorted and working beautifully. Turns out the <> needed to be replaced with =. As the <> was acting as an ‘if it does not equal’. I was thinking the opposite way round to how you would have gone about it (plus it was late and i wasn’t reading properly ;))! Cheers for the help Cad!

No worries: glad to help!

BFN
CAD