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 1 category and fill another up

From SpacialAudio

Jump to: navigation, search

This script will pull music from 1 category folder of your choice, based on rules, and fill the category you want it to.
It runs until the duration specified has been reached.

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 category 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=48

{*******************************************************
emptys a category folder and selects from more  1 category to fill the empty one
till duration is satisfied
cat2c.pal
 ***********************************************
Make sure the CategoryToPullFrom has songs in it
********************************************************}
PAL.loop := true   ;
const CategoryToPullFrom : String = 'Tracks' ;
const CatToFill          : String = 'jzshow';
const ShowDuration       : integer = 3600000; //1 hour in milli seconds

var D, D2              : TDataSet;
var SonginfoT          : TSongInfo;
var HoldArtist         : string;
var HoldSong           : string;
var totalduration      : integer ;
var catID              : integer ;
var idofsong           : integer ;
var songcount          : integer ;
var x                  : integer;
var logicswitch        : integer;
var durationinminutes  : integer;
var Artist             : string;
var ExistingArtist     : boolean;


totalduration := 0 ;
songcount := 0;
ExistingArtist:= false ;
HoldArtist := ;
HoldSong :=  ;

  //DELETE songs from CatToFill
     D2:=Query('SELECT ID, name  FROM category WHERE name = :cat', [CatToFill], True);
     writeln ('Deleting songs from category ' + D2['name']);
     ExecSQL('DELETE FROM categorylist WHERE categoryID = :categoryID', [D2['ID']]);
     catID := D2['ID']   ;
     D2.free ;
     writeln ( CatToFill + ' now empty');
      
  //Start PAL for filling CatToFill pulling from CategoryToPullFrom.
  while (totalduration <= ShowDuration) do
  begin
      {****************************************************
      here are 3 different ways to choose the songs you can add more.
      the randomInt is 0 based so if you want 4 different sets of logic 
      you use 4 but the numbers returned start at 0 so for 3 you get 0,1,2,3.
      Make sure the category you are pulling from has songs in it.
     ***************************************************}
     logicswitch := RandomInt(3);
     //writeln('logic switch = ' + inttostr(logicswitch))  ;
     case logicswitch of
        0 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,NoRules);
        1 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smLemmingLogic,NoRules);
        2 : SonginfoT := Cat[CategoryToPullFrom].ChooseSong(smRandom,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
              CAT[CatToFill].AddFile(SonginfoT['filename'],ipBottom);
              HoldArtist := HoldArtist + Artist + ;
              songcount := songcount + 1;
              writeln (SonginfoT['artist'] + ', ' + SonginfoT['artist'] +' Added');
              //if you want to see the list as its built uncomment the code below
              {
              writeln ('========================================');
              for x := 0 to y do
              begin
                 writeln ( 'artists in list ' + strlist[x]);
              end;
              writeln ('========================================');
              }
           end;
        end; // not oldsong
     end;  //  D2.EOF
     D2.Free        
  end; // while duration
  durationinminutes := (totalduration / 1000) /60;
  Writeln ( inttostr(songcount) + ' Songs were added for a total of ' + 
     'approximatly ' + inttostr(durationinminutes) + ' minutes');     
  //wait for next day
PAL.WaitForTime(T['23:59:59']);
Personal tools