Add Hourly Playlists

{*******************************************************************************
PAL script for putting Music 1 SE hourly playlists into the queue at 5 minutes
before the hour based on the naming scheme of Music 1 for hourly playlists
yymmdd.hh.m3u
You will need to change the constants to meet your needs.
The load time can be changed as well as clearing que or waiting for 1 song play clear queue and add.

This is a basic script - a starting place to extend to meet your own needs.
*******************************************************************************}

PAL.Loop := True;

const PlaylistPath = 'c:\music 1 se\SAM Playlists\'; // location your Music 1 playlists are saved
const Fileextension = '.m3u'  ; // the playlist extension

var Present: DateTime;
var Year, Month, Day, Hour, Min, Sec, MSec,DayLength,MonthLength, HourLength : Integer;
var HoldYear,TheYear,TheMonth, TheDay, TheHour, Playlist :String;
var LessThan : Boolean;


//Present:= Now + 1;  // since we are loading a few minutes before the next day we want the next days list
Present:= Now;
DecodeTime(Present, Hour, Min, Sec, MSec);
writeln ( IntToStr(Hour));
Hour := Hour + 1;
If (Hour = 24) then
   Hour := 0; // set it to mid night
writeln ('Hour to get ' + IntToStr(Hour));
if (Hour = 0)   Then
    Present:= Now + 1;

DecodeDate(Present, Year, Month, Day);
HoldYear :=  IntToStr(Year);
TheYear := Copy(HoldYear,3,2); // copy the last 2 digits of the year 2007 would copy the 07
TheMonth :=  IntToStr(Month);
TheDay := IntToStr(Day);
TheHour := IntToStr(Hour);
MonthLength := length(TheMonth) ;
DayLength := length(TheDay);
HourLength := length(TheHour);

LessThan := MonthLength < 2;
If (LessThan)  Then
   TheMonth := '0'+ TheMonth; // if a single digit add 0 to front

LessThan := DayLength < 2;
If (LessThan)  Then
    TheDay := '0'+ TheDay; // if a single digit add 0 to front

	LessThan := HourLength < 2;
If (LessThan)  Then
    TheHour := '0'+ TheHour; // if a single digit add 0 to front
	
Playlist := PlayListPath + TheYear+TheMonth+TheDay+ '.' + TheHour + Fileextension;
//  writeln (TheYear);
//  writeln (TheMonth);
//  writeln (TheDay);
   writeln (Playlist);


PAL.WaitforTime(T['xx:55:00']);  // wait for 5 minutes befor the hour

if(FileExists(Playlist))then
begin
   Queue.Clear;
   Queue.AddList(Playlist,ipBottom); // add playlist to bottom of the queue
   ActivePlayer.FadeToNext;
   WriteLn('Loaded: '+Playlist);
end
else
begin
   WriteLn('PLAYLIST NOT VALID!');
   WriteLn(Playlist);
end;

PAL.WaitforTime(T['xx:59:59']);