Last active
December 11, 2015 10:27
-
-
Save confact/500ff5b6e32f41041a7c to your computer and use it in GitHub Desktop.
Dirble AIR API script for SAM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
Script to submit song info to the Dirble AIR API (https://dirble.com/broadcasters/providers). | |
The stationId & airKey values need to be set for this to work. | |
} | |
const STATION_ID = ''; | |
const AIRKEY = ''; | |
var player : TPlayer; | |
var song : TSongInfo; | |
var baseUrl: String; | |
FUNCTION urlEncode(s: String): String; forward; | |
PROCEDURE update(stationId, airKey, artist, title : String); forward; | |
{Main} | |
PAL.Loop := true; | |
PAL.WaitForPlayCount(1); | |
player := ActivePlayer; | |
IF ( player <> NIL ) THEN | |
BEGIN | |
IF ( player.Duration > 45000 ) THEN | |
BEGIN | |
song := player.GetSongInfo; | |
IF ( song <> NIL ) THEN | |
BEGIN | |
update(STATION_ID, AIRKEY, song['artist'],song['title']); | |
song.Free; | |
END; | |
END; | |
END; | |
FUNCTION urlEncode(s: String): String; | |
BEGIN | |
var index : integer; | |
var intVal : integer; | |
result := ''; | |
PAL.LockExecution; | |
IF (Length(s)) > 0 THEN | |
BEGIN | |
FOR index := 1 TO length(s) DO | |
BEGIN | |
intVal := Ord(s[index]); | |
IF ((intVal > 47) AND (intVal < 58)) OR ((intVal > 64) AND (intVal < 91)) OR ((intVal > 96) AND (intVal < 123)) THEN | |
BEGIN | |
result := result + (s[index]) | |
END | |
ELSE | |
BEGIN | |
IF ( intVal < 128 ) THEN | |
BEGIN | |
result := result + '%' + IntToHex(intVal, 2); | |
END | |
ELSE IF ( intVal < 2048 ) THEN | |
BEGIN | |
result := result + '%' + IntToHex( $C0 or Trunc( intVal / 64 ), 2 ) + '%' + IntToHex( $BF and intVal, 2 ); | |
END | |
ELSE | |
BEGIN | |
// not yet supported | |
END; | |
END; | |
END; | |
END; | |
PAL.UnlockExecution; | |
END; | |
PROCEDURE update(stationId, airKey, artist, title : String); | |
BEGIN | |
var req : String; | |
req := 'http://api.dirble.com/v2/station/air?id=' + stationId | |
+ '&key=' + urlEncode(airKey) | |
+ '&song=' + urlEncode(title) | |
+ '&artist=' + urlEncode(artist); | |
WebToStr(req); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment