I recently found it necessary to add dedication info to some client's stream, so I've come up with yet another version of Xgeek's script. This one also tries to address the »control character/linefeed« problem and the damn shoutCAST »password shown« bug that they didn't fix since shoutCAST v1.9.2 …

Here goes, just in case anyone might need it:
Code:
// Requests on Stream.pal
// 2008-11-12 v1.0 Moonbase
// based on Xgeek's "Inject Request Dedication.pal" v0.05, 2004-11-12
PAL.LockExecution;
PAL.Loop := True;
// Instantiate a Song Info object
var Song: TSongInfo = TSongInfo.Create;
var dedicationText: String = '';
// Check if current song is a request
if ((ActivePlayer.GetSongInfo['requestID']) > 0) then
begin
var reqInfo: TDataSet = Query('SELECT name, msg FROM requestlist WHERE id = ' + ActivePlayer.GetSongInfo['requestID'], [], true);
var requestBy: String = reqInfo['name'];
var dedicationMsg : String = reqInfo['msg'];
reqInfo.Free;
var i: Integer;
var c: String;
var addStr, newTitle: String;
// clean up unwanted characters (i.e., line feeds, control characters; leave only ISO-8859-1)
for i := 1 to Length(dedicationMsg) do
begin
c := CharAt(dedicationMsg, i);
if (((CompareStr(c, ' ') >= 0) and (CompareStr(c, '~') <= 0)) or ((CompareStr(c, ' ') >= 0) and (CompareStr(c, 'ÿ') <= 0))) then
dedicationText := dedicationText + c;
end;
// build addistional info string
addStr := ' [Request';
if (requestBy > '') then
begin
// we have requester's name
addStr := addStr + ' von ' + requestBy;
if (dedicationText > '') then
// we also have a dedication
addStr := addStr + ': "' + dedicationText + '"';
addStr := addStr + ']';
end
else
// requester didn't give his name, we won't show anonymous dedications
addStr := addStr + ']';
writeln(addStr);
Song['artist'] := ActivePlayer.GetSongInfo['artist'];
newTitle := ActivePlayer.GetSongInfo['title'] + addStr;
// force maximum length of 150 characters
// (shoutCAST server shows password since v1.9.2 if > 150 characters!)
if (Length(Song['artist'] + ' - ' + newTitle) > 150) then
newTitle := Copy(ActivePlayer.GetSongInfo['title'] + addStr, 1, 146 - Length(Song['artist'])) + '...]';
Song['title'] := newTitle;
Encoders.SongChange(Song);
writeln(Song['artist'] + ' - ' + Song['title']);
end;
PAL.UnlockExecution;
// Release data structures
Song.Free;
// Wait for next song to come up
PAL.WaitForPlayCount(1);
Just in case anyone needs to
type this: The
second character that
looks like a blank in
Code:
or ((CompareStr(c, ' ') >= 0)
above is
not a blank but a
typed-in ALT+0160! (ISO-8859-1 readable characters are #32..#127 and #160..#255.)
N.B.: The length calculation in the code is a) only needed on shoutCAST servers from v1.9.2 up (icecast seem to work correctly), and b) of course only valid if you have set
title streaming in SAM to either
$combine$ or
$artist$ - $title$. Any adjustments should be a snap, though.