Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Reply
Thread Tools Search this Thread Display Modes
Old 10th February 2009, 04:42   #1
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
Twittercast: Shoutcast / Icecast Song Title To Twitter Status PHP Script

Shoutcast song title to twitter php script.

This will query a shoutcast server for the currently playing song and set it as your twitter status.
Only updates when the song changes.

Download Here

Instructions:

1. Download required files
2. Edit twitterAPI.php username and password
3. Edit twittercast.php server info
6. Upload all files in the same web directory
7. Access twittercast.php using your browser or set up a cron job to hit it every 10 mins
8. Check your twitter for results
dopelabs is offline   Reply With Quote
Old 10th February 2009, 04:44   #2
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
Attachment deleted at poster's request

~dotme
dopelabs is offline   Reply With Quote
Old 10th February 2009, 12:00   #3
Nick@ss
Moderator
 
Nick@ss's Avatar
 
Join Date: Nov 2004
Location: Streamsolutions Headquarters
Posts: 11,953
Good work.

Am i ok to post this here with the other collectoin of scripts? http://www.streamsolutions.co.uk/resources/scripts
Nick@ss is offline   Reply With Quote
Old 10th February 2009, 18:00   #4
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
Yes you may distribute freely =]

updated file attached
Attached Files
File Type: zip twittercast.zip (2.2 KB, 3191 views)
dopelabs is offline   Reply With Quote
Old 17th February 2009, 20:51   #5
crankygeek
Junior Member
 
Join Date: Feb 2009
Posts: 5
Not working

Well, I've done my best to set this up. I know the Twitter API is working fine because it does post, however all I get in a post is "Now Playing: " I have to delete the title.txt to get it to do it again. I have set IP and port in the .php

Am I missing something?
crankygeek is offline   Reply With Quote
Old 18th February 2009, 02:00   #6
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
The way this works is. the script will check the shoutcast server for the currently playing song. It then checks the title.txt for the same title info... if the title.txt file is empty, or it has different title info, it will send that data to twitter, and it will also write that to the title.txt file.

This script will ONLY update the title info if its different from the last time it checked, thus not posting the same title every min. (or however long you set your cron job for)

here is an example of a cron job that could be used:

*/10 * * * * wget -O /dev/null http://www.domain.com/twittercast.php >> /dev/null 2>&1

things to keep in mind:

make sure the title.txt file is writable by your webserver (chmod 777 title.txt) and in the same directory as everything else.

make sure there actually IS title info on your shoutcast server..

just visit your shoutcast server in your browser to check that.


I am also posting a new version.

Changes:

Support for multiple servers
Added listener count to twitter output
Added page refresh for automatic in-browser updates


see working examples at www twitter com / dubstepfm
Attached Files
File Type: zip twittercast_multi.zip (2.8 KB, 1456 views)

Last edited by dopelabs; 18th February 2009 at 03:04.
dopelabs is offline   Reply With Quote
Old 18th February 2009, 23:11   #7
crankygeek
Junior Member
 
Join Date: Feb 2009
Posts: 5
I know the server has titles and they do change. Is there a difference from hitting it with a browser or using a cronjob?
crankygeek is offline   Reply With Quote
Old 18th February 2009, 23:13   #8
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
no difference.. it will work either way
dopelabs is offline   Reply With Quote
Old 18th February 2009, 23:27   #9
crankygeek
Junior Member
 
Join Date: Feb 2009
Posts: 5
I did a chmod of the .txt to 777 , no help.

the two .php's should be at 644, correct?
crankygeek is offline   Reply With Quote
Old 18th February 2009, 23:28   #10
crankygeek
Junior Member
 
Join Date: Feb 2009
Posts: 5
also, can you tell me if the script puts any output on the page when executed via web browser. All I get is


Quote:
// Twittercast Shoutcast Twitter Status Script By DopeLabs - http://www.dubstep.fm // Twittercast Shoutcast Twitter Status Script By DopeLabs - http://www.dubstep.fm
crankygeek is offline   Reply With Quote
Old 18th February 2009, 23:34   #11
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
the new version displays exactly what will show up in your twitter status
dopelabs is offline   Reply With Quote
Old 18th February 2009, 23:41   #12
crankygeek
Junior Member
 
