Welcome
Welcome to <strong>Teazers Tunage: Forums</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

SAM and your Twitter (Adding now playing)

This section is in regards to those that wish to learn to be an Internet Radio Broadcaster, Production, Voice-Overs, etc. Station information will be here as well as Q & A's.

Moderator: djteazer

SAM and your Twitter (Adding now playing)

Postby djteazer on Thu Jul 23, 2009 11:26 am

Thank you Rob Oyler for this info!

I post to my twitter page the currently playing song on each song change. Here is how I do it. this method only works if using SAM broadcaster.

Here is my twitter page http://twitter.com/fm5280

Here is how it is done: Full credit goes to George at http://yourinternetradio.com although I have made some modifications to his original script

1) open your favorite text editor
enter the this code
Code:

|$song.title$
|$song.artist$
|$viewers$
|$history.requestID$
|$song.rating$


SAVE AS _twitter.html (note the underscore)

2) In SAM, go to Config > HTML output. In that window, set up SAM to automatically FTP your file on every song change. I set _twitter.html as my input file and twitter.html (no underscore!) as the output file. Change your upload FTP path to your Root (if you are already using html instead of php do not change your upload path change your paths for twitter to match where all your pages get uplaoded.).

When you have done that correctly, a file named twitter.html will be present on your web host and it will contain data about the current song.

3) Next copy this code and save it as twitter.php. EDIT THE CONFIGURATION PORTION, Then upload it to your webhost root directory.
Code:
<?php

// PERMIT EXECUTION FROM YOUR SAM PC, ONLY.
// CODE YOUR SAM PC'S IP ADDRESS.

if ($_SERVER['REMOTE_ADDR'] != "XXX.XX.XXX.XXX")
{
exit();
}

//====================================================
// CONFIGURATION
//====================================================

// YOUR TWITTER USERNAME AND PASSWORD
$username = '************';
$password = '************';

// YOUR WEB HOST PATH TO HTML FILE THAT SAM GENERATES AND
// UPLOADS ON EVERY SONG CHANGE.
DEFINE(htmlfile, '/var/www/html/twitter.html');

// THE URL THAT YOU WANT TO APPEAR ON TWITTER.
// IF YOUR URL IS GREATER THAN 29 CHARACTERS IN LENGTH,
// TWITTER WILL CONVERT IT TO A TINYURL.
$stationURL = "http://XXXXXXXX.com";

// MAXIMUM NUMBER OF CHARACTERS IN THE TWEETER MESSAGE.
// THIS INCLUDES ARTIST, TITLE, PUNCTUATION, SPACES, AND
// YOUR URL. TWEETER TRUNCATES AT 140 CHARACTERS.
// I TRUNCATE AT 137, LEAVING ROOM FOR A FEW TRAILING PERIODS.
$maxLimit = "137";

//====================================================
// END OF CONFIGURATION
// MAKE NO CHANGES BEYOND
// THIS POINT UNLESS YOU
// KNOW WHAT YOU ARE DOING
//====================================================
$da="";
$f=@fopen(htmlfile, "r");

if ($f!=0)
{
$da=@fread($f, 4096);
fclose($f);
}
else
{
exit;
}

$da=str_replace("\r", "\n", $da);
$da=str_replace("\n\n", "\n", $da);
$d=explode("\n", $da);

$d[0]=trim($d[0], "|"); // title
$d[1]=trim($d[1], "|"); // artist
$d[2]=trim($d[2], "|"); // listeners
$d[3]=trim($d[3], "|"); // RequestID
$d[4]=trim($d[4], "|"); // Rating
//====================================================
if ($d[0]=="" || $d[1]=="")
{
// IF WE COULD NOT GRAB THE ARTIST AND
// SONG TITLE FROM THE SAM-GENERATED HTML FILE,
// WE'LL BAIL OUT NOW WITHOUT SUBMITTING ANY TEXT
// TO TWITTER.
exit;
}
else
{
// SUCCESS IN GETTING ARTIST AND TITLE!
// WE'LL PROCEED WITH BUILDING A TEXT STRING TO SUBMIT TO TWITTER.
if($d[3] == 0)
$message = urlencode('NOW PLAYING: ' . $d[1] . ' - ' . $d[0] . ' - ' . 'rated ' . $d[4] . ' out of 5 stars' . ' Heard by ' . $d[2] . ' listeners at ');
else
$message = urlencode('By Request: ' . $d[1] . ' - ' . $d[0] . ' - ' . 'rated ' . $d[4] . ' out of 5 stars' . ' Heard by ' . $d[2] . ' listeners at ');

$stationURL = urlencode(' ' . $stationURL);

if ((strlen($message) + strlen($stationURL)) > $maxLimit)
{
// We have to truncate the artist-title string to make room for the station URL string.
$message = substr($message, 0, (($maxLimit - 2) - strlen($stationURL)));
$message .= ".." . $stationURL;
}
else
{
// No need to truncate, it all fits.
$message = $message . $stationURL;
}
} // if ($d[0]=="" || $d[1]=="")

//====================================================
// The twitter API address
$url = 'http://twitter.com/statuses/update.json';

// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

?>

4) Return to SAM and create this PAL and save as twitter.pal
Code:
// Wait 8 seconds after song change to let SAM handle crossfading, queries, etc. first.
PAL.WaitForTime('+00:00:04');

PAL.LockExecution;

PAL.Loop := True;
var Song : TSongInfo;
Song := ActivePlayer.GetSongInfo();
if ((Song['songtype'] = 'S') or (Song['songtype'] = 'C')) then
// Execute the PHP file on your web host.
// The first parameter is the name of a meaningless text file. Provide a valid path and name.
// The second parameter is the URL of your PHP file to be executed.
WebToFile('c:\dummy.txt','http://XXXXXXXXX.com/twitter.php'); //<--- be sure to change this line to where your twitter.php was uploaded
PAL.UnlockExecution;
Song.Free;
PAL.WaitForPlayCount(1);
This PAL will upload to twitter for songtypes S & C ( I use C for Christmas music) only.

ENJOY!!

_________________
Rob Oyler
Program Director, FM5280
djteazer
Site Admin
 
Posts: 168
Joined: Sun May 25, 2008 1:54 am

Return to Station FAQ\'s

Who is online

Users browsing this forum: No registered users and 0 guests

cron