TIP : Intelligent Now Playing Script

Here’s a scipt that I currently run. Essentially, it is used to update your SHOUTcast server and nowplaying.php file with details of the current song. However, if you are playing adverts/jingles or longer pre-recorded elements - You probably won’t want these made public, so the script sends alternative text.

EDIT: Code updated… See further down for the update!

This script is added in mAirListConfig as a Notification Script.

Should we move this thread to the new Scripts area perhaps?

Agreed: I think it’s a script forum job. :slight_smile:

Is it just me, or are there lots of redundant begin and end statements in that script? :o I have to say, I much prefer properly indented code because it makes excess snd unmatched statements much easier to spot!

A good free multi-language-highlighting editor (my favourite) is PSPad, which has a built-in, integrated FTP client as well! Just add mls to the internal PSPad list of file types for Object Pascal and away you go! :wink:

BFN
CAD

I have updated this script - it now works as it should, and includes Cad’s favourite: Constants :wink: I particular like the Last.FM link as it enables listeners to click the now playing info and be taken to that particular artist’s profile page. This works for about 99% of tracks, depends what you store in the Artist field.

Script is commented, hopefully it’s quite straight-forward.

[code]// Intelligent Now Playing Script
// by Charlie Davy

// 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.

// If you regularly play music beds from Players, the titles will be published. Same goes for news jingles.
// At some point, I’ll work in a .GetArtist IF line to check for BED/ID/JINGLE etc in the Artist field.

// The last.fm links work for most artist/groups - I find it really useful!

const
IDENT = 900000000; // 90 seconds
MUSIC = 900000000; // 90 seconds
PRE_REC = 3600000000; // 6 minutes

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

begin

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

if (Item.GetDuration > PRE_REC) then begin

