We are in the process of migrating the Spacial Wiki content to our new Help Center at spacial.com.
Please visit the Help Center for latest Tips and Tricks, Documentation and Troubleshooting.
spacial.com/help-center

Two For Tuesdays (Based on 2fer)

From SpacialAudio

Jump to: navigation, search

I took the 2fer Pal Script and added a Start and End time.

Fairly Simple to do if you are already running the 2fer script.


PAL.Loop := True;
var mytime : DateTime = now;
var I : Integer;
var start_time, end_time : DateTime;
start_time := date + EncodeTime(19,58,00,0);
end_time := date + EncodeTime(19,58,30,0);

// Only Run on Tuesday Nights

if DayOfWeek(Now) = Tuesday then
begin

// Declare variables

   var theArtistInQueue, theCountSongs, theSongChooser : TDataSet;
   
   if( mytime >= start_time) and (mytime <= end_time) Then
      begin
        WriteLn('Two for Tuesdays!');
  WriteLn();

// Choose a random song while enforcing the rules and put in queue bottom

   CAT['Songs'].QueueBottom(smRandom,EnforceRules);

// Let's find out the artist and songid we just put in the queue

   theArtistInQueue := Query('select title, artist, songID, queuelist.id as queueID ' +
     'from songlist, queuelist ' +
     'where songlist.id = queuelist.songID '+
     'order by queueID desc limit 1',[],True);
   WriteLn('Added: ' + QuotedStr(theArtistInQueue['artist']));
   WriteLn('  ' + QuotedStr(theArtistInQueue['title']));
   WriteLn();

// Let's get a count of the remaining songs by this artist

   theCountSongs := Query('select count(*) as cnt' +
     ' from songlist' +
     ' where id <> ' + IntToStr(theArtistInQueue['songID']) +
     ' and songtype = S' +
     ' and artist = ' + QuotedStr(theArtistInQueue['artist']),[],True);
   WriteLn('There are ' + IntToStr(theCountSongs['cnt']) + ' songs to choose from');
   WriteLn();
   if (theCountSongs['cnt'] = 0) then
     begin
       WriteLn('ZERO songs to choose from!');
       WriteLn('Removing ' + QuotedStr(theArtistInQueue['artist']));
       Queue.Delete(StrToInt(theArtistInQueue['queueID']));
       WriteLn('Starting over...');
     end
   else
     begin
       WriteLn('Choosing random song...');

// Choose a random song from the remaining songs by this artist

       theSongChooser := Query('select title, filename' +
         ' from songlist' +
         ' where id <> ' + IntToStr(theArtistInQueue['songID']) +
         ' and songtype = S' +
         ' and artist = ' + QuotedStr(theArtistInQueue['artist']) +
         ' order by rand() limit 1',[],True);

// Put random song in queue bottom

       Queue.AddFile(theSongChooser['filename'],ipBottom);
       WriteLn('Added: ' + QuotedStr(theArtistInQueue['artist']));
       WriteLn('  ' + QuotedStr(theSongChooser['title']));
       WriteLn();

// Be nice... Free up the data structures

       theSongChooser.Free;
       theArtistInQueue.Free;
       theCountSongs.Free;

//Wait for queue to contain 4 tracks before continuing

       WriteLn('Waiting for queue to contain 4 tracks before continuing...');
       PAL.WaitForQueue(4);
     end;
 end;
 end;

Good Luck with it...

Personal tools