Skip to Content
It is currently August 19th, 2019, 9:58 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 10th, 2019, 7:14 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
I hope this is the correct section for this post.

The PAL script, through WebToFile() that sends the calls to Tunein, sometimes, make 2 calls instad of 1
Indeed it calls a PHP script which in turn calls Tunein ... and I record on a LOG file (just for test purpose) all the calls.
I notice that randomly but frequently, it sends the same call 2 times ... the second time is some second (5-10) far away from the first call (when the song starts to play)

I just give an example to be more clear.

A player (not matter DeckA or DeckB) starts play a song: Title - Artist - Album
The script is "excited" and it sends to Tunein the info ... &title=&artist=&album
After 5-10 seconds (sometimes also 30), it sends again the same info above ...
Then is quite and it wait for the next song

Now, I would like to understand whether this is due some strange stuff with the computer, or SAM or some strange and known behavior of the Pal Script Management


Last edited by DJ Cassio on February 10th, 2019, 1:10 pm, edited 1 time in total.
Moved to PAL Forum


Top
 Profile  
Reply with quote  
PostPosted: February 10th, 2019, 10:46 pm 
Offline
SVS Member
SVS Member

Joined: October 15th, 2003, 11:59 pm
Posts: 4730
Location: Los Angeles - A Little West Of Nashville
Not really understanding how this is possible. It's probably the script.

However, without seeing the script, hard to diagnose the issue.

_________________
- DJ Dee
- Spacial Volunteer Support (SVS)
- Custom PAL services: www.palscripts.com
- http://www.AlternativeHD.com
- http://www.lahotcountry.com


Top
 Profile  
Reply with quote  
PostPosted: February 11th, 2019, 6:21 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7868
Location: Aachen (Germany)
Tormy wrote:
The script is "excited" and it sends to Tunein the info ... &title=&artist=&album

If your script is excited, that would explain why it gets confused and sends things twice.

PAL however is not known to have any feelings nor does it usually execute two separate requests for a WebToStr/WebToFile call.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

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


Top
 Profile  
Reply with quote  
PostPosted: February 11th, 2019, 6:44 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Mastacheata wrote:
Tormy wrote:
The script is "excited" and it sends to Tunein the info ... &title=&artist=&album

If your script is excited, that would explain why it gets confused and sends things twice.

PAL however is not known to have any feelings nor does it usually execute two separate requests for a WebToStr/WebToFile call.


:lol: :lol: :lol:

However here the PAL script by Benedikt Bauer that I adapted e bit to my case.
It turns that randomly, it calls the PHP 2 times, as I said in the opening post.

I need to understand if it's due lack in programming, SAM issue or PC issue.
I have noticed something via TeamViewer ... and till now I thought it was only with TeamViewer ... but today I was with the owner at the telephone and he told me it occurs also in consolle:

When SAM is switching player from A to B or viceversa, everything freezes for a while
I'm wondering if it can be the cause of this issue ...

I went to check the PC TechSpecs, and I found: i3 2120 3.3GHz 4 cores 8GB :-/

Code:
PAL.WaitForPlayCount(1);
{Declaration (Variables)}
var     Player : TPlayer;
var     Song : TSongInfo;
var     statusmessage, returnmessage, picture: String;
var     ErrorLog, DebugLog : String;
const Address : string = 'http://www.XXXXXXXXXXXXXX/pics/'; // Where Pics are uploaded
const URLWebSite : string = 'http://www.XXXXXXXXXXXXXXXXX/twtu.php'; // Script tat sends to Twitter, Tunein, Log
const m3u : string = '#EXTM3U' +#13#10;
const m3u1 : string = '#EXTINF:'+#13#10;
const PathFiles : string = 'D:\Radio\SAM-SONG.INFO\';
{Declaration (Functions and Procedures)}
// Construct the GET String for the Web Script, call it and return the output
FUNCTION update(status, picture : String) : String; forward;

// Write Error / Debug Log
PROCEDURE WriteLog(msg : String; error : boolean); forward;