Join Date: Feb 2009
Posts: 5
downloaded new version, edited high bitrate server ip and port, didnt touch anything else.


Quote:
Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/wdosfm/public_html/twitterstuff/twittercast_multi.php on line 113 Parse error: syntax error, unexpected ')' in /home/wdosfm/public_html/twitterstuff/twittercast_multi.php on line 113
any idea?
crankygeek is offline   Reply With Quote
Old 19th February 2009, 00:12   #13
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
im not sure what to tell you...

this is what line 113 looks like on mine:

$twitter_status=postToTwitter($twitter_username, $twitter_psw, 'Now Playing: '.$song[1] .' - ' .$total_listeners .' Listeners');

note that the username and password IS NOT entered here but in the API page

This is my Twitter status

Now Playing: [ARCHIVE] 2008-12-12 The Supernormous Smoke Sessions With Tminus Shambles Jviz KidLogic And Guests - 357 Listeners

This is my browser output

Now Playing: [ARCHIVE] 2008-12-12 The Supernormous Smoke Sessions With Tminus Shambles Jviz KidLogic And Guests - 357 Listeners



My station has 4 servers... so my ip and port block looks like this ( i changed my actual IPs )

$ip[1] = "123.123.123.123";
$port[1] = "80";

$ip[2] = "123.123.123.124";
$port[2] = "8000";

$ip[3] = "123.123.123.125";
$port[3] = "8030";

$ip[4] = "123.123.123.126";
$port[4] = "8050";

if you only have 1 server.. erase blocks 2, 3, and 4... if you need more add 5, 6, and so on
dopelabs is offline   Reply With Quote
Old 19th February 2009, 01:32   #14
aaronsnet
Member
 
aaronsnet's Avatar
 
Join Date: Mar 2004
Location: Notsville
Posts: 56
Send a message via AIM to aaronsnet
Quote:
Originally posted by crankygeek
downloaded new version, edited high bitrate server ip and port, didnt touch anything else.




any idea?
Maybe something you were trying to send had an apostrophe ( ' ) in it?

Also, if you send a duplicate to your previous twitter post...I don't think that it actually posts it again. I am pretty sure that it just ignores it.

Twitter has been nice to archive playlists though.

the detour network - detour MUSIC, detour TALK, detour BLUES, SOF Radio

Purple Zebra Media Services-http://purplezebra.us
Supporting independent, licensed internet radio stations since 2001!
aaronsnet is offline   Reply With Quote
Old 19th February 2009, 01:46   #15
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
thats why it writes the title info to title.txt it checks that for differences and will only post to twitter if there is a 'new' song.

yea maybe the song title has a ' in it...
dopelabs is offline   Reply With Quote
Old 19th February 2009, 09:10   #16
Wavestreaming
Major Dude
 
Wavestreaming's Avatar
 
Join Date: Apr 2004
Location: United Kingdom
Posts: 1,563
Send a message via AIM to Wavestreaming Send a message via Yahoo to Wavestreaming
Pretty cool!

I've been considering creating something similar to offer our clients and I'll probably add this script to our resources area. Twitter is a growing community and can prove a great marketing tool - especially given that Twitter openly allow people to use it for commercial purposes.

I actually had a chat with our web developer about using twitter for marketing a radio station a month or so back for Talkwebcasting; http://www.youtube.com/watch?v=FTWxnMGx3zA

By the way, any twitter people who'd like to follow us, feel free! http://twitter.com/wavestreaming
Wavestreaming is offline   Reply With Quote
Old 19th February 2009, 12:24   #17
aaronsnet
Member
 
aaronsnet's Avatar
 
Join Date: Mar 2004
Location: Notsville
Posts: 56
Send a message via AIM to aaronsnet
Quote:
Originally posted by dopelabs
thats why it writes the title info to title.txt it checks that for differences and will only post to twitter if there is a 'new' song.

yea maybe the song title has a ' in it...
I was just saying that that script is not necessary to do that because if you sent the same post x2 or more in a row, Twitter will automatically ignore it and not repost it over and over.

the detour network - detour MUSIC, detour TALK, detour BLUES, SOF Radio

Purple Zebra Media Services-http://purplezebra.us
Supporting independent, licensed internet radio stations since 2001!
aaronsnet is offline   Reply With Quote
Old 19th February 2009, 15:51   #18
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
Quote:
Originally posted by aaronsnet
I was just saying that that script is not necessary to do that because if you sent the same post x2 or more in a row, Twitter will automatically ignore it and not repost it over and over.
correct BUT since the new version also includes the listener count, it will be different each time the script executes. thus requiring the check =]
dopelabs is offline   Reply With Quote
Old 28th February 2009, 15:49   #19
Michael T.
Member
 
