Skip to Content
It is currently March 2nd, 2021, 9:34 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Waitfortime
PostPosted: October 20th, 2020, 8:30 pm 
Offline
Junior User
Junior User

Joined: August 7th, 2018, 7:29 am
Posts: 25
I am sorry, I am not a programmer. I can work with a script that has been written, but am not adept at writing it myself. So I implore you for patience.

I would be happy to be pointed to a script that is close to what I need, for training purposes.

I need it to go to a specific URL and run a file.

The file has a different date and month on it as appropriate.

It runs 7 days a week.

I have tried to write something myself but get nothing but screw-ups.

This script runs a program that airs at 07:20 every morning.

Here is the URL.


https://content.blubrry.com/thenational ... 1_2020.mp3

I do not use SQL.

Any help would be appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 21st, 2020, 7:12 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8155
Location: Cologne (Germany)
Can you influence the filename or is this a third party file?

It would be much easier if the date was in SAM's default format instead, because in PAL you can't influence the format of the DateToStr function, despite the documentation referencing the Delphi format definition variable.


If you can't influence the filename, you have to provide a list of Month names to replace the numeric values with.
Something like this needs to be placed at the top of your script:
Code:
var months : array[1..12] of string;

months[1] := 'Januar';
months[2] := 'Februar';
...


Then you can use the DecodeDate function like this:
Code:
var yy, mm, dd: Integer;
DecodeDate(Now, yy, mm, dd);

var url: string;
url := '...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';
WriteLn(filename);


That should give you the back part of the filename.
Now piece that together with the rest of the URL and the file extension and you have the URL you need for WebToFile.
If you don't need to keep an archive of these files, you can just store them with a new name and replace the downloaded file all the time.
i.e.:
Code:
WebToFile('C:\downloadedfile.mp3', url);[/quote]

Last but not least you probably want to play the file you just downloaded:
[code]Queue.AddFile('C:\downloadedfile.mp3', ipTop);
IF QueuedPlayer <> nil THEN
BEGIN
  PAL.LockExecution;
  QueuedPlayer.Next;
  QueuedPlayer.Play;
  ActivePlayer.Eject;
  PAL.UnlockExecution;
END
ELSE
  ActivePlayer.Next;


That snippet looks a little complicated, just because it's made to immediately start playing the track while removing all currently playing and queued tracks from both players. If you're fine with it just being at the top of the queue, you can leave the whole IF segment out.

Please note that the file you're playing will most likely not have any title/artist information when it's loaded or it will show the information from the previous download instead. You should try this first and only think about adjusting when you need to. (one problem at a time)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 21st, 2020, 7:33 pm 
Offline
Junior User
Junior User

Joined: August 7th, 2018, 7:29 am
Posts: 25
I can usually decipher and adapt to a script. I just can't write one from scratch.

I can not change the file name.

My big issue is that I can not get the waitfortime to waitfortime. There must be something I am missing to get it to work. It just keeps running and running.

I had a script to play it remotely as an outsourced program. But it won't stop loading the program.


PAL.Loop := True;


PAL.WaitForTime('7:20:00');

Queue.AddURL('https://content.blubrry.com/thenationaldaily/National_Daily_October_21_2020.mp3',iptop);


If someone wanted to make a buck .. and help the cause of SAM Broadcaster .. setup and offer online classes for PAL scripting.


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 22nd, 2020, 3:36 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8155
Location: Cologne (Germany)
WaitForTime should actually be called WaitForAtLeastTime.