// BEGIN MAIN
//PAL.Loop := True;
//while Queue.Count > 1 do

//PAL.WaitForTime('+00:2:00');
//PAL.WaitForTime('+00:00:07');

// reliably detect ActivePlayer (needed for SAM <= 4.9.0, fixed in 4.9.1)
PAL.LockExecution;
IF (DeckA.Duration - DeckA.CurTime) >= (DeckB.Duration - DeckB.CurTime) THEN
  Player := DeckA
ELSE
  Player := DeckB;
PAL.UnlockExecution;

// SAM >= 4.9.1 can use this one:
//Player := ActivePlayer;

// Is anything playing right now?
IF ( Player <> NIL ) THEN
BEGIN
  Song := Player.GetSongInfo;
  IF (Song <> NIL) AND (Pos(Song['songtype'],'SCV') > 0) THEN
  BEGIN
    // Message to display in twitter
    statusmessage := Song['title'] + ' - ' + Song['artist'];
    picture := Song['picture'];
   
    IF Pos('jpg', picture) = 0 THEN
    BEGIN
      picture := 'na.png'
    END;

    returnmessage := update(statusmessage, picture);

    // Errormessages don't contain the underscore
    IF ( Pos('##', returnmessage) = 0 )  THEN
    BEGIN
      WriteLog(returnmessage, TRUE)
    END
    // For debugging purposes Successful Posts will be logged as well
    ELSE
      WriteLog(returnmessage, FALSE);
  END;
END;

Song.Free;
Player.Free;
// END MAIN



FUNCTION update(status, picture : String) : String;
var getStr,strStr, returnstr : String;
BEGIN
  strStr := '   ' + status + '   ';
  //AppendStringToFile('songs.txt', strStr);
  WriteLn(picture);
 
  BEGIN
    //SONG to FILE create if not exists
    IF FileExists(PathFiles + 'songs.txt') THEN
      SaveStringToFile(PathFiles + 'songs.txt', strStr)
    ELSE
      SaveStringToFile(PathFiles + 'songs.txt', strStr);
  END;

  BEGIN
    //SONG to FILE create if not exists
    IF FileExists(PathFiles + 'pictures.m3u') THEN
    BEGIN
      SaveStringToFile(PathFiles + 'pictures.m3u', m3u);
      AppendStringToFile(PathFiles + 'pictures.m3u', m3u1);
      AppendStringToFile(PathFiles + 'pictures.m3u', Address + picture);
    END
    ELSE
    BEGIN
      SaveStringToFile(PathFiles + 'pictures.m3u', m3u);
      AppendStringToFile(PathFiles + 'pictures.m3u', m3u1);
      AppendStringToFile(PathFiles + 'pictures.m3u', Address + picture);
    END
  END;
 
  // URLEncode Blanks and Special Chars
  status := URLEncode(status);
  picture := URLEncode(picture);

  getStr := URLWebSite
    + '?message=' + status + '&picture=' + picture
    + '&title=' + URLEncode(Song['title']) + '&artist=' + URLEncode(Song['artist']);
  WriteLog(getStr, FALSE);
  // Here goes the magic!
  WebToFile(PathFiles + 'webresponse.txt', getStr);
  returnstr := FileToStr(PathFiles + 'webresponse.txt');

  result := returnstr;
END;

PROCEDURE WriteLog(msg : String; error : boolean);
BEGIN
  IF NOT SetCurrentDir(PathFiles) THEN
  BEGIN
    CreateDir(PathFiles);
    SetCurrentDir(PathFiles);
  END;

  PAL.LockExecution;
  msg := DateTimeToStr(NOW) + '  ' + msg + chr(13) + chr(10);
  Writeln(msg);
  IF error THEN
  BEGIN
    //ERROR LOG create if not exists
    IF FileExists(PathFiles + 'twitter-error.log') THEN
      AppendStringToFile(PathFiles + 'twitter-error.log', msg)
    ELSE
      SaveStringToFile(PathFiles + 'twitter-error.log', msg)
  END
  ELSE
  BEGIN
    //DEBUG LOG create if not exists
    IF FileExists(PathFiles + 'twitter-debug.log') THEN
      AppendStringToFile(PathFiles + 'twitter-debug.log', msg)
    ELSE
      SaveStringToFile(PathFiles + 'twitter-debug.log', msg);
  END;
  //PAL.UnlockExecution;