Join Date: Nov 2004
Posts: 82
Quote:
Originally posted by dopelabs
The way this works is. the script will check the shoutcast server for the currently playing song. It then checks the title.txt for the same title info... if the title.txt file is empty, or it has different title info, it will send that data to twitter, and it will also write that to the title.txt file.

This script will ONLY update the title info if its different from the last time it checked, thus not posting the same title every min. (or however long you set your cron job for)

here is an example of a cron job that could be used:

*/10 * * * * wget -O /dev/null http://www.domain.com/twittercast.php >> /dev/null 2>&1

things to keep in mind:

make sure the title.txt file is writable by your webserver (chmod 777 title.txt) and in the same directory as everything else.

make sure there actually IS title info on your shoutcast server..

just visit your shoutcast server in your browser to check that.


I am also posting a new version.

Changes:

Support for multiple servers
Added listener count to twitter output
Added page refresh for automatic in-browser updates


see working examples at www twitter com / dubstepfm
That looks pretty cool. Just edit the
$twitter_username ='username';
$twitter_psw ='password';
section of the twitterAPI with my twitter username and password?

and edit the
// High bitrate
$ip[1] = "123.123.123.123";
$port[1] = "8000";

// Medium bitrate
$ip[2] = "123.123.123.123";
$port[2] = "8002";

// Low bitrate
$ip[3] = "123.123.123.123";
$port[3] = "8004";?

section of the twitter_multi file with the server addresses and upload? I want to make sure I understand it all before I upload.

Last edited by Michael T.; 28th February 2009 at 16:29.
Michael T. is offline   Reply With Quote
Old 28th February 2009, 16:56   #20
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
Quote:
Originally posted by Michael T.
That looks pretty cool. Just edit the
$twitter_username ='username';
$twitter_psw ='password';
section of the twitterAPI with my twitter username and password?

and edit the
// High bitrate
$ip[1] = "123.123.123.123";
$port[1] = "8000";

// Medium bitrate
$ip[2] = "123.123.123.123";
$port[2] = "8002";

// Low bitrate
$ip[3] = "123.123.123.123";
$port[3] = "8004";

section of the twitter_multi file with the server addresses and upload? I want to make sure I understand it all before I upload.
Looks like you got it... if you have any problems you can PM me or ask in this thread =]

cheers
dopelabs is offline   Reply With Quote
Old 1st March 2009, 01:06   #21
Michael T.
Member
 
Join Date: Nov 2004
Posts: 82
I thought I had this figured out but it will not post to my twitter page.
Michael T. is offline   Reply With Quote
Old 12th March 2009, 20:24   #22
odogg
Member
 
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 75
I get it to say the song title on the web browser but it still don't post to Twitter. I have the login info correct. Puzzling...

Odogg
Dogglounge Internet Radio
Streaming Deep House Music 24/7
www.dogglounge.com
odogg is offline   Reply With Quote
Old 13th March 2009, 11:55   #23
Michael T.
Member
 
