Note that this Wiki is a work in progress, items may not be updated or may disappear entirely as the pages are updated.
Pull from multiple categories and make a playlist
From SpacialAudio
This script will pull music from multiple category folders of your choice, based on rules, and build a playlist of a certain duration with and intro and exit for the show.
It will cycle through the category list to pull from until the duration specified has been reached.
Wait for a time then load the playlist to the top of the queue.
The script has only been tested for a 1 hour show and 30 minutes on a 1.4 gig with 192 megs of memory and on an 850 with 256 megs of memory.
Be sure to give it plenty of time to work before the show should run.
There are no implied warranties or claims. This script is as is.
Feel free to modify or what ever.
1. Make sure the category you are pulling from has enough songs for the rules
2. Make sure the to categories you are pulling from and filling exist.
3. You may have to play with your rules some to get it to pull the way you want
4. I have tried to prevent duplicate artists but don't be surprised if some show up (tags , inconsistent artist names etc.)
If you get access memory problem.
Check to make sure that all the category folders involved exist
You may download the script here. http://spacialaudio.com/knowledge/attachment.php?attId=51
While the above link no longer works, here's the script retrieved from archive.org:
{*********************************************
selects from more than 1 category to fill a playlist
categories to pull from are cycled theough till duration is satisfied
cat3p.pal
***********************************************
Make sure the CategoryToPullFrom has songs in it
***********************************************}
PAL.loop := true ;
const ShowDuration : integer = 3600000; //1 hour in milli seconds
const ShowIntrofile : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\bbintro.wma' ;
const ShowExitfile : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\bbexit.wma' ;
const PlaylistFile : string = 'C:\Program Files\SpacialAudio\SAM2\Sound\promos\ashshow.m3u' ;
const ShowTitle : string = '# An Hour Show';
var D, D2 : TDataSet;
var SonginfoT : TSongInfo;
var ShowQueue : TStringList;
var CategoryList : TStringList;
var HoldArtist : string;
var CatlistIndex : integer ;
var totalduration : integer ;
var durationinminutes : integer;
var songcount : integer ;
var catID : integer ;
var idofsong : integer ;
var x : integer;
var logicswitch : integer;
var Artist : string;
var CategoryToPullFrom : string;
var ExistingArtist : boolean;
songcount := 0;
durationinminutes :=0 ;
totalduration := 0 ;
ExistingArtist := false ;
CategoryList := TStringList.Create;
ShowQueue := TStringList.Create;
HoldArtist := '';
CategoryList.add ('Tracks');
CategoryList.add ('bigband');
CategoryList.add ('Tracks');
CatlistIndex := 0;
// add show intro and get exit duration
D2 :=Query('SELECT duration from songlist where filename = :fname',[ShowIntroFile],True);
totalduration := totalduration + D2['duration'];
ShowQueue.Add(ShowTitle);
ShowQueue.Add(ShowIntroFile);
// get exit duration
D2 :=Query('SELECT duration from songlist where filename = :fname',[ShowExitFile],True);
totalduration := totalduration + D2['duration'];
writeln ('adding intro ' + ShowIntroFile + ' duration = ' + inttostr(D2['duration']));
D2.free ;
//Start PAL for filling CatToFill pulling from CategoryToPullFrom.
while (totalduration <= ShowDuration) do
begin
//which category to pull from
If CatListIndex >= CategoryList.Count then
CatListIndex := 0;
CategoryToPullFrom := CategoryList.Get(CatListIndex);
//Writeln(CategoryToPullFrom);
{**********************************************************
here are 2 different ways to choose the songs you can add more.
the randomInt is 0 based so if you want 3 different sets of logic
you use 3 but the numbers returned start at 0 so for 3 you get 0,1,2
*********************************************************}
logicswitch := RandomInt(2);
Case CatListIndex of
0,3: begin //jazz
case logicswitch of
0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,EnforceRules);
1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,NoRules);
end;
end;
1: begin //bigband
case logicswitch of
0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLRP,NoRules);
1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,NoRules);
end;
end;
2: begin // you get the idea
case logicswitch of
0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,NoRules);
1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,NoRules);
end;
end;
end;
{ case logicswitch of
0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,NoRules);
1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,NoRules);
end;}
Artist := Trim(SonginfoT['artist']) ;
//writeln('artist from choose = ' + artist);
D2 := Query('SELECT songid FROM categorylist ' +
'WHERE (songid = :sid) and (categoryID = :cid )', [ SonginfoT['songID'],catID], True);
If D2.EOF then
begin
//see it artists has already been put in show folder
x := Pos(Artist, HoldArtist);
if x > 0 then
ExistingArtist := True
else
ExistingArtist := False;
if not ExistingArtist then
begin
totalduration := totalduration + SonginfoT['duration'];
if totalduration <= ShowDuration then
begin
Writeln( 'Adding from ' + CategoryToPullFrom);
writeln ( SonginfoT['artist'] + ', ' + SonginfoT['title'] );
HoldArtist := HoldArtist + Artist + ' ';
ShowQueue.add (SonginfoT['filename']);
songcount := songcount + 1;
CatListIndex := CatListIndex + 1;
end;
end;
end;
D2.Free
end;
ShowQueue.Add(ShowExitFile);
ShowQueue.SaveToFile(PlaylistFile);
durationinminutes := (totalduration / 1000) /60;
Writeln ( inttostr(songcount) + ' Songs were added for a total of ' +
'approximatly ' + inttostr(durationinminutes) + ' minutes');
Categorylist.Destroy;
ShowQueue.Destroy;
//wait for 8pm to queup the show
PAL.WaitForTime(T['21:29:59']);
Queue.AddList(Playlistfile,ipTop);
PAL.WaitForTime(T['23:59:59']); {Wait for next day}
