|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 |
Major Dude
|
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 |
![]() |
![]() |
![]() |
#2 |
Major Dude
|
Attachment deleted at poster's request
~dotme |
![]() |
![]() |
![]() |
#3 |
Moderator
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 |
![]() |
![]() |
![]() |
#4 |
Major Dude
|
Yes you may distribute freely =]
updated file attached |
![]() |
![]() |
![]() |
#5 |
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? |
![]() |
![]() |
![]() |
#6 |
Major Dude
|
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 Last edited by dopelabs; 18th February 2009 at 04:04. |
![]() |
![]() |
![]() |
#7 |
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?
|
![]() |
![]() |
![]() |
#8 |
Major Dude
|
no difference.. it will work either way
|
![]() |
![]() |
![]() |
#9 |
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? |
![]() |
![]() |
![]() |
#10 | |
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:
|
|
![]() |
![]() |
![]() |
#11 |
Major Dude
|
the new version displays exactly what will show up in your twitter status
|
![]() |
![]() |
![]() |
#12 | |
Junior Member
Join Date: Feb 2009
Posts: 5
|
downloaded new version, edited high bitrate server ip and port, didnt touch anything else.
Quote:
|
|
![]() |
![]() |
![]() |
#13 |
Major Dude
|
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 |
![]() |
![]() |
![]() |
#14 | |
Member
|
Quote:
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 Purple Zebra Consulting-http://purplezebra.us Supporting independent internet radio stations since 2001! |
|
![]() |
![]() |
![]() |
#15 |
Major Dude
|
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... |
![]() |
![]() |
![]() |
#16 |
Major Dude
|
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 ![]() |
![]() |
![]() |
![]() |
#17 | |
Member
|
Quote:
the detour network - detour MUSIC, detour TALK Purple Zebra Consulting-http://purplezebra.us Supporting independent internet radio stations since 2001! |
|
![]() |
![]() |
![]() |
#18 | |
Major Dude
|
Quote:
|
|
![]() |
![]() |
![]() |
#19 | |
Member
Join Date: Nov 2004
Posts: 99
|
Quote:
$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 17:29. |
|
![]() |
![]() |
![]() |
#20 | |
Major Dude
|
Quote:
cheers |
|
![]() |
![]() |
![]() |
#21 |
Member
Join Date: Nov 2004
Posts: 99
|
I thought I had this figured out but it will not post to my twitter page.
|
![]() |
![]() |
![]() |
#22 |
Member
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 77
|
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...
|
![]() |
![]() |
![]() |
#23 |
Member
Join Date: Nov 2004
Posts: 99
|
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.
![]() |
![]() |
![]() |
![]() |
#24 |
Major Dude
|
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.
|
![]() |
![]() |
![]() |
#25 |
Member
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 77
|
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.
|
![]() |
![]() |
![]() |
#26 |
Member
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 77
|
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! |
![]() |
![]() |
![]() |
#27 |
Member
Join Date: Nov 2004
Posts: 99
|
I'm not familiar with curl.
|
![]() |
![]() |
![]() |
#28 |
Moderator
Join Date: Dec 2005
Location: Atlantic Beach
Posts: 8,140
|
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 |
![]() |
![]() |
![]() |
#29 |
Member
Join Date: Jan 2004
Location: St. Paul, MN
Posts: 77
|
My only problem was not having the curl php module installed on the web server. It's installed now and everything works fine.
|
![]() |
![]() |
![]() |
#30 |
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 |
![]() |
![]() |
![]() |
#31 |
Major Dude
|
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 |
![]() |
![]() |
![]() |
#32 |
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?
|
![]() |
![]() |
![]() |
#33 |
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. |
![]() |
![]() |
![]() |
#34 |
Major Dude
|
FYI: i have had some issues with servers on dreamhost.. i had to move my twittercast off dreamhost servers to get them to work..
|
![]() |
![]() |
![]() |
#35 |
Major Dude
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
|
![]() |
![]() |
![]() |
#36 |
Major Dude
|
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...
|
![]() |
![]() |
![]() |
#37 |
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.
|
![]() |
![]() |
![]() |
#38 |
Forum King
Join Date: Jul 2004
Location: E*arth
Posts: 3,031
|
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. ![]() ![]() |
![]() |
![]() |
![]() |
#39 |
Forum King
Join Date: Jul 2004
Location: E*arth
Posts: 3,031
|
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. ![]() ![]() |
![]() |
![]() |
![]() |
#40 |
Junior Member
Join Date: Jun 2009
Posts: 4
|
Check this out: http://twt.fm/ very cool application...
|
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|