Join Date: Nov 2004
Posts: 82
I've experienced this to. I figured out that I needed the twittercast_multi.php open and my twitter page open at the same time for song to post. Try that. I hope it helps.
Michael T. is offline   Reply With Quote
Old 13th March 2009, 15:11   #24
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
i dont seem to experience this... i dont have either page open in my browser and it updates for me just fine. i use a cron job to access and run the script from the command line.
dopelabs is offline   Reply With Quote
Old 13th March 2009, 19:53   #25
odogg
Member
 
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 75
I have a cron job hitting it every 5 mins as well but no go. Can you tell us what your file permissions are set at? Mine are at 644 except the txt file which is 777. I'm thinking maybe I need to chmod the .php files to at least 744.

Odogg
Dogglounge Internet Radio
Streaming Deep House Music 24/7
www.dogglounge.com
odogg is offline   Reply With Quote
Old 17th March 2009, 21:49   #26
odogg
Member
 
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 75
Okay I figured it out, you gotta be sure to have the Curl PHP module installed or else no go. So, if anyone else out there has the same problem install Curl or contact your web host to have them do it.


Cheers!

Odogg
Dogglounge Internet Radio
Streaming Deep House Music 24/7
www.dogglounge.com
odogg is offline   Reply With Quote
Old 17th March 2009, 23:48   #27
Michael T.
Member
 
Join Date: Nov 2004
Posts: 82
I'm not familiar with curl.
Michael T. is offline   Reply With Quote
Old 17th March 2009, 23:58   #28
fc*uk
Moderator
 
fc*uk's Avatar
 
Join Date: Dec 2005
Location: Atlantic Beach
Posts: 8,089
Where are you having problems with respect to curl?

See the manpage if it is a general problem: http://curl.haxx.se/docs/manpage.html
fc*uk is offline   Reply With Quote
Old 18th March 2009, 00:14   #29
odogg
Member
 
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 75
My only problem was not having the curl php module installed on the web server. It's installed now and everything works fine.

Odogg
Dogglounge Internet Radio
Streaming Deep House Music 24/7
www.dogglounge.com
odogg is offline   Reply With Quote
Old 3rd May 2009, 14:58   #30
AKAradio
Junior Member
 
Join Date: Aug 2004
Posts: 2
is there anyway to modify this so that it only tweets DJ changes? Ive found that people like the tweeting we are doing but soon get tired of all the song updates. DJ changes would keep us out there, just not as such a high volume...

Thanks!
Eric
AKAradio is offline   Reply With Quote
Old 3rd May 2009, 16:50   #31
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
this script pulls the data straight off your shoutcast server.

whatever is on the song title or now playing from your shoutcast server is what will be tweeted...

if you wish it to stick to a single DJ.. tell your djs to set a static song title in their broadcasting application.

for example.. my station (DubstepFm) uses a static title for each dj's show.. for instance.. 'Dubfix With DopeLabs From Seattle'

its not really possible or efficient to have the dj enter in each and every song name while trying to mix using records, cd's or serato.

this script is tailored more towards stations that have DJs that do mix sets where the song title doesnt change for the entirety of the show. DubstepFM rarely has shows that are under 1 hour long.... stations that broadcast single tunes would probably not want to use this script as it would post a new song to twitter once every 3-5 mins...

hope this helps a little =]

cheers

DL
dopelabs is offline   Reply With Quote
Old 4th May 2009, 18:54   #32
aktiveradio
Junior Member
 
Join Date: Jan 2009
Posts: 14
Ok the cron works and updates the TXT file when it runs and I can see it update if I open twittercast_multi.php in a browser but I don't see twitter profile updating, I checked that my host has PHP Curl and they do Username and password are correct any other ideas?
aktiveradio is offline   Reply With Quote
Old 6th June 2009, 00:31   #33
chevereradiotv
Junior Member
 
Join Date: Jun 2009
Posts: 4
hello dopelabs, Yes I did and I have tried it many times without success. I downloaded both scripts and created the title.txt file as well. Here it is my twittercast.php script:
==========================================
<html>
<head>

<title>Untitled</title>

