No announcement yet.

Twittercast: Shoutcast / Icecast Song Title To Twitter Status PHP Script

  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    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 =]




    • #32
      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
        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:




        // Twittercast Shoutcast Twitter Status Script By DopeLabs -


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

        $ip[1] = "";
        $port[1] = "8186";

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

        $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";
        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];



        $fh = @fopen('title.txt', 'r+');
        $track = @fread($fh, filesize('title.txt'));
        if ($track == $song[1]."\n"){
        @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]);


        And this is my Twitter API script:



        // 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 = "".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);


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


        Any help will greatly appreciated.


        • #34
          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
            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
              well my station only plays mixes.. so at the minimum it changes once an hour... most sets on are about 2 hours long though...


              • #37
                We use yahoo servers. However, I think that I am missing something in my script. Not sure what it is.


                • #38
                  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
                    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
                      Check this out: very cool application...


                      • #41
                        This is the address: http: //


                        • #42
                          twittercast hasn't been working for a while now. I don't know if it had to do with the migration of my web server or what but this is all I get now.

                          Now Playing: - 0 Listeners// Twittercast Shoutcast Twitter Status Script By DopeLabs -

                          Which isn't right because I know that there are listeners since I monitor the stream using Radio Tool Box.


                          • #43
                            When song title is updated, after each dj connects. Is it possible to have a link inserted automatically?

                            ie Joe Blogg Live Now is what goes from song title, but have next to each tweet without the dj having to put the full web address in song title?



                            • #44
                              yes.... here is what my code looks like

                              $twitter_status=postToTwitter($twitter_username, $twitter_psw, ' - Now Playing: '.$song[1] .' - ' .$total_listeners .' Listeners -');
                              here is the output on twitter

                     - Now Playing: ARCHIVE - 2009-06-06 - Part Time Sucker Radio from Chicago With Searchl1te Jeekoos F8less - 282 Listeners -


                              • #45
                                Twittercast not posting to twitter - FIX

                                Twitter recently upgraded their Apache web server which now properly handle HTTP Expect headers. There needs to be a curl option set in twitterAPI.php to handle this.

                                Add this line in with the rest of the curl options:

                                PHP Code:
                                curl_setopt($chCURLOPT_HTTPHEADER, array('Expect:')); 
                                In my script, I put it right below:
                                PHP Code:
                                $ch curl_init(); 
                                and everything started working.

                                Hope this helps!