END;


Top
 Profile  
Reply with quote  
PostPosted: February 11th, 2019, 2:00 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7868
Location: Aachen (Germany)
What's the matter with all the BEGINs and ENDs in there?
You can't and shouldn't use BEGIN and END as visual markers in your code. Use comments for that purpose.
Surplus BEGINs are usually ignored, but a surplus END is only surplus and ignored if there isn't a BEGIN that it could match to. In this case it could match to the FUNCTION declaration's BEGIN statement and therefore prematurely end the function body.
In SAM/PAL the results of that are pretty much unpredictable as you can't pause code inside a function. Function calls are always treated as if they were executed inside a LockExecution block.

I'd suggest removing all the surplus BEGIN and END statements and checking if that already solves your problem.

Code:
FUNCTION update(status, picture : String) : String;
var getStr,strStr, returnstr : String;
BEGIN
  strStr := '   ' + status + '   ';
  //AppendStringToFile('songs.txt', strStr);
  WriteLn(picture);
 
  BEGIN // <-- This one is not supposed to be there
    //SONG to FILE create if not exists
    IF FileExists(PathFiles + 'songs.txt') THEN
      SaveStringToFile(PathFiles + 'songs.txt', strStr)
    ELSE
      SaveStringToFile(PathFiles + 'songs.txt', strStr);
  END; //<-- This one neither, depending on how PAL takes this, this might be ending the function declaration already.

  BEGIN //<-- This isn't in the right place either
    //SONG to FILE create if not exists
    IF FileExists(PathFiles + 'pictures.m3u') THEN
    BEGIN
      SaveStringToFile(PathFiles + 'pictures.m3u', m3u);
      AppendStringToFile(PathFiles + 'pictures.m3u', m3u1);
      AppendStringToFile(PathFiles + 'pictures.m3u', Address + picture);
    END
    ELSE
    BEGIN
      SaveStringToFile(PathFiles + 'pictures.m3u', m3u);
      AppendStringToFile(PathFiles + 'pictures.m3u', m3u1);
      AppendStringToFile(PathFiles + 'pictures.m3u', Address + picture);
    END  //<-- this one needs a semicolon at the end
  END; //<-- this one isn't meant to be here either and could once again end the declaration/body of the function
 
  // URLEncode Blanks and Special Chars
  status := URLEncode(status);
  picture := URLEncode(picture);

  getStr := URLWebSite
    + '?message=' + status + '&picture=' + picture
    + '&title=' + URLEncode(Song['title']) + '&artist=' + URLEncode(Song['artist']);
  WriteLog(getStr, FALSE);
  // Here goes the magic!
  WebToFile(PathFiles + 'webresponse.txt', getStr);
  returnstr := FileToStr(PathFiles + 'webresponse.txt');

  result := returnstr;
END;



You can also remove the code for reliably detecting the right playback deck from your code and use the ActiveDeck Function from PAL instead (it's written in the comments and the best practice is commented out because I created that script when SAM 4.9.1 wasn't out / was really new)

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

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


Top
 Profile  
Reply with quote  
PostPosted: February 11th, 2019, 5:46 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
I never ever used BEGIN-END as visual markers.
I did find that code, and I adjusted something , but not that structure.
It looks like the Pascal (to me) But I have not clue how and when to use BEGIN-END, thus I left as they were. I simply copied and paste one or two times a cycle, and modified it to write the m3u and songs.txt

Then recently I only worked to variables that's it.

NOTE: I remind that: when I have more lines on the cycle IF THEN ELSE I have not clue how to manage them without getting an error from the tini-tiny editor of SAM. So I used in one case a BEGIN-END to be able do not get the error


Top
 Profile  
