Try this script:
var
i, iItemCount, iMax, iVol, iToth: integer;
i64Duration: TTimeValue;
sArtist : string;
sMessage, sPlaylist, sTitle : string;
currentItem, ItemHook, ItemHook2: IPlaylistItem;
ads: IContainerPlaylistItem;
adsPlaylist, newPlaylist: IPlaylist;
adsContainerAsPlaylistItem, piNews: IPlaylistItem;
sFileName, sOpener, sCloser, sMiddle: string;
i64HookIn, i64HookFade, i64HookOut: TTimeValue;
const SONG_MIN_LENGTH = 900000000;
procedure startMarkup;
begin
for i := 0 to Playlist(0).GetCount -1 do
begin
if Playlist(0).GetItem(i).GetTitle = 'Top of the hour' then begin
iToth := i;
SystemLog(Playlist(0).GetItem(i).GetTitle);
break;
end;
end;
end;
procedure MarkupCurrentPlaylist;
begin
// Set values (REPLACE THESE WITH YOUR OWN)
sOpener := 'M:\Jingle\NFM\NFM Selected with Passion Mixdown 1.mp3';
sMiddle := 'M:\Jingle\Soundeffect\BBC Bleep 2.mp3';
sCloser := 'M:\Jingle\NFM\NFM 2014 Jingles 4a.mp3';
// Reset counters etc.
iMax := iItemCount - 1;
iVol := 0;
// Display our start up message
SystemLog('Hook: '
+ 'Checking the playlist, looking for songs with Hooks.');
ads.GetPlaylist.InsertFile(0, sOpener, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);
// Step through each item in the current (selected) Playlist
for i := iToth + 2 to Playlist(0).GetCount -1 do
begin
// Create a local reference to the current item
// This makes all subsequent code easier to read and slightly faster to process
currentItem := Playlist(0).GetItem(i);
// Store the current item's Artist, Title, and Effective Duration
sArtist := currentItem.GetArtist;
sTitle := currentItem.GetTitle;
i64Duration := currentItem.GetDuration;
// Is this a song?
if currentItem.IsCueable then
begin
// Add the song to the container and set it to a hook.
ItemHook := iPlaylistItem(currentItem.Clone);
i64HookIn := ItemHook.GetCuePosition(ptHookIn);
i64HookFade := ItemHook.GetCuePosition(ptHookFade);
i64HookOut := ItemHook.GetCuePosition(ptHookOut);
if (i64HookIn > 0) then
begin
// SystemLog('Added');
ads.GetPlaylist.Add(ItemHook);
if (iVol < 2) then
begin
ads.GetPlaylist.InsertFile(ads.GetPlaylist.GetCount, sMiddle, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);
end;
ItemHook.SetCuePosition(ptCueIn, i64HookIn);
ItemHook.SetCuePosition(ptFadeOut, i64HookFade);
ItemHook.SetCuePosition(ptStartNext, i64HookFade);
ItemHook.SetCuePosition(ptCueOut, i64HookOut);
ItemHook.SetArtist('Coming up: '+ currentItem.GetArtist);
iVol := iVol + 1
end;
if (iVol = 3) then
begin
break;
end;
SystemLog('Hook: ' + 'Item '
+ IntToStr(i + 1)
+ ' ('
+ Trim(currentItem.GetTitle)
+ ' / '
+ Trim(currentItem.GetArtist)
+ ') '
+ '.');
end
end; // of for... loop
// All Playlist items processed, inform user
if (ivol < 3) then
begin
ads.GetPlaylist.Delete(ads.GetPlaylist.GetCount -1);
end;
ads.GetPlaylist.InsertFile(ads.GetPlaylist.GetCount, sCloser, [fitMMD, fitTags, fitNativeTags, fitDuration, fitTilde, fitAutoCue, fitDatabaseLookup]);
SystemLog('Hook: ' + 'Checking done.');
end;
begin
// Create a new Container Item
ads := Factory.CreateContainerPlaylistItem;
// create a copy of the reference as an IPlaylistItem interface
adsContainerAsPlaylistItem := IPlaylistItem(ads);
startMarkup;
MarkupCurrentPlaylist;
adsContainerAsPlaylistItem.SetTitle('Coming Up Next');
Playlist(0).Insert(iToth + 1, adsContainerAsPlaylistItem);
end.
You have to make some minor adjustments concerning the opener, middle and closer jingles.
It picks, when available, up to three hooks from the current playlist and plays them with a jingle before, in the middle and after. If there are no hooks, only the closer jingle is played. Good luck.