sl := TStringList.Create;
sl.Add(‘See our website for live now playing info…’);
sl.SaveToFile(‘S:\nowplaying\nowplaying.php’); // PHP File for now-playing on website
sl.SaveToFile(‘S:\RDS RT.txt’); // RDS radio text source
sl.Free;
HTTPGetAsync(‘http://server:8000/admin.cgi?pass=changeme&mode=updinfo&song=See our website for live now playing info…’);
SystemLog(‘Pre-Recorded or song too long! See our website for live now playing info…’);

// 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(’’ + Item.GetArtist + ’ - ’ + Item.GetTitle + ‘’);
sl.SaveToFile(‘S:\nowplaying\nowplaying.php’); // PHP File for now-playing on website
sl.SaveToFile(‘S:\RDS RT.txt’); // RDS radio text source
sl.Free;
HTTPGetAsync(‘http://server:8000/admin.cgi?pass=changeme&mode=updinfo&song=’ + Item.GetArtist + ’ - ’ + Item.GetTitle);
SystemLog('Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle);

// If the track is under 90 seconds, assume it’s an advert or jingle

end else if (Item.GetDuration < IDENT) then begin

sl := TStringList.Create;
sl.Add(‘More music soon…’);
sl.SaveToFile(‘S:\nowplaying\nowplaying.php’); // PHP File for now-playing on website
sl.SaveToFile(‘S:\RDS RT.txt’); // RDS radio text source
sl.Free;
HTTPGetAsync(‘http://server:8000/admin.cgi?pass=changeme&mode=updinfo&song=More music soon…’);
SystemLog(‘More music soon… Playing Adverts and Jingles’);

end;
end;
begin
end.[/code]

IMPORTANT: You will need the latest snapshot build for the HTTPGetAsync to work. You can specify more than 1 SHOUTcast server using this method. Revert to the old HTTPGet if you’re using an older EXE.
Have fun!

Hee hee! :smiley:

Trust me, Charlie: the bigger the program, the more important it is to use manifest constants (as they are known)! It’s all too easy to type ‘magic numbers’ into a program and then have a Big Hunt some weeks later to find out where the heck they are (been there, done that, got the T-shirt). Even more fun is when what was supposed to be the same ‘magic number’ is typed in two or more places in the code, but at least one value is different (AAArgh!).

Putting all ‘magic numbers’ (and anything else that you or the user might want to change later) at the top of the code, and giving them all sensible names, saves everyone a lot of pain. It’s also best programming practice.

PS: I now have IVP-3.0 almost ready to go—it now ‘underlays’ songs as discussed, and there’s a companion script to simplify voicetrack setup even further (he said mysteriously). Hope to post it later.

BFN
CAD

I wouldn’t mind having a helping-hand regarding the pioNoLogging option - I’d like to bulk-change a load of jingles that should be “Excluded from Logging”…

It’s the same principle as playlist items, because it uses a set.

Here you go, hopefully you can see how easily you could change this.
WARNING! the script below saves MMD files!

[code]// SetNoLogging - Script to set ‘no logging’ attribute on ALL items in current Playlist.
// Written by Cad Delworth, Leith FM, Edinburgh, Scotland
// http://www.leithfm.co.uk

// Change the appropriate CONSTs below if you wish to change how this script works.
// It’s a good idea to add comments here if you do this.
// NOTE: DO NOT remove ANY of the CONSTs! The script will stop working if you do.
const
// Name of script, used as a prefix to all SystemLog messages (default: 'IVP-MarkEndings script: ')
// If you change this, keep a colon and space as the last two characters.
SCRIPTNAME = 'SetNoLogging: ‘;
var
i, iItemCount, iMax: integer;
sMessage, sPlaylist: string;
currentItem: IPlaylistItem;
procedure SetNoLogging(playlistItem: IPlaylistItem);
var
piOptions: TPlaylistItemOptions;
begin
piOptions := playlistItem.GetOptions;
piOptions := piOptions + [pioNoLogging];
playlistItem.SetOptions(piOptions);
// Remove the line below if you DON’T want to save the MMD
playlistItem.SaveMMD;
end;
procedure ProcessCurrentPlaylist;
begin
iMax := iItemCount - 1;
SystemLog(SCRIPTNAME
+ ‘Setting NO LOGGING option on items in Playlist ’
+ sPlaylist
+ ’ (’
+ IntToStr(iItemCount)
+ ’ items).’);
for i := 0 to iMax do
begin
currentItem := CurrentPlaylist.GetItem(i);
SetNoLogging(currentItem);
end; // of for… loop
sMessage := SCRIPTNAME
+ 'Playlist ’
+ sPlaylist
+ ': ';
if iItemCount = 1 then
sMessage := sMessage + '1 item ’
else
sMessage := sMessage + IntToStr(iItemCount) + ’ items ';
sMessage := sMessage
+ ‘changed to NO LOGGING.’;
SystemLog(sMessage);
end;
// MAIN CODE STARTS BELOW
begin
sPlaylist := IntToStr(CurrentPlaybackControl.GetIndex + 1);
iItemCount := CurrentPlaylist.GetCount;
if CurrentPlaybackControl.GetAutomation = true then
SystemLog(SCRIPTNAME + ‘Please put Playlist ’ + sPlaylist + ’ into ASSIST mode, then try again.’)
else
ProcessCurrentPlaylist;
end.
[/code]

BFN
CAD

Excellent - thanks for that, it works perfectly.

EDIT: New version posted… See below.

You’re very welcome!

And of COURSE it works perfectly: I test all my scripts before I post them here! :wink:

BFN
CAD

Looks great.

Sorry to be fussy, but what do you think about a news bed which would probably be around 4-5 mins long hmmm :\

Thanks.

Not a problem - in the Item Properties window, simply tick the box “Exclude from Logging” and my script will ignore it - no matter what the length. See the Scripts section for Cad’s bulk “no logging” script :slight_smile:

The script only allows loggable items through the routine - then, based upon 3 length rules, it does something (or not, if you comment them out).

Yeah: what Charlie said!
(The penny finally dropped about why Charlie wanted to tag tracks as ‘exclude from logging!’)

BFN
CAD

This update includes a check of mAirList’s “OnAir status” - useful for when you’re pre-recording shows or do not want details to be uploaded.

[code]// 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 minutes

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…’);

// Let’s ignore any track that has the “Exclude from Logging” option enabled

end else if (pioNoLogging in Item.GetOptions) then begin

sl := TStringList.Create;
sl.Add(‘Sorry, no details available for this item…’);
sl.SaveToFile(‘C:\nowplaying.php’);
sl.Free;
HTTPGetAsync(‘http://server:port/admin.cgi?pass=password&mode=updinfo&song=See our website for information’);
SystemLog(‘This item will not be logged…’);

// 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(‘Sorry, no details available for this item…’);
sl.SaveToFile(‘C:\nowplaying.php’);
sl.Free;
HTTPGetAsync(‘http://server:port/admin.cgi?pass=password&mode=updinfo&song=See our website for information’);
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(’’ + Item.GetArtist + ’ - ’ + Item.GetTitle);
sl.SaveToFile(‘C:\nowplaying.php’);
sl.Free;
HTTPGetAsync(‘http://server:port/admin.cgi?pass=password&mode=updinfo&song=’ + Item.GetArtist + ’ - ’ + Item.GetTitle);
SystemLog('Now Playing… ’ + Item.GetArtist + ’ - ’ + Item.GetTitle);

// If the track is under 90 seconds, assume it’s an advert or jingle
// You may wish to comment this section out as sending this info for such a short time may seem pointless!

end else if (Item.GetDuration < IDENT) then begin

sl := TStringList.Create;
sl.Add(‘More music soon’);
sl.SaveToFile(‘C:\nowplaying.php’);
sl.Free;
HTTPGetAsync(‘http://server:port/admin.cgi?pass=password&mode=updinfo&song=More Music Soon’);
SystemLog(‘Playing Adverts or Jingles…’);

end;
end;
begin
end.[/code]