Reply with quote  
PostPosted: February 11th, 2019, 6:53 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7868
Location: Aachen (Germany)
Code:
IF ... THEN
BEGIN
  WriteLn('1');
  WriteLn('2');
  WriteLn('3');
END;


This is fine.

Code:
BEGIN
  IF ... THEN
  BEGIN
    WriteLn('1');
    WriteLn('2');
    WriteLn('3');
  END;
END;


This is not. You already encapsulated the THEN part of the IF, so why do you want to encapsulate the IF itself as well?

IF x THEN dostuff ELSE dostuff
is treated as ONE statement by PAL/Pascal.
So is WHILE x DO dostuff, REPEAT dostuff UNTIL x and FOR x:=1 TO 2 DO dostuff

There's no need to wrap either of these in BEGIN END.
Obviously if you want to put that inside another thing and combine it with one or more other commands, then you need BEGIN and END, but only because that outer thing wants it, not because of IF or any of the LOOPS need to be encapsulated.



This is the original code from my website:
Code:
{**
 * SAM Broadcaster Web2.0 Connector (Twitter)
 *
 * @copyright     2011 by Benedikt Bauer | http://www.sam-song.info
 * @version       11.07-11b
 * @link          http://www.sam-song.info
 * @author        Benedikt Bauer
 *
 * @license
 * The contents of this file are subject to the
 *            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *                   Version 2, December 2004
 *
 * Copyright for this License (C) 2004 Sam Hocevar <sam@hocevar.net>
 *
 * Everyone is permitted to copy and distribute verbatim or modified
 * copies of this license document, and changing it is allowed as long
 * as the name is changed.
 *
 *            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 *   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 *
 *  0. You just DO WHAT THE FUCK YOU WANT TO.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
 *}



/////////////////////////////////////////////////////////////////////
//    Nettiquette                                                  //
//    You may use this PAL Script to communicate with my server    //
//    Change it to your like but don't flood the server/network    //
//                                                                 //
//    Also make sure you don't post any inappropriate messages     //
//    Either me or twitter/fb might then cease to run this service //
//                                                                 //
//    This service has no guaranteed uptime nor support            //
//    However you may ask Questions in the Spacialaudio Forums     //
//    I will probably come back to you and help                    //
//                                                                 //
//    The Webservice will stay private                             //
//    At least until its completely done and tidied up             //
//                                                                 //
//                                                                 //
//    Don't make any changes outside of boxes like this            //
//    unless you really know what you do.                          //
//    I won't give any support if you changed something            //
//    you better shouldn't have touched                            //
//                                                                 //
/////////////////////////////////////////////////////////////////////

{Declaration (Variables)}
var     Player : TPlayer;
var     Song : TSongInfo;
var     statusmessage, returnmessage, picture : String;
var     ErrorLog, DebugLog : String;

{Declaration (Functions and Procedures)}
// Construct the GET String for the Web Script, call it and return the output
FUNCTION update(status, picture : String) : String; forward;

// Write Error / Debug Log
PROCEDURE WriteLog(msg : String; error : boolean); forward;


// BEGIN MAIN
PAL.Loop := True;

PAL.WaitForTime('+00:15:00');

// reliably detect ActivePlayer (needed for SAM <= 4.9.0, fixed in 4.9.1)
//PAL.LockExecution;
//IF (DeckA.Duration - DeckA.CurTime) >= (DeckB.Duration - DeckB.CurTime) THEN
//  Player := DeckA
//ELSE
//  Player := DeckB;
//PAL.UnlockExecution;

// SAM >= 4.9.1 can use this one:
Player := ActivePlayer;