</head>
<body>

<?

// Twittercast Shoutcast Twitter Status Script By DopeLabs - http://www.dubstep.fm


<?php

$timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline

$ip[1] = "http://38.96.148.45";
$port[1] = "8186";

$servers = count($ip);
$i = "1";

while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$i],$errno,$errstr,$timeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
$info = str_replace('</body></html>', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}

$song[$i] = $stats[6];

}
$i++;
}

require('twitterAPI.php');

$fh = @fopen('title.txt', 'r+');
$track = @fread($fh, filesize('title.txt'));
if ($track == $song[1]."\n"){
fclose($fh);
die(0);
}else{
@fclose($fh); // if it errors, then the file doesn't exist, and the stream was never open
$fh = fopen('title.txt', 'w');
fwrite($fh, $song[1]."\n");
$twitter_status=postToTwitter($twitter_username, $twitter_psw, 'Now Playing: '.$song[1]);
}
fclose($fh);

?>

</body>
</html>
===============================================
And this is my Twitter API script:
==================================

<html>

<body>
<?php

// A simple function using Curl to post (GET) to Twitter
// Kosso : March 14 2007

$twitter_username ='chevereradiotv';
$twitter_psw ='xxxxxxxxx';

function postToTwitter($username,$password,$message){

$host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch);
// Look at the returned header
$resultArray = curl_getinfo($ch);

curl_close($ch);

if($resultArray['http_code'] == "200"){
$twitter_status='Your message has been sended! <a href="http://twitter.com/'.$username.'">See your profile</a>';
} else {
$twitter_status="Error posting to Twitter. Retry";
}
return $twitter_status;
}
?>
</body>
</html>

=======================

Any help will greatly appreciated.
chevereradiotv is offline   Reply With Quote
Old 6th June 2009, 03:04   #34
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
FYI: i have had some issues with servers on dreamhost.. i had to move my twittercast off dreamhost servers to get them to work..
dopelabs is offline   Reply With Quote
Old 6th June 2009, 12:46   #35
sputnik radio
Major Dude
 
sputnik radio's Avatar
 
Join Date: Feb 2006
Location: Dallas
Posts: 871
so everytime the song changes all your followers get a text? hmmm I don't think i would want a text every 3 minutes
sputnik radio is offline   Reply With Quote
Old 6th June 2009, 16:16   #36
dopelabs
Senior Member
 
dopelabs's Avatar
 
Join Date: Oct 2006
Location: Silicon Valley
Posts: 149
Send a message via AIM to dopelabs
well my station only plays mixes.. so at the minimum it changes once an hour... most sets on dubstep.fm are about 2 hours long though...
dopelabs is offline   Reply With Quote
Old 6th June 2009, 18:21   #37
chevereradiotv
Junior Member
 
Join Date: Jun 2009
Posts: 4
We use yahoo servers. However, I think that I am missing something in my script. Not sure what it is.
chevereradiotv is offline   Reply With Quote
Old 6th June 2009, 19:48   #38
Jkey
Forum King
 
Join Date: Jul 2004
Location: E*arth
Posts: 3,035
It maybe worth only using this script for special events or stations with live djs/long mixes as said above it could be very annoying for followers.

So Long, and Thanks for All the Fish.
Jkey is offline   Reply With Quote
Old 6th June 2009, 20:13   #39
Jkey
Forum King
 
Join Date: Jul 2004
Location: E*arth
Posts: 3,035
Forgot to add i have been working on a win32/linux shoutcast song title application using twitlib.

You just simply run it from the commandline and let it run in the backround.

I will post it once its completed all being well next week.

So Long, and Thanks for All the Fish.
Jkey is offline   Reply With Quote
Old 6th June 2009, 23:00   #40
chevereradiotv
Junior Member
 
Join Date: Jun 2009
Posts: 4
Check this out: http://twt.fm/ very cool application...
chevereradiotv is offline   Reply With Quote
Reply
Go Back   Winamp Forums > SHOUTcast > SHOUTcast Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump