Jump to content

Make a weekly PAL play monthly?


busby

Recommended Posts

I have a 'default' PAL which I use for my weekly shows, but I want to add a selction at the beginning of the script so it only runs on defined weeks of the month, so I can schedule it as a weekly show in the event scheduler..

 

Can anyone help please?

Link to comment
Share on other sites

OK, here we go:

 

//Set integer value to number of parts in show
const PARTS : Integer = 1;
var Song : TSongInfo;
var Present : DateTime = now;
var curPart, Year, Month, Day : Integer;
var D : string;
var Artist : string;
var Show : string;

// Settings, Artist has to be EXACTLY like the folder-name.
Artist := 'Sunlight';
Show := 'Sun Trance On 1Mix Radio..';

SubDir['C:\Radio\' + Artist].Rescan;
curPart := 0;

//Wait half a minute
PAL.WaitForTime('XX:00:00');
PAL.LockExecution;
Queue.Clear;
//Add files to top of queue in reverse order so last loaded plays first
//Dir['C:\Radio\Jingles&Wipes'].QueueTop(smRandom, NoRules);
//Dir['C:\Radio\'+Artist+'\part 04'].QueueTop(smLRP, NoRules);
//Dir['C:\Radio\Jingles&Wipes'].QueueTop(smRandom, NoRules);
//Dir['C:\Radio\'+Artist+'\part 03'].QueueTop(smLRP, NoRules);
//Dir['C:\Radio\Jingles&Wipes'].QueueTop(smRandom, NoRules);
//Dir['C:\Radio\'+Artist+'\part 02'].QueueTop(smLRP, NoRules);
//Dir['C:\Radio\Jingles&Wipes'].QueueTop(smRandom, NoRules);
Dir['C:\Radio\'+Artist+'\part 01'].QueueTop(smLRP, NoRules);
Dir['C:\Radio\Jingles&Wipes'].QueueTop(smRandom, NoRules);

//Fade into jingle, which was loaded last
//Check for incorrectly loaded track and eject if it exists
if QueuedPlayer  NIL then
 QueuedPlayer.Eject;
//Fade into jingle, which was loaded last
ActivePlayer.FadeToNext;
PAL.UnlockExecution;
PAL.WaitForPlayCount(2);
// Inserting title and date
while (curPart   begin
   Song := TSongInfo.Create;
   DecodeDate(Present, Year, Month, Day);
   D := (IntToStr(Day)) + '.' + (IntToStr(Month)) + '.' + (IntToStr(Year));
   Song['artist'] := Artist;
   Song['title'] := Show + ' (' + D + ') Check the Forums for Tracklisting..';
   Encoders.SongChange(Song);
   Song.Free;
   curPart := curPart + 1;
   PAL.WaitForPlayCount(0);
end;

 

I have a script which has the required selections, but every attempt I have had to extract the bits I want has just given me compile errors:

 

const ONE_PART : Integer = 1;
const SHOW_HOST : String = 'Arctic Sun'; //also Artist name!
const SHOW_NAME : String = 'Sunstate Sounds';
const TWITTER : String = '';
const TRAILING_TAG : String = 'on 1Mix Radio..';
const FIRST_CATEGORY : String = 'New Shows'; //'Category Name';
const SECOND_CATEGORY : String = 'Replays'; //'Category Name';
const JINGLE_DIR : String = 'C:\Radio\Jingles&Wipes';
const MIX_JINGLES : Integer = 1;
const SUB_DIR : Integer = 0;
const MOVE_FILES : Integer = 0;
const OLD_DIR : String = 'C:\Radio\'+SHOW_HOST+'\';
const NEW_DIR : String = 'C:\Radio\Replay\';
const INTRO_ON : Integer = 0;
const INTRO : String = OLD_DIR+'id\id1.mp3';
const OUTTRO_ON : Integer = 0;
const OUTTRO : String = OLD_DIR+'id\id2.mp3';
const WEEK_ONE   : Integer = 0;
const WEEK_TWO   : Integer = 1;
const WEEK_THREE : Integer = 0;
const WEEK_FOUR  : Integer = 0;
const WEEK_FIVE  : Integer = 0;

/////////////////////////////////////////////////////////////////////////////
/////////////////////////END USER ADJUSTABLE SETTINGS////////////////////////
/////////////////////////EDIT BELOW AT YOUR OWN RISK/////////////////////////
/////////////////////////////////////////////////////////////////////////////

type
   TPrimitive = class
public
   value : Variant;
   constructor Create(new : Variant);
end;

constructor TPrimitive.Create(new : Variant);
begin
   inherited Create;
value := new;
end;

var List : TList;
var Part : TPrimitive;
var Week : array[0..4] of Integer;
var Present : DateTime;
var CatTDS, FileTDS : TDataSet;
var NewName, DiffFile, DelFile : Boolean;
var FirstCatID, SecondCatID, FileName, FileExt, PathStr, NewPath, OldFile, FileDate, ShowDate, myMonth, myDay, TempStr : String;
var WeekOfMonth, WeekDay, Year, Month, Day, Cur, NewExist, PartsCount, Flag : Integer;

PAL.LockExecution;

Week[0] := WEEK_ONE;
Week[1] := WEEK_TWO;
Week[2] := WEEK_THREE;
Week[3] := WEEK_FOUR;
Week[4] := WEEK_FIVE;

Flag := 0;
WeekOfMonth := 0;

Present := Now;
DecodeDate(Present, Year, Month, Day);

while Day > 0 do
 begin
   Day := Day - 7;
   if Day > 0 then
     WeekOfMonth := WeekOfMonth + 1;
end;

PAL.UnlockExecution;

if (Week[WeekOfMonth] = 1) then
 begin
   List := TList.Create;
   Present := Now;
   DecodeDate(Present, Year, Month, Day);
   IF (Month       myMonth := '0' + IntToStr(Month)
   ELSE
     myMonth := IntToStr(Month);

   IF (Day       myDay := '0' + IntToStr(Day)
   ELSE
     myDay := IntToStr(Day);

   FileDate := IntToStr(Year) + '-' + myMonth + '-' + myDay;
   WriteLn(FileDate);
   ShowDate := '(' + myDay + '.' + myMonth + '.' + IntToStr(Year) + ')';
   WriteLn(ShowDate);

   CatTDS := Query('SELECT id FROM category WHERE name = :name',[FIRST_CATEGORY],True);
   FirstCatID := CatTDS['id'];
   CatTDS.Free;

   if (MOVE_FILES = 1) then
     begin
       CatTDS := Query('SELECT id FROM category WHERE name = :name',[sECOND_CATEGORY],True);
       SecondCatID := CatTDS['id'];
       CatTDS.Free;
   end;

   if (SUB_DIR = 0) then
     begin
       DIR[(OLD_DIR)].Rescan;
       DIR.Free;
   end
   else
     begin
       SUBDIR[(OLD_DIR)].Rescan;
       SUBDIR.Free;
   end;
   
   DIR[(JINGLE_DIR)].Rescan;
   DIR.Free;

   Cur := 0;

   PathStr := StringReplace(OLD_DIR,'\', '_', True);

   CatTDS := Query('SELECT COUNT(*) AS PartsCount FROM songlist WHERE filename LIKE :PathStr AND date_added LIKE :FileDate AND songtype = :songtype',[PathStr+'%',FileDate+'%','S'],True);
   PartsCount := CatTDS['PartsCount'];
   if (PartsCount = 0) then
     NewExist := 0
   else
     NewExist := 1;
   CatTDS.Free;
 
   if (NewExist = 1) then
     begin
       CatTDS := Query('SELECT * FROM songlist WHERE filename LIKE :PathStr AND date_added NOT LIKE :FileDate AND songtype = :songtype',[PathStr+'%',FileDate+'%','S'],True);
       CatTDS.First;
       while not CatTDS.EOF do
         begin
           if FileExists(CatTDS['filename']) then
             begin
               OldFile := CatTDS['filename'];
               if (MOVE_FILES = 1) then
                 begin
                   FileExt := ExtractFileExt(CatTDS['filename']);
                   FileName := ExtractFileName(CatTDS['filename']);
                   DiffFile := CopyFile(CatTDS['filename'],NEW_DIR+FileName, True);
                   if (DiffFile = True) then
                     begin
                       ExecSQL('UPDATE songlist SET filename = :filename, title = :title WHERE id = :id',[NEW_DIR+FileName+FileExt,CatTDS['title']+' [Replay]',CatTDS['id']]);
                       FileTDS := Query('SELECT id FROM categorylist WHERE songid = :songid',[CatTDS['id']],True);
                       FileTDS.First;
                       if FileTDS.EOF then
                         ExecSQL('INSERT INTO categorylist (songid, categoryid) VALUES (:songid, :secondcatid)',[CatTDS['id'],SecondCatID])
                       else
                         ExecSQL('UPDATE categorylist SET categoryid = :secondcatid WHERE songid = :songid',[secondCatID,CatTDS['id']]);
                       FileTDS.Free;
                   end
                   else
                     WriteLn('Could not move file '+CatTDS['filename']);
               end;
               DelFile := DeleteFile(OldFile);
               if (DelFile = False) then
                 WriteLn('Could not delete file: '+CatTDS['filename']);
               if (MOVE_FILES = 0) then
                 ExecSQL('DELETE FROM songlist WHERE id = :id',[CatTDS['id']]);
           end;
           CatTDS.Next;
       end;
       CatTDS.Free;
       CatTDS := Query('SELECT * FROM songlist WHERE filename LIKE :PathStr AND date_added LIKE :FileDate AND songtype = :songtype ORDER BY filename',[PathStr+'%',FileDate+'%','S'],True);
       CatTDS.First;
       while not CatTDS.EOF do
         begin
           FileExt := ExtractFileExt(CatTDS['filename']);
           if (ONE_PART = 0) then
             begin
               NewName := RenameFile(CatTDS['filename'],OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+' Part '+IntToStr(Cur+1)+' of '+IntToStr(PartsCount)+FileExt);
               if (NewName = True) then
                 begin
                   NewPath := OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+' Part '+IntToStr(Cur+1)+' of '+IntToStr(PartsCount)+FileExt;
                   ExecSQL('UPDATE songlist SET filename = :filename WHERE id = :id',[OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+' Part '+IntToStr(Cur+1)+' of '+IntToStr(PartsCount)+FileExt,CatTDS['id']]);
                   ExecSQL('UPDATE songlist SET artist = :show_host, title = :show_name WHERE id = :id',[sHOW_HOST+' '+TWITTER,SHOW_NAME+' '+ShowDate+' '+TRAILING_TAG,CatTDS['id']]);
               end
               else
                 WriteLn('File '+CatTDS['filename']+' could not be renamed.');
           end
           else if (ONE_PART = 1) then
             begin
               NewName := RenameFile(CatTDS['filename'],OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+FileExt);
               if (NewName = True) then
                 begin
                   NewPath := OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+FileExt;
                   ExecSQL('UPDATE songlist SET filename = :filename WHERE id = :id',[OLD_DIR+SHOW_HOST+' - '+SHOW_NAME+' '+ShowDate+FileExt,CatTDS['id']]);
                   ExecSQL('UPDATE songlist SET artist = :show_host, title = :show_name WHERE id = :id',[sHOW_HOST+' '+TWITTER,SHOW_NAME+' '+ShowDate+' '+TRAILING_TAG,CatTDS['id']]);
               end
               else
                 WriteLn('File '+CatTDS['filename']+' could not be renamed.');
           end;
           ExecSQL('INSERT INTO categorylist (categoryid, songid) VALUES (:firstcatid, :songid)',[FirstCatID,CatTDS['id']]);
           Part := TPrimitive.Create(NewPath);
           List.Add(Part);
           Cur := Cur + 1;
           CatTDS.Next;
       end;
       CatTDS.Free;
       WriteLn('New files ready to queue.');
       Flag := 1
   end

   else if (NewExist = 0) then
     begin
       CatTDS := Query('SELECT * FROM songlist WHERE filename LIKE :PathStr AND songtype = :songtype ORDER BY filename',[PathStr+'%','S'],True);
       CatTDS.First;
       if CatTDS.BOF and CatTDS.EOF then
         begin
           WriteLn('No files to play for '+SHOW_NAME+'!');
           Flag := 2;
       end;
       while not CatTDS.EOF do
         begin
           Part := TPrimitive.Create(CatTDS['filename']);
           List.Add(Part);
           CatTDS.Next;
       end;
       if not (Flag = 2) then
         begin
           WriteLn('Previous files ready to queue in leiu of this weeks files.');
           Flag := 1;
       end;
   end;
end;

while Flag = 1 do
 begin
   PAL.WaitForTime(T['XX:00:00']);
   PAL.LockExecution;
   if QueuedPlayer  NIL then
     QueuedPlayer.Eject;
 
   Cur := 0;
   Queue.Clear;
   DIR[(JINGLE_DIR)].QueueBottom(smRandom, NoRules);

   if (INTRO_ON = 1) then
     Queue.Addfile(INTRO, ipBottom);
     
   for Cur := 0 to List.Count-1 do
     begin
       Part := List[Cur] as TPrimitive;
       WriteLn(Part.value);
       Queue.AddFile(Part.value,ipBottom);
       Part.Free;
       if (MIX_JINGLES = 1) then
         DIR[(JINGLE_DIR)].QueueBottom(smRandom, NoRules);
   end;
   
   if (OUTTRO_ON = 1) then
     Queue.Addfile(OUTTRO, ipBottom);
   DIR[(JINGLE_DIR)].QueueBottom(smRandom, NoRules);

   ActivePlayer.FadeToNext;
   PAL.UnlockExecution;
   Flag := 0;
end;

List.Free;

 

Hope you can help..

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...