The reason your script keeps on looping is because once 07:20:00 has passed (like for instance when it's 13:30:00), 07:20:00 is over so there's no need to wait anymore.

Check out the PAL Quick Start Guide to get an intro to programming PAL and mentions of all/most of the quirks that separate PAL from PASCAL/Delphi (the programming language it's modeled after and using internally)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 22nd, 2020, 5:02 pm 
Offline
Junior User
Junior User

Joined: August 7th, 2018, 7:29 am
Posts: 25
The code:

var yy, mm, dd: Integer;
DecodeDate(Now, yy, mm, dd);

var url: string;
url := '...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';
WriteLn(filename);

returns an 'unknown file name error. Where is it getting the filename from? Does Pal know that it is supposed to be October now?


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 22nd, 2020, 5:08 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8155
Location: Cologne (Germany)
Oh, sorry my bad. That happens when I write forum posts at almost 3am in the night.
It should actually say url there. I changed the name of the variable while writing this to be more explicit and better show what it actually contains.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 24th, 2020, 11:57 am 
Offline
Junior User
Junior User

Joined: August 7th, 2018, 7:29 am
Posts: 25
Ok, explain just where the script goes out and gets the file to download.

All I am getting is the placement of 'downloaded file' in the queue. Not the file I am trying to get.

Here is what I have so far, with your assistance, thank you.

Code:
//PAL.WaitForAtLeastTime('07:19:00'); //Show Starts at 7:20 am

var months : array[1..12] of string;

months[1] := 'Januar';
months[2] := 'Februar';
months[3] := 'March';
months[4] := 'April';
months[5] := 'May';
months[6] := 'June';
months[7] := 'July';
months[8] := 'August';
months[9] := 'September';
months[10] := 'October';
months[11] := 'November';
months[12] := 'December';

var yy, mm, dd: Integer;
DecodeDate(Now, yy, mm, dd);

var url: string;
//October_23_2020.mp3
url := 'https://content.blubrry.com/thenationaldaily/National_Daily_...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';
WriteLn(url);

//Last but not least you probably want to play the file you just downloaded:

Queue.AddFile('C:\documents\alexanews\National_Daily_...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';.mp3', ipTop);

 if (ActivePlayer = nil) then
    WriteLn('WARNING!!! Nothing is playing??');


IF QueuedPlayer <> nil THEN

Queue.AddFile('c:\documents\alexanews\National_Daily_...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';.mp3',ipTop);

 ActivePlayer.FadeToNext;

BEGIN
  PAL.LockExecution;
  QueuedPlayer.Next;
  QueuedPlayer.Play;
  ActivePlayer.Eject;
  PAL.UnlockExecution;
END    ;
//ELSE
  //ActivePlayer.Next;

PAL.Loop := True; //Restart script


Last edited by Mastacheata on October 24th, 2020, 5:40 pm, edited 1 time in total.
Please use CODE tags for pasting PAL-Code


Top
 Profile  
Reply with quote  
 Post subject: Re: Waitfortime
PostPosted: October 24th, 2020, 6:11 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8155
Location: Cologne (Germany)
Hahaha, sorry I think I might've confused you with the WaitForAtLeastTime thing.
There is no command by that name as you might've noticed. I just said that it should actually be called that way to better explain how the command works and that the real name is misleading. If you want to have a PAL script wait for an exact time, you first need to check if the next wait time is today or tomorrow. If you can still wait for that time today, PAL.WaitForTime works just as expected. If that time is already over, you first have to wait for the end of the day and then wait for the time again.

Example:
It's 5am and you want to wait for 07:00:00 => PAL.WaitForTime will wait 2 hours until it's 7am.

It's 11am and you want to wait for 07:00:00 => PAL.WaitForTime will not wait at all, because 7am is already over.
For situations where you want to run a PAL script every day at one specific time, better use the event scheduler and schedule the PAL script to run instead of adding a loop and WaitForTime to your PAL script.


---

Code:
months[1] := 'Januar';
months[2] := 'Februar';


You either missed a y at the end of the first 2 months or you mistakenly named your other months in English instead of sticking with the German names.

Code:
url := 'https://content.blubrry.com/thenationaldaily/National_Daily_...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';

That doesn't look like the sample filename you posted earlier. You missed to fill in the blanks I left for you to fill in. (... is not the actual text that's supposed to go there. You take the original link and put everything up to the name of the month in front of the first + and everything that comes after the year after the last + - You're supposed to fill in the correct filename and stuff yourself where I left the ...)

Same here:
Code:
Queue.AddFile('c:\documents\alexanews\National_Daily_...' + months[mm] + '_' + IntTostr(dd) + '_' + IntToStr(yy) + '...';.mp3',ipTop);


That script will not work because you messed the IF up.
An if statement can either have ONE (only one) command that is executed when the condition matches or it can have a block of statements enclosed in begin ... end; (You may not have a semicolon after END if the next line says either ELSE or UNTIL and you must have a semicolon after END in any other case)

In your case you moved the queue.addfile inside the IF, so that one is only executed if there's no player that has a track loaded, but is not playing.

The rest of the code is always executed, regardless of whether there is a QueuedPlayer or not and regardless of whether you added the file to the queue or not.

Last but not least: Where did downloading the file go? You stored the URL in a variable, but never use it and then you add a file from your harddisk that you never downloaded in the first place (or maybe you have, but you didn't do that through SAM)

---


To sum it up:

1. Schedule your script with the Event scheduler and remove WaitForTime and PAL.Loop
2. Fix your months
3. Fix the URL (fill in the ...)
4. Download the file after you built the url and before you add it to the queue. (WebToFile in my last post)
5. Fix the IF (move queue.addfile above the IF, remove activeplayer.fadetonext)
6. Maybe you need to fix your queue.addfile after you downloaded the file (use the same name you entered in WebToFile as the second parameter)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group