// Is anything playing right now?
IF ( Player <> NIL ) THEN
BEGIN
  Song := Player.GetSongInfo;
  IF (Song <> NIL) AND (Pos(Song['songtype'],'SJI') > 0) THEN
  BEGIN
    // Message to display in Twitter
    statusmessage := Song['artist'] + ' - ' + Song['title'];
    picture := Song['picture'];

    IF Pos('jpg', picture) = 0 THEN
    BEGIN
      picture := 'na.gif'
    END;

    returnmessage := update(statusmessage, picture);

    // Errormessages don't contain the underscore
    IF ( Pos('##', returnmessage) = 0 )  THEN
    BEGIN
      WriteLog(returnmessage, TRUE)
    END
    // For debugging purposes Successful Posts will be logged as well
    ELSE
      WriteLog(returnmessage, FALSE);
  END;
END;

Song.Free;
Player.Free;
// END MAIN



FUNCTION update(status, picture : String) : String;
var getstr,returnstr : String;
BEGIN
  // URLEncode Blanks and Special Chars
  status := URLEncode(status);
  picture := URLEncode(picture);

  getStr := 'http://dev.sam-song.info/twitter/'
    + '?message=' + status + '&userid=123456';

  WriteLog(getStr, FALSE);

  // Here goes the magic!
  returnstr := WebToStr(getStr);

  result := returnstr;
END;

PROCEDURE WriteLog(msg : String; error : boolean);
BEGIN
  IF NOT SetCurrentDir('C:\sam-song.info') THEN
  BEGIN
    CreateDir('C:\sam-song.info');
    SetCurrentDir('C:\sam-song.info');
  END;

  PAL.LockExecution;
  msg := DateTimeToStr(NOW) + '  ' + msg + chr(13) + chr(10);
  Writeln(msg);
  IF error THEN
  BEGIN
    //ERROR LOG create if not exists
    IF FileExists('twitter-error.log') THEN
      AppendStringToFile('twitter-error.log', msg)
    ELSE
      SaveStringToFile('twitter-error.log', msg)
  END
  ELSE
  BEGIN
    //DEBUG LOG create if not exists
    IF FileExists('twitter-debug.log') THEN
      AppendStringToFile('twitter-debug.log', msg)
    ELSE
      SaveStringToFile('twitter-debug.log', msg);
  END;
  PAL.UnlockExecution;
END;


If you look closely you can see that BEGIN and END are only used INSIDE of some PAL/Pascal internal structure (IF, WHILE, FUNCTION, PROCEDURE), but never outside.
My code is even indented to help for better readability.
Code works a lot better if you have an editor that has syntax highlighting for the programming language. (In case of PAL, the closest relatives are Pascal and Delphi)
VS Code, SublimeText or even Notepad++ if nothing else is available are good choices.

If you're really completely new to programming, I'm pretty impressed by how far you got without any major problems so far.
Keep up the good work and don't take my critique personally. I'm really not good at critizizing people without making it look like I want to blame them in english. :(

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

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


Top
 Profile  
Reply with quote  
PostPosted: February 12th, 2019, 5:15 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Great

yes I do use Notepad++ because I'm PHP Programmer and I use it intensively.
I had not clue where PAL came from thus it was difficult to see syntaxis

About the script: I've made the corrections you suggested.

But the hiccup of SAM still there. Wile I'm writing this message, I saw already 2 calls for the same song :-/

However, I want to thank you very much for your helps and suggestions. Very appreciated


Top
 Profile  
Reply with quote  
PostPosted: February 13th, 2019, 3:07 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
I found a turn around. This is not the solution, but just something to avoid that double calls are made to Twitter and Tunein

Checking the log by my PHP script, I saw more precisely that every double call, is made after 9-11 seconds after the very first call.

Thus since I store into a MySQL record any aired song, with the time stamp of the first call, to any incoming call I compare the new timestamp with the one into the record.

In case the interval is less than 20 (just to be sure) seconds, I just exit.

In case the interval is longer, then the script continues.

here below the few lines of code (in case somebody else got the same issue, and wants to apply something, in order to avoid Twitter's policies violation)

Code:
/**
 * CHECK IF ELAPSED TIME IS MORE THAN 20 SECONDS
 */
$query = "SELECT * FROM $ts";
$sth = $conn->prepare($query);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$PREVTime = $row['OnAirTimeStamp'];
$CHECKCurrent = time();
if ( ($CHECKCurrent - $PREVTime ) < 20 ) { exit; }
...
...



As I said, this is not to be considered a solution.
This is just a protection for double calls.
The causes for it, should in any case investigated


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 7:13 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Im' back t this script because I got again anomalies.
I did notice indeed that often it looses songs ... i mean:

    the song is started playing
    he sends the call
    the call never arrives to the script, because SAM doesn't make any call, in the reality

To minimize errors due the numbers of BEGIN END cycles, I tried deleting all what is not fundamental to the goal, to check if the issue persists. And it does :-/


Code:
PAL.loop := true;
PAL.WaitForPlayCount(1);
{Declaration (Variables)}
var     Player : TPlayer;
var     Song : TSongInfo;
var     statusmessage, returnmessage, picture, ipCheck, ipResult: String;
var     ErrorLog, DebugLog : String;
const RadioDomain : string = 'https://www.MYRADIO.com';
const RadioSocial : string = RadioDomain + '/sam/myscript.php';
const Address : string = RadioDomain + '/SongOnDemand/pictures/';
const PathFiles : string = 'C:\sam-song-info\';

// Check the IP of SAM
ipCheck := RadioSocial + '?myip=ip';
ipResult := WebToStr(ipCheck);
WriteLn(ipResult); // it works

{Declaration (Functions and Procedures)}
// Construct the GET String for the Web Script, call it and return the output
FUNCTION update(status, picture : String) : String; forward;

Player := ActivePlayer;

// Is anything playing right now?
IF ( Player <> NIL ) THEN
BEGIN
   Song := Player.GetSongInfo;
   IF (Song <> NIL) AND (Pos(Song['songtype'],'SAV') > 0) THEN
   BEGIN
      // Message to display in twitter
      statusmessage := Song['title'] + ' - ' + Song['artist'];
      picture := Song['picture'];

      IF Pos('jpg', picture) = 0 THEN
      BEGIN
         picture := 'na.png'
      END;

   returnmessage := update(statusmessage, picture);
   END;
END;

Song.Free;
Player.Free;
// END MAIN



FUNCTION update(status, picture : String) : String;
var getStr, returnstr : String;
BEGIN
   WriteLn(picture);

   // URLEncode Blanks and Special Chars
   status := URLEncode(status);
   picture := URLEncode(picture);

   //getStr := 'http://www.sam-song.info/twitter/'
   getStr := RadioSocial
   + '?message=' + status
    + '&picture=' + picture
   + '&title=' + URLEncode(Song['title'])
    + '&artist=' + URLEncode(Song['artist'])
   + '&album=' + URLEncode(Song['album'])
    + '&duration=' + URLEncode(Song['duration'])
   + '&shop=' + URLEncode(Song['buycd'])
    + '&songtype=' + Song['songtype'];

   //WebToStr(getStr); // Tormy
   // Here goes the magic!
   WebToFile(PathFiles + 'webresponse.txt', getStr);
   returnstr := FileToStr(PathFiles + 'webresponse.txt');

   result := returnstr;
END;



so ... in the last hour were broadcasted 18 songs. Only 12 reached the script (that is packing and sending to Twitter)
The other 6 were simply lost :-/ is seems SAM didn't make the call.

In the log is written: it called ... but in fact the script didn't receive any call.
There is not interference made by oithers, because the script checks also the IP of the caller, upfront any action. And it does know the IP of SAM ...

Really I can't figure out what is causing this


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 11:04 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Here again with my report from 18:00 CET
a broadcast was successfully sent (the first part)
the advertisements ... then back to the second part an then a lot of music.

Updates are stopped at the first part of the broadcast.

I'm getting mad ..


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 12:26 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7868
Location: Aachen (Germany)
That's really strange. My users have been using the original version of that script for 8 or 9 years now and I haven't heard of the script skipping or halting at all.

If you got at least SAM 2017.8, there is another non-blocking alternative to WebToFile, by using the way more complex THttpClient:

Code:
FUNCTION update(status, picture : String) : String;
var getStr, returnstr : String;
var httpClient : THttpClient;
BEGIN
   WriteLn(picture);

   // URLEncode Blanks and Special Chars
   status := URLEncode(status);
   picture := URLEncode(picture);

   //getStr := 'http://www.sam-song.info/twitter/'
   getStr := RadioSocial
   + '?message=' + status
    + '&picture=' + picture
   + '&title=' + URLEncode(Song['title'])
    + '&artist=' + URLEncode(Song['artist'])
   + '&album=' + URLEncode(Song['album'])
    + '&duration=' + URLEncode(Song['duration'])
   + '&shop=' + URLEncode(Song['buycd'])
    + '&songtype=' + Song['songtype'];

   //WebToStr(getStr); // Tormy
   // Here goes the magic!

//   WebToFile(PathFiles + 'webresponse.txt', getStr);
   httpClient.Get;
   while not httpClient.ResponseReady do
     Pal.WaitForTime('+00:00:01');

  // HTTP Status Codes: 200 = OK, 404 = NOT FOUND, 403 = Forbidden, 500 = Generic Server error
  IF httpClient.ResponseCode = 200 THEN
    returnstr := httpClient.ResponseData;

  result := returnstr;
END;

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

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


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 1:13 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
I'm using 2019.1

really it doesn't start ... I'm getting crazy .. because that script, with that communication, is triggering a series of very important automation processes.

It seems only for twitter but it isn't ... the PHP script sends also to tunein, it checks how many times an emission is broadcasted, and triggers the information for the producers so that they can upload the new episodes, checsk from the DNS if ever the IP of SAM is changed etc etc etc. When it doesn't communicate with the server, it's a disaster


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 3:00 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7868
Location: Aachen (Germany)
So, did you try my suggestion?

Whether the HTTP-GET-Request triggers a post to twitter or anything else is completely irrelevant.
The only changes to my original script are the second (blocking) request to do the IP check and adding a bunch of additional query-parameters.
That shouldn't affect the way the script works as far as I can tell and from my experience the WebToFile is pretty unproblematic.

People usually come and complain if the service doesn't work for a few hours, but I haven't yet had any users complain about the PAL script not working in the 9 years since I started sam-song.info. And I'm not the only one using that. There are about 200 people using sam-song.info and a handful on the "secret" version with Facebook. (They share a very similar PAL script that only differs in the URL and some parameters)

Aside from trying to use a different way to perform the HTTP requests, you should really move your IP-check after the function declaration. I'm not sure if this has any effect on the code, but the way I learned Turbo Pascal was that you had to put forward declarations to the very top of your program so it's only preceded by the variable declarations.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

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


Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2019, 3:04 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 99
Mastacheata wrote:
So, did you try my suggestion?

Whether the HTTP-GET-Request triggers a post to twitter or anything else is completely irrelevant.
The only changes to my original script are the second (blocking) request to do the IP check and adding a bunch of additional query-parameters.
That shouldn't affect the way the script works as far as I can tell and from my experience the WebToFile is pretty unproblematic.

People usually come and complain if the service doesn't work for a few hours, but I haven't yet had any users complain about the PAL script not working in the 9 years since I started sam-song.info. And I'm not the only one using that. There are about 200 people using sam-song.info and a handful on the "secret" version with Facebook. (They share a very similar PAL script that only differs in the URL and some parameters)

Aside from trying to use a different way to perform the HTTP requests, you should really move your IP-check after the function declaration. I'm not sure if this has any effect on the code, but the way I learned Turbo Pascal was that you had to put forward declarations to the very top of your program so it's only preceded by the variable declarations.

I was not home, now I will try it and I will let it work for a while
I'm not thinking is the script the issue ... I'm afraid is SAM itself ... because the script runs, but SAM doesn't call ... even when I was writing my previous message, a similar event occurred right under my nose

Now, as I said, the CALL that SAM has to do, is very important because sending the information to he PHP script, it triggers a bunch of other things.

I was rally relying on this. But now I'm very concerned.

I try your modified script and I will be back


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 11 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